forked from GeyserMC/Geyser
Merge pull request #300 from DoctorMacc/cats
Add extra metadata for tameable entities
This commit is contained in:
commit
27f4879f0a
5 changed files with 88 additions and 9 deletions
|
@ -28,6 +28,7 @@ package org.geysermc.connector.entity.living.animal.tameable;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityData;
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
||||||
import org.geysermc.connector.entity.type.EntityType;
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
|
@ -40,12 +41,32 @@ public class CatEntity extends TameableEntity {
|
||||||
@Override
|
@Override
|
||||||
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||||
if (entityMetadata.getId() == 18) {
|
if (entityMetadata.getId() == 18) {
|
||||||
metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue());
|
// Different colors in Java and Bedrock for some reason
|
||||||
|
int variantColor;
|
||||||
|
switch ((int) entityMetadata.getValue()) {
|
||||||
|
case 0:
|
||||||
|
variantColor = 8;
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
variantColor = 0;
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
variantColor = 10;
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
variantColor = 9;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
variantColor = (int) entityMetadata.getValue();
|
||||||
|
}
|
||||||
|
metadata.put(EntityData.VARIANT, variantColor);
|
||||||
}
|
}
|
||||||
if (entityMetadata.getId() == 21) {
|
if (entityMetadata.getId() == 21) {
|
||||||
// FIXME: Colors the whole animal instead of just collar
|
// Needed or else wild cats are a red color
|
||||||
|
if (metadata.getFlags().getFlag(EntityFlag.TAMED)) {
|
||||||
metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue());
|
metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
super.updateBedrockMetadata(entityMetadata, session);
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* @author GeyserMC
|
||||||
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geysermc.connector.entity.living.animal.tameable;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
|
public class ParrotEntity extends TameableEntity {
|
||||||
|
|
||||||
|
public ParrotEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
|
super(entityId, geyserId, entityType, position, motion, rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||||
|
// Parrot color
|
||||||
|
if (entityMetadata.getId() == 18) {
|
||||||
|
metadata.put(EntityData.VARIANT, entityMetadata.getValue());
|
||||||
|
}
|
||||||
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,7 @@ package org.geysermc.connector.entity.living.animal.tameable;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
||||||
import org.geysermc.connector.entity.living.animal.AnimalEntity;
|
import org.geysermc.connector.entity.living.animal.AnimalEntity;
|
||||||
import org.geysermc.connector.entity.type.EntityType;
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
|
@ -45,6 +46,11 @@ public class TameableEntity extends AnimalEntity {
|
||||||
metadata.getFlags().setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01);
|
metadata.getFlags().setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01);
|
||||||
metadata.getFlags().setFlag(EntityFlag.ANGRY, (xd & 0x02) == 0x02);
|
metadata.getFlags().setFlag(EntityFlag.ANGRY, (xd & 0x02) == 0x02);
|
||||||
metadata.getFlags().setFlag(EntityFlag.TAMED, (xd & 0x04) == 0x04);
|
metadata.getFlags().setFlag(EntityFlag.TAMED, (xd & 0x04) == 0x04);
|
||||||
|
// Must be set for wolf collar color to work
|
||||||
|
// Extending it to all entities to prevent future bugs
|
||||||
|
if (metadata.getFlags().getFlag(EntityFlag.TAMED)) {
|
||||||
|
metadata.put(EntityData.OWNER_EID, session.getPlayerEntity().getGeyserId());
|
||||||
|
} // Can't de-tame an entity so no resetting the owner ID
|
||||||
}
|
}
|
||||||
super.updateBedrockMetadata(entityMetadata, session);
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ package org.geysermc.connector.entity.living.animal.tameable;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityData;
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
||||||
import org.geysermc.connector.entity.type.EntityType;
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
|
@ -39,9 +40,14 @@ public class WolfEntity extends TameableEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||||
|
// "Begging" on wiki.vg, "Interested" in Nukkit - the tilt of the head
|
||||||
|
if (entityMetadata.getId() == 18) {
|
||||||
|
metadata.getFlags().setFlag(EntityFlag.INTERESTED, (boolean) entityMetadata.getValue());
|
||||||
|
}
|
||||||
|
// Wolf collar color
|
||||||
|
// Relies on EntityData.OWNER_EID being set in TameableEntity.java
|
||||||
if (entityMetadata.getId() == 19) {
|
if (entityMetadata.getId() == 19) {
|
||||||
// FIXME: Colors the whole animal instead of just collar
|
metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue());
|
||||||
// metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue());
|
|
||||||
}
|
}
|
||||||
super.updateBedrockMetadata(entityMetadata, session);
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,8 @@ import lombok.Getter;
|
||||||
import org.geysermc.connector.entity.*;
|
import org.geysermc.connector.entity.*;
|
||||||
import org.geysermc.connector.entity.living.*;
|
import org.geysermc.connector.entity.living.*;
|
||||||
import org.geysermc.connector.entity.living.animal.*;
|
import org.geysermc.connector.entity.living.animal.*;
|
||||||
import org.geysermc.connector.entity.living.animal.tameable.CatEntity;
|
|
||||||
import org.geysermc.connector.entity.living.animal.tameable.TameableEntity;
|
|
||||||
import org.geysermc.connector.entity.living.animal.horse.*;
|
import org.geysermc.connector.entity.living.animal.horse.*;
|
||||||
import org.geysermc.connector.entity.living.animal.tameable.WolfEntity;
|
import org.geysermc.connector.entity.living.animal.tameable.*;
|
||||||
import org.geysermc.connector.entity.living.monster.*;
|
import org.geysermc.connector.entity.living.monster.*;
|
||||||
import org.geysermc.connector.entity.living.monster.raid.AbstractIllagerEntity;
|
import org.geysermc.connector.entity.living.monster.raid.AbstractIllagerEntity;
|
||||||
import org.geysermc.connector.entity.living.monster.raid.RaidParticipantEntity;
|
import org.geysermc.connector.entity.living.monster.raid.RaidParticipantEntity;
|
||||||
|
@ -62,7 +60,7 @@ public enum EntityType {
|
||||||
POLAR_BEAR(PolarBearEntity.class, 28, 1.4f, 1.3f),
|
POLAR_BEAR(PolarBearEntity.class, 28, 1.4f, 1.3f),
|
||||||
LLAMA(LlamaEntity.class, 29, 1.87f, 0.9f),
|
LLAMA(LlamaEntity.class, 29, 1.87f, 0.9f),
|
||||||
TRADER_LLAMA(TraderLlamaEntity.class, 29, 1.187f, 0.9f),
|
TRADER_LLAMA(TraderLlamaEntity.class, 29, 1.187f, 0.9f),
|
||||||
PARROT(TameableEntity.class, 30, 0.9f, 0.5f),
|
PARROT(ParrotEntity.class, 30, 0.9f, 0.5f),
|
||||||
DOLPHIN(WaterEntity.class, 31, 0.6f, 0.9f),
|
DOLPHIN(WaterEntity.class, 31, 0.6f, 0.9f),
|
||||||
ZOMBIE(ZombieEntity.class, 32, 1.8f, 0.6f, 0.6f, 1.62f),
|
ZOMBIE(ZombieEntity.class, 32, 1.8f, 0.6f, 0.6f, 1.62f),
|
||||||
CREEPER(CreeperEntity.class, 33, 1.7f, 0.6f, 0.6f, 1.62f),
|
CREEPER(CreeperEntity.class, 33, 1.7f, 0.6f, 0.6f, 1.62f),
|
||||||
|
|
Loading…
Reference in a new issue