diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java index b378a4310..de58cc26c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java @@ -236,7 +236,7 @@ public final class EntityDefinitions { .type(EntityType.EXPERIENCE_ORB) .identifier("minecraft:xp_orb") .build(); - EVOKER_FANGS = EntityDefinition.builder(EvokerFangsEntity::new) // No entity metadata to listen to as of 1.18.1 + EVOKER_FANGS = EntityDefinition.inherited(EvokerFangsEntity::new, entityBase) .type(EntityType.EVOKER_FANGS) .height(0.8f).width(0.5f) .identifier("minecraft:evocation_fang") @@ -847,6 +847,7 @@ public final class EntityDefinitions { .type(EntityType.SNIFFER) .height(1.75f).width(1.9f) .addTranslator(MetadataType.SNIFFER_STATE, SnifferEntity::setSnifferState) + .addTranslator(null) // Integer, drop seed at tick .build(); STRIDER = EntityDefinition.inherited(StriderEntity::new, ageableEntityBase) .type(EntityType.STRIDER) @@ -890,7 +891,6 @@ public final class EntityDefinitions { .build(); CAMEL = EntityDefinition.inherited(CamelEntity::new, abstractHorseEntityBase) .type(EntityType.CAMEL) - .identifier("minecraft:llama") // todo 1.20 .height(2.375f).width(1.7f) .addTranslator(MetadataType.BOOLEAN, CamelEntity::setDashing) .addTranslator(null) // Last pose change tick diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java index 9cdd30bde..2cf4632fb 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java @@ -29,11 +29,14 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.SnifferState; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ObjectEntityMetadata; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class SnifferEntity extends AnimalEntity { + private static final float DIGGING_HEIGHT = EntityDefinitions.SNIFFER.height() - 0.4f; + public SnifferEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java index ed46cfc2a..09067eff2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java @@ -28,7 +28,6 @@ package org.geysermc.geyser.entity.type.living.animal.horse; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.cloudburstmc.math.vector.Vector3f; -import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.Item; @@ -44,12 +43,6 @@ public class CamelEntity extends AbstractHorseEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - @Override - protected void initializeMetadata() { - super.initializeMetadata(); - this.dirtyMetadata.put(EntityDataTypes.VARIANT, 2); // Closest llama colour to camel - } - @Override public boolean canEat(Item item) { return item == Items.CACTUS; diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SignBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SignBlockEntityTranslator.java index 44f3b7362..f9c228f5f 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SignBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SignBlockEntityTranslator.java @@ -27,8 +27,11 @@ package org.geysermc.geyser.translator.level.block.entity; import com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; +import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.translator.text.MessageTranslator; import org.geysermc.geyser.util.SignUtils; @@ -66,52 +69,66 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator { @Override public void translateTag(NbtMapBuilder builder, CompoundTag tag, int blockState) { + builder.putCompound("FrontText", translateSide(tag.get("front_text"))); + builder.putCompound("BackText", translateSide(tag.get("back_text"))); + var waxed = tag.get("is_waxed"); + builder.putBoolean("IsWaxed", waxed != null && waxed.getValue() instanceof Number number && number.byteValue() != 0); + } + + private NbtMap translateSide(Tag tag) { + if (!(tag instanceof CompoundTag signData)) { + return NbtMap.EMPTY; + } + NbtMapBuilder builder = NbtMap.builder(); + StringBuilder signText = new StringBuilder(); - for (int i = 0; i < 4; i++) { - int currentLine = i + 1; - String signLine = getOrDefault(tag.getValue().get("Text" + currentLine), ""); - signLine = MessageTranslator.convertMessageLenient(signLine); + Tag messages = signData.get("messages"); + if (messages instanceof ListTag listTag) { + for (int i = 0; i < listTag.size(); i++) { + String signLine = (String) listTag.get(i).getValue(); + signLine = MessageTranslator.convertMessageLenient(signLine); - // Check the character width on the sign to ensure there is no overflow that is usually hidden - // to Java Edition clients but will appear to Bedrock clients - int signWidth = 0; - StringBuilder finalSignLine = new StringBuilder(); - boolean previousCharacterWasFormatting = false; // Color changes do not count for maximum width - for (char c : signLine.toCharArray()) { - if (c == '\u00a7') { - // Don't count this character - previousCharacterWasFormatting = true; - } else if (previousCharacterWasFormatting) { - // Don't count this character either - previousCharacterWasFormatting = false; - } else { - signWidth += SignUtils.getCharacterWidth(c); + // Check the character width on the sign to ensure there is no overflow that is usually hidden + // to Java Edition clients but will appear to Bedrock clients + int signWidth = 0; + StringBuilder finalSignLine = new StringBuilder(); + boolean previousCharacterWasFormatting = false; // Color changes do not count for maximum width + for (char c : signLine.toCharArray()) { + if (c == ChatColor.ESCAPE) { + // Don't count this character + previousCharacterWasFormatting = true; + } else if (previousCharacterWasFormatting) { + // Don't count this character either + previousCharacterWasFormatting = false; + } else { + signWidth += SignUtils.getCharacterWidth(c); + } + + // todo 1.20: update for hanging signs (smaller width). Currently OK because bedrock sees hanging signs as normal signs + if (signWidth <= SignUtils.BEDROCK_CHARACTER_WIDTH_MAX) { + finalSignLine.append(c); + } else { + // Adding the character would make Bedrock move to the next line - Java doesn't do that, so we do not want to + break; + } } - // todo 1.20: update for hanging signs (smaller width). Currently OK because bedrock sees hanging signs as normal signs - if (signWidth <= SignUtils.BEDROCK_CHARACTER_WIDTH_MAX) { - finalSignLine.append(c); - } else { - // Adding the character would make Bedrock move to the next line - Java doesn't do that, so we do not want to - break; - } + signText.append(finalSignLine); + signText.append("\n"); } - - signText.append(finalSignLine); - signText.append("\n"); } builder.putString("Text", signText.toString()); // Java Edition 1.14 added the ability to change the text color of the whole sign using dye - Tag color = tag.get("Color"); + Tag color = signData.get("Color"); if (color != null) { builder.putInt("SignTextColor", getBedrockSignColor(color.getValue().toString())); } // Glowing text - boolean isGlowing = getOrDefault(tag.getValue().get("GlowingText"), (byte) 0) != (byte) 0; + boolean isGlowing = getOrDefault(signData.get("GlowingText"), (byte) 0) != (byte) 0; builder.putBoolean("IgnoreLighting", isGlowing); - builder.putBoolean("TextIgnoreLegacyBugResolved", isGlowing); // ??? required + return builder.build(); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaOpenSignEditorTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaOpenSignEditorTranslator.java index 811ed1ebd..0427c9dfc 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaOpenSignEditorTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaOpenSignEditorTranslator.java @@ -38,7 +38,7 @@ public class JavaOpenSignEditorTranslator extends PacketTranslator