From 03c611224bddecd0ce4201362d3fd30940e7c03b Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Tue, 7 Apr 2020 19:38:44 -0400 Subject: [PATCH 1/4] Add llama decoration support --- .../living/animal/horse/LlamaEntity.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java index b4c958904..e7e2f7825 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java @@ -47,6 +47,24 @@ public class LlamaEntity extends ChestedHorseEntity { if (entityMetadata.getId() == 19) { metadata.put(EntityData.STRENGTH, entityMetadata.getValue()); } + // Color equipped on the llama + if (entityMetadata.getId() == 20) { + // Bedrock treats llama decoration as armor + MobArmorEquipmentPacket equipmentPacket = new MobArmorEquipmentPacket(); + equipmentPacket.setRuntimeEntityId(getGeyserId()); + if ((int) entityMetadata.getValue() != -1) { + // The damage value is the dye color that Java sends us + // Always going to be a carpet so we can hardcode 171 + // The int then short conversion is required or we get a ClassCastException + equipmentPacket.setChestplate(ItemData.of(171, (short)((int) entityMetadata.getValue()), 1)); + } else equipmentPacket.setChestplate(ItemData.of(0, (short) 0, 0)); + // Required to fill out the rest of the equipment or Bedrock ignores it + equipmentPacket.setBoots(ItemData.of(0, (short) 0, 0)); + equipmentPacket.setHelmet(ItemData.of(0, (short) 0, 0)); + equipmentPacket.setLeggings(ItemData.of(0, (short) 0, 0)); + + session.getUpstream().sendPacket(equipmentPacket); + } // Color of the llama if (entityMetadata.getId() == 21) { metadata.put(EntityData.VARIANT, entityMetadata.getValue()); From bbf0baf948b27249307d652d0500cbe057256056 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Tue, 7 Apr 2020 19:40:35 -0400 Subject: [PATCH 2/4] Additional explanation comment --- .../connector/entity/living/animal/horse/LlamaEntity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java index e7e2f7825..c6657602d 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java @@ -52,6 +52,7 @@ public class LlamaEntity extends ChestedHorseEntity { // Bedrock treats llama decoration as armor MobArmorEquipmentPacket equipmentPacket = new MobArmorEquipmentPacket(); equipmentPacket.setRuntimeEntityId(getGeyserId()); + // -1 means no armor if ((int) entityMetadata.getValue() != -1) { // The damage value is the dye color that Java sends us // Always going to be a carpet so we can hardcode 171 From 20700998b1337aa69b2a617d033a6a52e66ab715 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Tue, 7 Apr 2020 19:57:34 -0400 Subject: [PATCH 3/4] Fix requested changes; remove unused import --- .../entity/living/animal/horse/LlamaEntity.java | 13 +++++++------ .../network/translators/block/BlockTranslator.java | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java index c6657602d..e20132c5e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java @@ -26,7 +26,6 @@ package org.geysermc.connector.entity.living.animal.horse; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; -import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.EntityData; import com.nukkitx.protocol.bedrock.data.ItemData; @@ -57,12 +56,14 @@ public class LlamaEntity extends ChestedHorseEntity { // The damage value is the dye color that Java sends us // Always going to be a carpet so we can hardcode 171 // The int then short conversion is required or we get a ClassCastException - equipmentPacket.setChestplate(ItemData.of(171, (short)((int) entityMetadata.getValue()), 1)); - } else equipmentPacket.setChestplate(ItemData.of(0, (short) 0, 0)); + equipmentPacket.setChestplate(ItemData.of(BlockTranslator.LLAMA_ARMOR_ID, (short)((int) entityMetadata.getValue()), 1)); + } else { + equipmentPacket.setChestplate(ItemData.AIR); + } // Required to fill out the rest of the equipment or Bedrock ignores it - equipmentPacket.setBoots(ItemData.of(0, (short) 0, 0)); - equipmentPacket.setHelmet(ItemData.of(0, (short) 0, 0)); - equipmentPacket.setLeggings(ItemData.of(0, (short) 0, 0)); + equipmentPacket.setBoots(ItemData.AIR); + equipmentPacket.setHelmet(ItemData.AIR); + equipmentPacket.setLeggings(ItemData.AIR); session.getUpstream().sendPacket(equipmentPacket); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java index 98846e882..66d476702 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java @@ -55,6 +55,9 @@ public class BlockTranslator { private static final Int2ObjectMap BEDROCK_TO_JAVA_BLOCK_MAP = new Int2ObjectOpenHashMap<>(); private static final IntSet WATERLOGGED = new IntOpenHashSet(); + // Carpet ID, used in LlamaEntity.java + public static final int LLAMA_ARMOR_ID = 171; + private static final int BLOCK_STATE_VERSION = 17760256; static { From d4f23379ef3116c92c71bb1b59f0e9fe35c82cb3 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Tue, 7 Apr 2020 20:06:20 -0400 Subject: [PATCH 4/4] Fix requested change; modify comments --- .../connector/entity/living/animal/horse/LlamaEntity.java | 6 +++--- .../network/translators/block/BlockTranslator.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java index e20132c5e..26c13a5ce 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java @@ -54,13 +54,13 @@ public class LlamaEntity extends ChestedHorseEntity { // -1 means no armor if ((int) entityMetadata.getValue() != -1) { // The damage value is the dye color that Java sends us - // Always going to be a carpet so we can hardcode 171 + // Always going to be a carpet so we can hardcode 171 in BlockTranslator // The int then short conversion is required or we get a ClassCastException - equipmentPacket.setChestplate(ItemData.of(BlockTranslator.LLAMA_ARMOR_ID, (short)((int) entityMetadata.getValue()), 1)); + equipmentPacket.setChestplate(ItemData.of(BlockTranslator.CARPET, (short)((int) entityMetadata.getValue()), 1)); } else { equipmentPacket.setChestplate(ItemData.AIR); } - // Required to fill out the rest of the equipment or Bedrock ignores it + // Required to fill out the rest of the equipment or Bedrock ignores it, including above else statement if removing armor equipmentPacket.setBoots(ItemData.AIR); equipmentPacket.setHelmet(ItemData.AIR); equipmentPacket.setLeggings(ItemData.AIR); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java index 66d476702..906179d1f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java @@ -55,8 +55,8 @@ public class BlockTranslator { private static final Int2ObjectMap BEDROCK_TO_JAVA_BLOCK_MAP = new Int2ObjectOpenHashMap<>(); private static final IntSet WATERLOGGED = new IntOpenHashSet(); - // Carpet ID, used in LlamaEntity.java - public static final int LLAMA_ARMOR_ID = 171; + // Bedrock carpet ID, used in LlamaEntity.java for decoration + public static final int CARPET = 171; private static final int BLOCK_STATE_VERSION = 17760256;