From a305c22665b830f60bfc054819796788f4474e84 Mon Sep 17 00:00:00 2001 From: David Choo Date: Fri, 26 Nov 2021 23:03:46 -0500 Subject: [PATCH] 1.18 entity name and metadata changes (#2651) * Fix amount & javaId being used before it is initialized Fixes invisible falling blocks and incorrectly sized exp orbs * Add missing item metadata to throwable items and fireballs Renamed ItemedFireballEntity -> FireballEntity * Renamed more EntityDefinitions to match MCProtocolLib * Add some missing metadata and add null check * Use entity type when possible in debug spawn message Fallback onto classes simple name Also don't register ENDER_DRAGON_PART * Remove redundant entity identifiers and fix END_CRYSTAL and FISHING_BOBBER identifiers minecraft:end_crystal -> minecraft:ender_crystal minecraft:fishing_book -> minecraft:fishing_hook * Cave spider should inherit metadata from spider * Keep entity definitions in roughly alphabetical order * Alphabetize entity definitions * ABCs? * Bump MCProtocolLib version --- core/pom.xml | 2 +- .../geyser/entity/EntityDefinitions.java | 151 +++++++++--------- .../geyser/entity/InteractiveTagManager.java | 6 +- .../geysermc/geyser/entity/type/Entity.java | 9 +- .../geyser/entity/type/ExpOrbEntity.java | 8 - .../entity/type/FallingBlockEntity.java | 6 - ...ireballEntity.java => FireballEntity.java} | 4 +- .../geyser/entity/type/ThrowableEntity.java | 18 +-- .../entity/type/ThrowableItemEntity.java | 5 + .../entity/type/ThrownPotionEntity.java | 37 +++-- .../geyser/entity/type/WitherSkullEntity.java | 2 +- .../BedrockEntityPickRequestTranslator.java | 4 +- .../entity/JavaEntityEventTranslator.java | 2 +- .../org/geysermc/geyser/util/EntityUtils.java | 8 +- 14 files changed, 135 insertions(+), 127 deletions(-) rename core/src/main/java/org/geysermc/geyser/entity/type/{ItemedFireballEntity.java => FireballEntity.java} (91%) diff --git a/core/pom.xml b/core/pom.xml index 39ea986b2..09d4dc978 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -155,7 +155,7 @@ com.github.GeyserMC MCProtocolLib - 7f7808e2 + f7f84e7 compile 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 c8f413e63..e1f2169ef 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java @@ -63,36 +63,43 @@ public final class EntityDefinitions { public static final EntityDefinition BLAZE; public static final EntityDefinition BOAT; public static final EntityDefinition CAT; - public static final EntityDefinition CAVE_SPIDER; + public static final EntityDefinition CAVE_SPIDER; + public static final EntityDefinition CHEST_MINECART; public static final EntityDefinition CHICKEN; - public static final EntityDefinition CREEPER; public static final EntityDefinition COD; + public static final EntityDefinition COMMAND_BLOCK_MINECART; public static final EntityDefinition COW; - public static final EntityDefinition DONKEY; + public static final EntityDefinition CREEPER; public static final EntityDefinition DOLPHIN; - public static final EntityDefinition DRAGON_FIREBALL; + public static final EntityDefinition DONKEY; + public static final EntityDefinition DRAGON_FIREBALL; public static final EntityDefinition DROWNED; + public static final EntityDefinition EGG; public static final EntityDefinition ELDER_GUARDIAN; public static final EntityDefinition ENDERMAN; public static final EntityDefinition ENDERMITE; public static final EntityDefinition ENDER_DRAGON; + public static final EntityDefinition ENDER_PEARL; public static final EntityDefinition END_CRYSTAL; public static final EntityDefinition EVOKER; public static final EntityDefinition EVOKER_FANGS; + public static final EntityDefinition EXPERIENCE_BOTTLE; public static final EntityDefinition EXPERIENCE_ORB; public static final EntityDefinition EYE_OF_ENDER; public static final EntityDefinition FALLING_BLOCK; - public static final EntityDefinition FIREBALL; - public static final EntityDefinition FISHING_BOBBER; + public static final EntityDefinition FIREBALL; public static final EntityDefinition FIREWORK_ROCKET; + public static final EntityDefinition FISHING_BOBBER; public static final EntityDefinition FOX; - public static final EntityDefinition GIANT; + public static final EntityDefinition FURNACE_MINECART; // Not present on Bedrock public static final EntityDefinition GHAST; + public static final EntityDefinition GIANT; public static final EntityDefinition GLOW_ITEM_FRAME; public static final EntityDefinition GLOW_SQUID; public static final EntityDefinition GOAT; public static final EntityDefinition GUARDIAN; public static final EntityDefinition HOGLIN; + public static final EntityDefinition HOPPER_MINECART; public static final EntityDefinition HORSE; public static final EntityDefinition HUSK; public static final EntityDefinition ILLUSIONER; // Not present on Bedrock @@ -105,12 +112,6 @@ public final class EntityDefinitions { public static final EntityDefinition LLAMA_SPIT; public static final EntityDefinition MAGMA_CUBE; public static final EntityDefinition MINECART; - public static final EntityDefinition MINECART_CHEST; - public static final EntityDefinition MINECART_COMMAND_BLOCK; - public static final EntityDefinition MINECART_HOPPER; - public static final EntityDefinition MINECART_FURNACE; // Not present on Bedrock - public static final EntityDefinition MINECART_SPAWNER; // Not present on Bedrock - public static final EntityDefinition MINECART_TNT; public static final EntityDefinition MOOSHROOM; public static final EntityDefinition MULE; public static final EntityDefinition OCELOT; @@ -124,7 +125,7 @@ public final class EntityDefinitions { public static final EntityDefinition PILLAGER; public static final EntityDefinition PLAYER; public static final EntityDefinition POLAR_BEAR; - public static final EntityDefinition PRIMED_TNT; + public static final EntityDefinition POTION; public static final EntityDefinition PUFFERFISH; public static final EntityDefinition RABBIT; public static final EntityDefinition RAVAGER; @@ -136,31 +137,30 @@ public final class EntityDefinitions { public static final EntityDefinition SKELETON; public static final EntityDefinition SKELETON_HORSE; public static final EntityDefinition SLIME; - public static final EntityDefinition SMALL_FIREBALL; + public static final EntityDefinition SMALL_FIREBALL; public static final EntityDefinition SNOWBALL; public static final EntityDefinition SNOW_GOLEM; + public static final EntityDefinition SPAWNER_MINECART; // Not present on Bedrock public static final EntityDefinition SPECTRAL_ARROW; public static final EntityDefinition SPIDER; public static final EntityDefinition SQUID; public static final EntityDefinition STRAY; public static final EntityDefinition STRIDER; - public static final EntityDefinition THROWN_EGG; - public static final EntityDefinition THROWN_ENDERPEARL; - public static final EntityDefinition THROWN_EXP_BOTTLE; - public static final EntityDefinition THROWN_POTION; - public static final EntityDefinition TROPICAL_FISH; - public static final EntityDefinition TURTLE; + public static final EntityDefinition TNT; + public static final EntityDefinition TNT_MINECART; public static final EntityDefinition TRADER_LLAMA; public static final EntityDefinition TRIDENT; + public static final EntityDefinition TROPICAL_FISH; + public static final EntityDefinition TURTLE; + public static final EntityDefinition VEX; + public static final EntityDefinition VILLAGER; + public static final EntityDefinition VINDICATOR; public static final EntityDefinition WANDERING_TRADER; public static final EntityDefinition WITCH; public static final EntityDefinition WITHER; public static final EntityDefinition WITHER_SKELETON; public static final EntityDefinition WITHER_SKULL; public static final EntityDefinition WOLF; - public static final EntityDefinition VILLAGER; - public static final EntityDefinition VINDICATOR; - public static final EntityDefinition VEX; public static final EntityDefinition ZOGLIN; public static final EntityDefinition ZOMBIE; public static final EntityDefinition ZOMBIE_HORSE; @@ -212,13 +212,14 @@ public final class EntityDefinitions { .addTranslator(MetadataType.BOOLEAN, BoatEntity::setPaddlingRight) .addTranslator(MetadataType.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityData.BOAT_BUBBLE_TIME, entityMetadata.getValue())) // May not actually do anything .build(); - DRAGON_FIREBALL = EntityDefinition.inherited(ItemedFireballEntity::new, entityBase) + DRAGON_FIREBALL = EntityDefinition.inherited(FireballEntity::new, entityBase) .type(EntityType.DRAGON_FIREBALL) .heightAndWidth(1.0f) .build(); END_CRYSTAL = EntityDefinition.inherited(EnderCrystalEntity::new, entityBase) .type(EntityType.END_CRYSTAL) .heightAndWidth(2.0f) + .identifier("minecraft:ender_crystal") .addTranslator(MetadataType.OPTIONAL_POSITION, EnderCrystalEntity::setBlockTarget) .addTranslator(MetadataType.BOOLEAN, (enderCrystalEntity, entityMetadata) -> enderCrystalEntity.setFlag(EntityFlag.SHOW_BOTTOM, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) // There is a base located on the ender crystal @@ -236,16 +237,13 @@ public final class EntityDefinitions { .type(EntityType.EYE_OF_ENDER) .heightAndWidth(0.25f) .identifier("minecraft:eye_of_ender_signal") + .addTranslator(null) // Item .build(); FALLING_BLOCK = EntityDefinition.inherited(null, entityBase) .type(EntityType.FALLING_BLOCK) .heightAndWidth(0.98f) .addTranslator(null) // "start block position" .build(); - FIREBALL = EntityDefinition.inherited(ItemedFireballEntity::new, entityBase) - .type(EntityType.FIREBALL) - .heightAndWidth(1.0f) - .build(); FIREWORK_ROCKET = EntityDefinition.inherited(FireworkEntity::new, entityBase) .type(EntityType.FIREWORK_ROCKET) .heightAndWidth(0.25f) @@ -256,8 +254,9 @@ public final class EntityDefinitions { .build(); FISHING_BOBBER = EntityDefinition.inherited(null, entityBase) .type(EntityType.FISHING_BOBBER) - .identifier("minecraft:fishing_book") + .identifier("minecraft:fishing_hook") .addTranslator(MetadataType.INT, FishingHookEntity::setHookedEntity) + .addTranslator(null) // Biting TODO check .build(); ITEM = EntityDefinition.inherited(ItemEntity::new, entityBase) .type(EntityType.ITEM) @@ -279,44 +278,52 @@ public final class EntityDefinitions { PAINTING = EntityDefinition.inherited((PaintingEntityFactory) PaintingEntity::new, entityBase) .type(EntityType.PAINTING) .build(); - PRIMED_TNT = EntityDefinition.inherited(TNTEntity::new, entityBase) - .type(EntityType.PRIMED_TNT) - .heightAndWidth(0.98f) - .identifier("minecraft:tnt") - .addTranslator(MetadataType.INT, TNTEntity::setFuseLength) - .build(); SHULKER_BULLET = EntityDefinition.inherited(ThrowableEntity::new, entityBase) .type(EntityType.SHULKER_BULLET) .heightAndWidth(0.3125f) .build(); - SMALL_FIREBALL = EntityDefinition.inherited(ItemedFireballEntity::new, entityBase) + TNT = EntityDefinition.inherited(TNTEntity::new, entityBase) + .type(EntityType.TNT) + .heightAndWidth(0.98f) + .addTranslator(MetadataType.INT, TNTEntity::setFuseLength) + .build(); + + EntityDefinition fireballBase = EntityDefinition.inherited(FireballEntity::new, entityBase) + .addTranslator(null) // Item + .build(); + FIREBALL = EntityDefinition.inherited(FireballEntity::new, fireballBase) + .type(EntityType.FIREBALL) + .heightAndWidth(1.0f) + .build(); + SMALL_FIREBALL = EntityDefinition.inherited(FireballEntity::new, fireballBase) .type(EntityType.SMALL_FIREBALL) .heightAndWidth(0.3125f) .build(); - SNOWBALL = EntityDefinition.inherited(ThrowableItemEntity::new, entityBase) - .type(EntityType.SNOWBALL) + + EntityDefinition throwableItemBase = EntityDefinition.inherited(ThrowableItemEntity::new, entityBase) + .addTranslator(MetadataType.ITEM, ThrowableItemEntity::setItem) + .build(); + EGG = EntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) + .type(EntityType.EGG) .heightAndWidth(0.25f) .build(); - THROWN_ENDERPEARL = EntityDefinition.inherited(ThrowableItemEntity::new, entityBase) - .type(EntityType.THROWN_ENDERPEARL) + ENDER_PEARL = EntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) + .type(EntityType.ENDER_PEARL) .heightAndWidth(0.25f) - .identifier("minecraft:ender_pearl") .build(); - THROWN_EGG = EntityDefinition.inherited(ThrowableItemEntity::new, entityBase) - .type(EntityType.THROWN_EGG) - .heightAndWidth(0.25f) - .identifier("minecraft:egg") - .build(); - THROWN_EXP_BOTTLE = EntityDefinition.inherited(ThrowableItemEntity::new, entityBase) - .type(EntityType.THROWN_EXP_BOTTLE) + EXPERIENCE_BOTTLE = EntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) + .type(EntityType.EXPERIENCE_BOTTLE) .heightAndWidth(0.25f) .identifier("minecraft:xp_bottle") .build(); - THROWN_POTION = EntityDefinition.inherited(ThrownPotionEntity::new, entityBase) - .type(EntityType.THROWN_POTION) + POTION = EntityDefinition.inherited(ThrownPotionEntity::new, throwableItemBase) + .type(EntityType.POTION) .heightAndWidth(0.25f) .identifier("minecraft:splash_potion") - .addTranslator(MetadataType.ITEM, ThrownPotionEntity::setPotion) + .build(); + SNOWBALL = EntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) + .type(EntityType.SNOWBALL) + .heightAndWidth(0.25f) .build(); EntityDefinition abstractArrowBase = EntityDefinition.inherited(AbstractArrowEntity::new, entityBase) @@ -363,32 +370,28 @@ public final class EntityDefinitions { .addTranslator(MetadataType.INT, MinecartEntity::setCustomBlockOffset) .addTranslator(MetadataType.BOOLEAN, MinecartEntity::setShowCustomBlock) .build(); - MINECART_CHEST = EntityDefinition.inherited(MINECART.factory(), MINECART) - .type(EntityType.MINECART_CHEST) - .identifier("minecraft:chest_minecart") + CHEST_MINECART = EntityDefinition.inherited(MINECART.factory(), MINECART) + .type(EntityType.CHEST_MINECART) .build(); - MINECART_COMMAND_BLOCK = EntityDefinition.inherited(CommandBlockMinecartEntity::new, MINECART) - .type(EntityType.MINECART_COMMAND_BLOCK) - .identifier("minecraft:command_block_minecart") + COMMAND_BLOCK_MINECART = EntityDefinition.inherited(CommandBlockMinecartEntity::new, MINECART) + .type(EntityType.COMMAND_BLOCK_MINECART) .addTranslator(MetadataType.STRING, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.COMMAND_BLOCK_COMMAND, entityMetadata.getValue())) .addTranslator(MetadataType.CHAT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.COMMAND_BLOCK_LAST_OUTPUT, MessageTranslator.convertMessage(entityMetadata.getValue()))) .build(); - MINECART_FURNACE = EntityDefinition.inherited(FurnaceMinecartEntity::new, MINECART) - .type(EntityType.MINECART_FURNACE) + FURNACE_MINECART = EntityDefinition.inherited(FurnaceMinecartEntity::new, MINECART) + .type(EntityType.FURNACE_MINECART) .identifier("minecraft:minecart") .addTranslator(MetadataType.BOOLEAN, FurnaceMinecartEntity::setHasFuel) .build(); - MINECART_HOPPER = EntityDefinition.inherited(MINECART.factory(), MINECART) - .type(EntityType.MINECART_HOPPER) - .identifier("minecraft:hopper_minecart") + HOPPER_MINECART = EntityDefinition.inherited(MINECART.factory(), MINECART) + .type(EntityType.HOPPER_MINECART) .build(); - MINECART_SPAWNER = EntityDefinition.inherited(SpawnerMinecartEntity::new, MINECART) - .type(EntityType.MINECART_SPAWNER) + SPAWNER_MINECART = EntityDefinition.inherited(SpawnerMinecartEntity::new, MINECART) + .type(EntityType.SPAWNER_MINECART) .identifier("minecraft:minecart") .build(); - MINECART_TNT = EntityDefinition.inherited(MINECART.factory(), MINECART) - .type(EntityType.MINECART_TNT) - .identifier("minecraft:tnt_minecart") + TNT_MINECART = EntityDefinition.inherited(MINECART.factory(), MINECART) + .type(EntityType.TNT_MINECART) .build(); WITHER_SKULL = EntityDefinition.inherited(WitherSkullEntity::new, entityBase) @@ -451,10 +454,6 @@ public final class EntityDefinitions { .height(1.8f).width(0.6f) .addTranslator(MetadataType.BYTE, BlazeEntity::setBlazeFlags) .build(); - CAVE_SPIDER = EntityDefinition.inherited(MonsterEntity::new, mobEntityBase) - .type(EntityType.CAVE_SPIDER) - .height(0.5f).width(0.7f) - .build(); CREEPER = EntityDefinition.inherited(CreeperEntity::new, mobEntityBase) .type(EntityType.CREEPER) .height(1.7f).width(0.6f) @@ -536,6 +535,10 @@ public final class EntityDefinitions { .offset(1f) .addTranslator(MetadataType.BYTE, SpiderEntity::setSpiderFlags) .build(); + CAVE_SPIDER = EntityDefinition.inherited(SpiderEntity::new, SPIDER) + .type(EntityType.CAVE_SPIDER) + .height(0.5f).width(0.7f) + .build(); SQUID = EntityDefinition.inherited(SquidEntity::new, mobEntityBase) .type(EntityType.SQUID) .heightAndWidth(0.8f) @@ -732,6 +735,8 @@ public final class EntityDefinitions { .height(0.5f).width(1.25f) .addTranslator(MetadataType.INT, FoxEntity::setFoxVariant) .addTranslator(MetadataType.BYTE, FoxEntity::setFoxFlags) + .addTranslator(null) // Trusted player 1 + .addTranslator(null) // Trusted player 2 .build(); HOGLIN = EntityDefinition.inherited(HoglinEntity::new, ageableEntityBase) .type(EntityType.HOGLIN) @@ -891,7 +896,7 @@ public final class EntityDefinitions { // As of 1.18 these don't track entity data at all ENDER_DRAGON_PART = EntityDefinition.builder(null) .identifier("minecraft:armor_stand") // Emulated - .build(); + .build(false); // Never sent over the network Registries.JAVA_ENTITY_IDENTIFIERS.get().put("minecraft:marker", null); // We don't need an entity definition for this as it is never sent over the network } diff --git a/core/src/main/java/org/geysermc/geyser/entity/InteractiveTagManager.java b/core/src/main/java/org/geysermc/geyser/entity/InteractiveTagManager.java index b51f83f2c..fe423dde5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/InteractiveTagManager.java +++ b/core/src/main/java/org/geysermc/geyser/entity/InteractiveTagManager.java @@ -162,9 +162,9 @@ public class InteractiveTagManager { interactiveTag = InteractiveTag.RIDE_MINECART; } break; - case MINECART_CHEST: - case MINECART_COMMAND_BLOCK: - case MINECART_HOPPER: + case CHEST_MINECART: + case COMMAND_BLOCK_MINECART: + case HOPPER_MINECART: interactiveTag = InteractiveTag.OPEN_CONTAINER; break; case PIG: diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 3b01c428f..1828f63e1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -30,6 +30,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; +import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; @@ -159,7 +160,11 @@ public class Entity { flagsDirty = false; - session.getGeyser().getLogger().debug("Spawned entity " + getClass().getName() + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); + if (session.getGeyser().getConfig().isDebugMode()) { + EntityType type = definition.entityType(); + String name = type != null ? type.name() : getClass().getSimpleName(); + session.getGeyser().getLogger().debug("Spawned entity " + name + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); + } } /** @@ -402,7 +407,7 @@ public class Entity { public float setFreezing(IntEntityMetadata entityMetadata) { // The value that Java edition gives us is in ticks, but Bedrock uses a float percentage of the strength 0.0 -> 1.0 // The Java client caps its freezing tick percentage at 140 - int freezingTicks = Math.min(((IntEntityMetadata) entityMetadata).getPrimitiveValue(), 140); + int freezingTicks = Math.min(entityMetadata.getPrimitiveValue(), 140); float freezingPercentage = freezingTicks / 140f; dirtyMetadata.put(EntityData.FREEZING_EFFECT_STRENGTH, freezingPercentage); return freezingPercentage; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java index 25135d0b5..8196d03ff 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java @@ -32,17 +32,9 @@ import org.geysermc.geyser.session.GeyserSession; public class ExpOrbEntity extends Entity { - private final int amount; - public ExpOrbEntity(GeyserSession session, int amount, long entityId, long geyserId, Vector3f position) { super(session, entityId, geyserId, null, EntityDefinitions.EXPERIENCE_ORB, position, Vector3f.ZERO, 0, 0, 0); - this.amount = amount; - } - - @Override - protected void initializeMetadata() { - super.initializeMetadata(); this.dirtyMetadata.put(EntityData.EXPERIENCE_VALUE, amount); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java index 346861f96..1f690036f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java @@ -35,16 +35,10 @@ import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class FallingBlockEntity extends Entity { - private final int javaId; public FallingBlockEntity(GeyserSession session, long entityId, long geyserId, UUID uuid, Vector3f position, Vector3f motion, float yaw, float pitch, int javaId) { super(session, entityId, geyserId, uuid, EntityDefinitions.FALLING_BLOCK, position, motion, yaw, pitch, 0f); - this.javaId = javaId; - } - @Override - protected void initializeMetadata() { - super.initializeMetadata(); this.dirtyMetadata.put(EntityData.VARIANT, session.getBlockMappings().getBedrockBlockId(javaId)); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemedFireballEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java similarity index 91% rename from core/src/main/java/org/geysermc/geyser/entity/type/ItemedFireballEntity.java rename to core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java index 49548ec2a..52796d67b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemedFireballEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java @@ -31,7 +31,7 @@ import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; -public class ItemedFireballEntity extends ThrowableEntity { +public class FireballEntity extends ThrowableEntity { private final Vector3f acceleration; /** @@ -39,7 +39,7 @@ public class ItemedFireballEntity extends ThrowableEntity { */ protected int futureTicks = 3; - public ItemedFireballEntity(GeyserSession session, long entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public FireballEntity(GeyserSession session, long entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, position, Vector3f.ZERO, yaw, pitch, headYaw); float magnitude = motion.length(); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java index 67aa09794..d68779c9f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java @@ -118,16 +118,16 @@ public class ThrowableEntity extends Entity implements Tickable { protected float getGravity() { if (getFlag(EntityFlag.HAS_GRAVITY)) { switch (definition.entityType()) { - case THROWN_POTION: + case POTION: return 0.05f; - case THROWN_EXP_BOTTLE: + case EXPERIENCE_BOTTLE: return 0.07f; case FIREBALL: case SHULKER_BULLET: return 0; case SNOWBALL: - case THROWN_EGG: - case THROWN_ENDERPEARL: + case EGG: + case ENDER_PEARL: return 0.03f; case LLAMA_SPIT: return 0.06f; @@ -144,11 +144,11 @@ public class ThrowableEntity extends Entity implements Tickable { return 0.8f; } else { switch (definition.entityType()) { - case THROWN_POTION: - case THROWN_EXP_BOTTLE: + case POTION: + case EXPERIENCE_BOTTLE: case SNOWBALL: - case THROWN_EGG: - case THROWN_ENDERPEARL: + case EGG: + case ENDER_PEARL: case LLAMA_SPIT: return 0.99f; case FIREBALL: @@ -172,7 +172,7 @@ public class ThrowableEntity extends Entity implements Tickable { @Override public boolean despawnEntity() { - if (definition.entityType() == EntityType.THROWN_ENDERPEARL) { + if (definition.entityType() == EntityType.ENDER_PEARL) { LevelEventPacket particlePacket = new LevelEventPacket(); particlePacket.setType(LevelEventType.PARTICLE_TELEPORT); particlePacket.setPosition(position); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java index 7abffd0bf..2cee252ec 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java @@ -25,6 +25,8 @@ package org.geysermc.geyser.entity.type; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; @@ -75,4 +77,7 @@ public class ThrowableItemEntity extends ThrowableEntity { protected void setInvisible(boolean value) { invisible = value; } + + public void setItem(EntityMetadata entityMetadata) { + } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java index c4cd5d54a..3b4d5674a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java @@ -48,24 +48,31 @@ public class ThrownPotionEntity extends ThrowableItemEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setPotion(EntityMetadata entityMetadata) { + @Override + public void setItem(EntityMetadata entityMetadata) { ItemStack itemStack = entityMetadata.getValue(); - ItemMapping mapping = session.getItemMappings().getMapping(itemStack); - if (mapping.getJavaIdentifier().endsWith("potion") && itemStack.getNbt() != null) { - Tag potionTag = itemStack.getNbt().get("Potion"); - if (potionTag instanceof StringTag) { - Potion potion = Potion.getByJavaIdentifier(((StringTag) potionTag).getValue()); - if (potion != null) { - dirtyMetadata.put(EntityData.POTION_AUX_VALUE, potion.getBedrockId()); - setFlag(EntityFlag.ENCHANTED, !NON_ENCHANTED_POTIONS.contains(potion)); - } else { - dirtyMetadata.put(EntityData.POTION_AUX_VALUE, 0); - GeyserImpl.getInstance().getLogger().debug("Unknown java potion: " + potionTag.getValue()); + if (itemStack == null) { + dirtyMetadata.put(EntityData.POTION_AUX_VALUE, 0); + setFlag(EntityFlag.ENCHANTED, false); + setFlag(EntityFlag.LINGERING, false); + } else { + ItemMapping mapping = session.getItemMappings().getMapping(itemStack); + if (mapping.getJavaIdentifier().endsWith("potion") && itemStack.getNbt() != null) { + Tag potionTag = itemStack.getNbt().get("Potion"); + if (potionTag instanceof StringTag) { + Potion potion = Potion.getByJavaIdentifier(((StringTag) potionTag).getValue()); + if (potion != null) { + dirtyMetadata.put(EntityData.POTION_AUX_VALUE, potion.getBedrockId()); + setFlag(EntityFlag.ENCHANTED, !NON_ENCHANTED_POTIONS.contains(potion)); + } else { + dirtyMetadata.put(EntityData.POTION_AUX_VALUE, 0); + GeyserImpl.getInstance().getLogger().debug("Unknown java potion: " + potionTag.getValue()); + } } - } - boolean isLingering = mapping.getJavaIdentifier().equals("minecraft:lingering_potion"); - setFlag(EntityFlag.LINGERING, isLingering); + boolean isLingering = mapping.getJavaIdentifier().equals("minecraft:lingering_potion"); + setFlag(EntityFlag.LINGERING, isLingering); + } } } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java index fbed041fe..f645fae34 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java @@ -33,7 +33,7 @@ import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; -public class WitherSkullEntity extends ItemedFireballEntity { +public class WitherSkullEntity extends FireballEntity { private boolean isCharged; public WitherSkullEntity(GeyserSession session, long entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockEntityPickRequestTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockEntityPickRequestTranslator.java index 732142573..580dccc88 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockEntityPickRequestTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockEntityPickRequestTranslator.java @@ -66,11 +66,11 @@ public class BedrockEntityPickRequestTranslator extends PacketTranslator itemName = "lead"; - case MINECART_CHEST, MINECART_COMMAND_BLOCK, MINECART_FURNACE, MINECART_HOPPER, MINECART_TNT -> + case CHEST_MINECART, COMMAND_BLOCK_MINECART, FURNACE_MINECART, HOPPER_MINECART, TNT_MINECART -> // The Bedrock identifier matches the item name which moves MINECART to the end of the name // TODO test itemName = entity.getDefinition().identifier(); - case MINECART_SPAWNER -> itemName = "minecart"; // Turns into a normal minecart + case SPAWNER_MINECART -> itemName = "minecart"; // Turns into a normal minecart //case ITEM_FRAME -> Not an entity in Bedrock Edition //case GLOW_ITEM_FRAME -> case ARMOR_STAND, END_CRYSTAL, MINECART, PAINTING -> diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java index 1c3239d69..eb54ad942 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java @@ -97,7 +97,7 @@ public class JavaEntityEventTranslator extends PacketTranslator mountedHeightOffset = height * 0.5f; case DONKEY, MULE -> mountedHeightOffset -= 0.25f; case LLAMA -> mountedHeightOffset = height * 0.67f; - case MINECART, MINECART_HOPPER, MINECART_TNT, MINECART_CHEST, MINECART_FURNACE, MINECART_SPAWNER, - MINECART_COMMAND_BLOCK -> mountedHeightOffset = 0; + case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART, + COMMAND_BLOCK_MINECART -> mountedHeightOffset = 0; case BOAT -> mountedHeightOffset = -0.1f; case HOGLIN, ZOGLIN -> { boolean isBaby = mount.getFlag(EntityFlag.BABY); @@ -169,8 +169,8 @@ public final class EntityUtils { yOffset += EntityDefinitions.PLAYER.offset(); } switch (mount.getDefinition().entityType()) { - case MINECART, MINECART_HOPPER, MINECART_TNT, MINECART_CHEST, MINECART_FURNACE, MINECART_SPAWNER, - MINECART_COMMAND_BLOCK, BOAT -> yOffset -= mount.getDefinition().height() * 0.5f; + case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART, + COMMAND_BLOCK_MINECART, BOAT -> yOffset -= mount.getDefinition().height() * 0.5f; } Vector3f offset = Vector3f.from(xOffset, yOffset, zOffset); passenger.setRiderSeatPosition(offset);