From 1e0b312d9dc3971248e72bfadeccf8625b4e66a4 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 20 Nov 2021 13:25:21 -0600 Subject: [PATCH] Update to support MCProtocolLib entity metadata changes --- .../connector/entity/AbstractArrowEntity.java | 5 ++- .../entity/AreaEffectCloudEntity.java | 6 ++-- .../geysermc/connector/entity/BoatEntity.java | 13 ++++---- .../entity/DefaultBlockMinecartEntity.java | 11 +++---- .../connector/entity/EnderCrystalEntity.java | 10 +++--- .../org/geysermc/connector/entity/Entity.java | 33 ++++++++++--------- .../connector/entity/EntityDefinition.java | 30 ++++++++++++++--- .../connector/entity/EntityDefinitions.java | 33 +++++++++---------- .../entity/EntityMetadataTranslator.java | 7 ++-- .../connector/entity/FallingBlockEntity.java | 5 ++- .../connector/entity/FireworkEntity.java | 4 +-- .../connector/entity/FishingHookEntity.java | 5 ++- .../entity/FurnaceMinecartEntity.java | 5 ++- .../geysermc/connector/entity/ItemEntity.java | 2 +- .../connector/entity/ItemFrameEntity.java | 6 ++-- .../connector/entity/LivingEntity.java | 19 ++++++----- .../connector/entity/MinecartEntity.java | 13 ++++---- .../geysermc/connector/entity/TNTEntity.java | 2 +- .../connector/entity/ThrownPotionEntity.java | 2 +- .../connector/entity/TippedArrowEntity.java | 5 ++- .../connector/entity/WitherSkullEntity.java | 5 ++- .../entity/living/AgeableEntity.java | 5 ++- .../entity/living/ArmorStandEntity.java | 19 ++++++----- .../connector/entity/living/BatEntity.java | 5 ++- .../connector/entity/living/MobEntity.java | 5 ++- .../connector/entity/living/SlimeEntity.java | 5 ++- .../entity/living/SnowGolemEntity.java | 5 ++- .../entity/living/animal/AxolotlEntity.java | 9 +++-- .../entity/living/animal/BeeEntity.java | 9 +++-- .../entity/living/animal/FoxEntity.java | 10 +++--- .../entity/living/animal/GoatEntity.java | 5 ++- .../entity/living/animal/HoglinEntity.java | 5 ++- .../entity/living/animal/PandaEntity.java | 17 +++++----- .../living/animal/PufferFishEntity.java | 5 ++- .../entity/living/animal/RabbitEntity.java | 8 ++--- .../entity/living/animal/SheepEntity.java | 2 +- .../entity/living/animal/StriderEntity.java | 9 +++-- .../living/animal/TropicalFishEntity.java | 5 ++- .../entity/living/animal/TurtleEntity.java | 9 +++-- .../animal/horse/AbstractHorseEntity.java | 5 ++- .../living/animal/horse/HorseEntity.java | 5 ++- .../living/animal/horse/LlamaEntity.java | 5 ++- .../living/animal/tameable/CatEntity.java | 16 ++++----- .../animal/tameable/TameableEntity.java | 11 ++++--- .../living/animal/tameable/WolfEntity.java | 13 ++++---- .../living/merchant/VillagerEntity.java | 5 +-- .../monster/AbstractSkeletonEntity.java | 5 ++- .../living/monster/BasePiglinEntity.java | 5 ++- .../entity/living/monster/BlazeEntity.java | 5 ++- .../entity/living/monster/CreeperEntity.java | 13 ++++---- .../living/monster/EnderDragonEntity.java | 8 ++--- .../entity/living/monster/EndermanEntity.java | 13 ++++---- .../entity/living/monster/GhastEntity.java | 5 ++- .../entity/living/monster/GuardianEntity.java | 5 ++- .../entity/living/monster/PhantomEntity.java | 5 ++- .../entity/living/monster/PiglinEntity.java | 13 ++++---- .../entity/living/monster/ShulkerEntity.java | 10 +++--- .../entity/living/monster/SkeletonEntity.java | 5 ++- .../entity/living/monster/SpiderEntity.java | 5 ++- .../entity/living/monster/VexEntity.java | 5 ++- .../entity/living/monster/WitherEntity.java | 15 ++++----- .../entity/living/monster/ZoglinEntity.java | 5 ++- .../entity/living/monster/ZombieEntity.java | 9 +++-- .../living/monster/ZombieVillagerEntity.java | 6 ++-- .../raid/SpellcasterIllagerEntity.java | 5 ++- .../living/monster/raid/VindicatorEntity.java | 5 ++- .../connector/entity/player/PlayerEntity.java | 20 ++++++----- .../entity/player/SessionPlayerEntity.java | 12 +++---- .../entity/JavaSetEntityDataTranslator.java | 26 +++++---------- .../loader/EnchantmentRegistryLoader.java | 1 + .../loader/ParticleTypesRegistryLoader.java | 1 + 71 files changed, 301 insertions(+), 324 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/AbstractArrowEntity.java b/connector/src/main/java/org/geysermc/connector/entity/AbstractArrowEntity.java index be07a12ce..27ca23a2e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/AbstractArrowEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/AbstractArrowEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType; import com.nukkitx.math.vector.Vector3f; @@ -45,8 +44,8 @@ public class AbstractArrowEntity extends Entity { setMotion(motion); } - public void setArrowFlags(EntityMetadata entityMetadata) { - byte data = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setArrowFlags(ByteEntityMetadata entityMetadata) { + byte data = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.CRITICAL, (data & 0x01) == 0x01); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java b/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java index 1c2830232..3e91ba0e5 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java @@ -56,13 +56,13 @@ public class AreaEffectCloudEntity extends Entity { setFlag(EntityFlag.FIRE_IMMUNE, true); } - public void setRadius(EntityMetadata entityMetadata) { - float value = ((FloatEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setRadius(FloatEntityMetadata entityMetadata) { + float value = entityMetadata.getPrimitiveValue(); dirtyMetadata.put(EntityData.AREA_EFFECT_CLOUD_RADIUS, value); dirtyMetadata.put(EntityData.BOUNDING_BOX_WIDTH, 2.0f * value); } - public void setParticle(EntityMetadata entityMetadata) { + public void setParticle(EntityMetadata entityMetadata) { Particle particle = entityMetadata.getValue(); int particleId = EffectUtils.getParticleId(session, particle.getType()); if (particleId != -1) { diff --git a/connector/src/main/java/org/geysermc/connector/entity/BoatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/BoatEntity.java index 7069f5cfb..8283511cb 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/BoatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/BoatEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; @@ -114,13 +113,13 @@ public class BoatEntity extends Entity { moveRelative(0, 0, 0, yaw + 90, 0, 0, isOnGround); } - public void setVariant(EntityMetadata entityMetadata) { - variant = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setVariant(IntEntityMetadata entityMetadata) { + variant = entityMetadata.getPrimitiveValue(); dirtyMetadata.put(EntityData.VARIANT, variant); } - public void setPaddlingLeft(EntityMetadata entityMetadata) { - isPaddlingLeft = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setPaddlingLeft(BooleanEntityMetadata entityMetadata) { + isPaddlingLeft = entityMetadata.getPrimitiveValue(); if (isPaddlingLeft) { // Java sends simply "true" and "false" (is_paddling_left), Bedrock keeps sending packets as you're rowing // This is an asynchronous method that emulates Bedrock rowing until "false" is sent. @@ -138,8 +137,8 @@ public class BoatEntity extends Entity { } } - public void setPaddlingRight(EntityMetadata entityMetadata) { - isPaddlingRight = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setPaddlingRight(BooleanEntityMetadata entityMetadata) { + isPaddlingRight = entityMetadata.getPrimitiveValue(); if (isPaddlingRight) { paddleTimeRight = 0f; if (!this.passengers.isEmpty()) { diff --git a/connector/src/main/java/org/geysermc/connector/entity/DefaultBlockMinecartEntity.java b/connector/src/main/java/org/geysermc/connector/entity/DefaultBlockMinecartEntity.java index f4991b312..bcc88c33f 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/DefaultBlockMinecartEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/DefaultBlockMinecartEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; @@ -56,7 +55,7 @@ public class DefaultBlockMinecartEntity extends MinecartEntity { } @Override - public void setCustomBlock(EntityMetadata entityMetadata) { + public void setCustomBlock(IntEntityMetadata entityMetadata) { customBlock = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); if (showCustomBlock) { @@ -65,8 +64,8 @@ public class DefaultBlockMinecartEntity extends MinecartEntity { } @Override - public void setCustomBlockOffset(EntityMetadata entityMetadata) { - customBlockOffset = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setCustomBlockOffset(IntEntityMetadata entityMetadata) { + customBlockOffset = entityMetadata.getPrimitiveValue(); if (showCustomBlock) { dirtyMetadata.put(EntityData.DISPLAY_OFFSET, customBlockOffset); @@ -74,8 +73,8 @@ public class DefaultBlockMinecartEntity extends MinecartEntity { } @Override - public void setShowCustomBlock(EntityMetadata entityMetadata) { - if (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()) { + public void setShowCustomBlock(BooleanEntityMetadata entityMetadata) { + if (entityMetadata.getPrimitiveValue()) { showCustomBlock = true; dirtyMetadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(customBlock)); dirtyMetadata.put(EntityData.DISPLAY_OFFSET, customBlockOffset); diff --git a/connector/src/main/java/org/geysermc/connector/entity/EnderCrystalEntity.java b/connector/src/main/java/org/geysermc/connector/entity/EnderCrystalEntity.java index df7c041b3..1a8a9bd5f 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/EnderCrystalEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/EnderCrystalEntity.java @@ -33,6 +33,7 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.connector.network.session.GeyserSession; +import java.util.Optional; import java.util.UUID; public class EnderCrystalEntity extends Entity { @@ -48,12 +49,13 @@ public class EnderCrystalEntity extends Entity { setFlag(EntityFlag.FIRE_IMMUNE, true); } - public void setBlockTarget(EntityMetadata entityMetadata) { + public void setBlockTarget(EntityMetadata, ?> entityMetadata) { // Show beam // Usually performed client-side on Bedrock except for Ender Dragon respawn event - Position position = entityMetadata.getValue(); - if (position != null) { - dirtyMetadata.put(EntityData.BLOCK_TARGET, Vector3i.from(position.getX(), position.getY(), position.getZ())); + Optional optionalPos = entityMetadata.getValue(); + if (optionalPos.isPresent()) { + Position pos = optionalPos.get(); + dirtyMetadata.put(EntityData.BLOCK_TARGET, Vector3i.from(pos.getX(), pos.getY(), pos.getZ())); } else { dirtyMetadata.put(EntityData.BLOCK_TARGET, Vector3i.ZERO); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index 3bf5a3a16..db7f92dca 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -47,6 +47,7 @@ import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.chat.MessageTranslator; import org.geysermc.connector.utils.MathUtils; +import java.util.Optional; import java.util.UUID; @Getter @@ -120,7 +121,7 @@ public class Entity { this.valid = false; setPosition(position); - setAir(getMaxAir()); + setAirSupply(getMaxAir()); initializeMetadata(); } @@ -304,8 +305,8 @@ public class Entity { } } - public void setFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.ON_FIRE, ((xd & 0x01) == 0x01) && !getFlag(EntityFlag.FIRE_IMMUNE)); // Otherwise immune entities sometimes flicker onfire setFlag(EntityFlag.SNEAKING, (xd & 0x02) == 0x02); setFlag(EntityFlag.SPRINTING, (xd & 0x08) == 0x08); @@ -327,11 +328,11 @@ public class Entity { /** * Set an int from 0 - this entity's maximum air - (air / maxAir) represents the percentage of bubbles left */ - public final void setAir(EntityMetadata entityMetadata) { - setAir(((IntEntityMetadata) entityMetadata).getPrimitiveValue()); + public final void setAir(IntEntityMetadata entityMetadata) { + setAirSupply(entityMetadata.getPrimitiveValue()); } - protected void setAir(int amount) { + protected void setAirSupply(int amount) { dirtyMetadata.put(EntityData.AIR_SUPPLY, (short) MathUtils.constrain(amount, 0, getMaxAir())); } @@ -339,10 +340,10 @@ public class Entity { return 300; } - public void setDisplayName(EntityMetadata entityMetadata) { - Component name = entityMetadata.getValue(); - if (name != null) { - nametag = MessageTranslator.convertMessage(name, session.getLocale()); + public void setDisplayName(EntityMetadata, ?> entityMetadata) { + Optional name = entityMetadata.getValue(); + if (name.isPresent()) { + nametag = MessageTranslator.convertMessage(name.get(), session.getLocale()); dirtyMetadata.put(EntityData.NAMETAG, nametag); } else if (!nametag.isEmpty()) { // Clear nametag @@ -350,18 +351,18 @@ public class Entity { } } - public void setDisplayNameVisible(EntityMetadata entityMetadata) { - dirtyMetadata.put(EntityData.NAMETAG_ALWAYS_SHOW, (byte) (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue() ? 1 : 0)); + public void setDisplayNameVisible(BooleanEntityMetadata entityMetadata) { + dirtyMetadata.put(EntityData.NAMETAG_ALWAYS_SHOW, (byte) (entityMetadata.getPrimitiveValue() ? 1 : 0)); } - public void setGravity(EntityMetadata entityMetadata) { - setFlag(EntityFlag.HAS_GRAVITY, !((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); + public void setGravity(BooleanEntityMetadata entityMetadata) { + setFlag(EntityFlag.HAS_GRAVITY, !entityMetadata.getPrimitiveValue()); } /** * Usually used for bounding box and not animation. */ - public void setPose(EntityMetadata entityMetadata) { + public void setPose(EntityMetadata entityMetadata) { Pose pose = entityMetadata.getValue(); setFlag(EntityFlag.SLEEPING, pose.equals(Pose.SLEEPING)); @@ -396,7 +397,7 @@ public class Entity { /** * Set a float from 0-1 - how strong the "frozen" overlay should be on screen. */ - public float setFreezing(EntityMetadata entityMetadata) { + 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); diff --git a/connector/src/main/java/org/geysermc/connector/entity/EntityDefinition.java b/connector/src/main/java/org/geysermc/connector/entity/EntityDefinition.java index e4baf1ed4..d0c7c3826 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/EntityDefinition.java +++ b/connector/src/main/java/org/geysermc/connector/entity/EntityDefinition.java @@ -31,6 +31,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import lombok.Setter; import lombok.experimental.Accessors; +import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.entity.factory.BaseEntityFactory; import org.geysermc.connector.entity.factory.EntityFactory; import org.geysermc.connector.registry.Registries; @@ -47,7 +48,7 @@ import java.util.function.BiConsumer; * @param the entity type this definition represents */ public record EntityDefinition(EntityFactory factory, EntityType entityType, String identifier, - float width, float height, float offset, List> translators) { + float width, float height, float offset, List> translators) { public static Builder inherited(BaseEntityFactory factory, EntityDefinition parent) { return inherited((EntityFactory) factory, parent); @@ -61,6 +62,25 @@ public record EntityDefinition(EntityFactory factory, Entit return new Builder<>(factory); } + + public void translateMetadata(T entity, EntityMetadata> metadata) { + EntityMetadataTranslator>> translator = (EntityMetadataTranslator>>) this.translators.get(metadata.getId()); + if (translator == null) { + // This can safely happen; it means we don't translate this entity metadata + return; + } + + if (translator.acceptedType() != metadata.getType()) { + GeyserConnector.getInstance().getLogger().warning("Metadata ID " + metadata.getId() + " was received with type " + metadata.getType() + " but we expected " + translator.acceptedType() + " for " + entity.getDefinition().entityType()); + if (GeyserConnector.getInstance().getConfig().isDebugMode()) { + GeyserConnector.getInstance().getLogger().debug(metadata.toString()); + } + return; + } + + translator.translateFunction().accept(entity, metadata); + } + @Setter @Accessors(fluent = true, chain = true) public static class Builder { @@ -70,14 +90,14 @@ public record EntityDefinition(EntityFactory factory, Entit private float width; private float height; private float offset; - private final List> translators; + private final List> translators; private Builder(EntityFactory factory) { this.factory = factory; translators = new ObjectArrayList<>(); } - public Builder(EntityFactory factory, EntityType type, String identifier, float width, float height, float offset, List> translators) { + public Builder(EntityFactory factory, EntityType type, String identifier, float width, float height, float offset, List> translators) { this.factory = factory; this.type = type; this.identifier = identifier; @@ -105,12 +125,12 @@ public record EntityDefinition(EntityFactory factory, Entit return this; } - public Builder addTranslator(MetadataType type, BiConsumer> translateFunction) { + public >> Builder addTranslator(MetadataType type, BiConsumer translateFunction) { translators.add(new EntityMetadataTranslator<>(type, translateFunction)); return this; } - public Builder addTranslator(EntityMetadataTranslator translator) { + public Builder addTranslator(EntityMetadataTranslator translator) { translators.add(translator); return this; } diff --git a/connector/src/main/java/org/geysermc/connector/entity/EntityDefinitions.java b/connector/src/main/java/org/geysermc/connector/entity/EntityDefinitions.java index f4324bcd3..4700b81c5 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/EntityDefinitions.java +++ b/connector/src/main/java/org/geysermc/connector/entity/EntityDefinitions.java @@ -31,7 +31,6 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEnt import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType; import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; -import net.kyori.adventure.text.Component; import org.geysermc.connector.entity.factory.BaseEntityFactory; import org.geysermc.connector.entity.factory.ExperienceOrbEntityFactory; import org.geysermc.connector.entity.factory.PaintingEntityFactory; @@ -182,7 +181,7 @@ public final class EntityDefinitions { .addTranslator(MetadataType.INT, Entity::setAir) // Air/bubbles .addTranslator(MetadataType.OPTIONAL_CHAT, Entity::setDisplayName) .addTranslator(MetadataType.BOOLEAN, Entity::setDisplayNameVisible) - .addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.SILENT, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) + .addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.SILENT, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataType.BOOLEAN, Entity::setGravity) .addTranslator(MetadataType.POSE, Entity::setPose) .addTranslator(MetadataType.INT, Entity::setFreezing) @@ -204,7 +203,7 @@ public final class EntityDefinitions { .offset(0.35f) .addTranslator(MetadataType.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityData.HURT_TIME, entityMetadata.getValue())) // Time since last hit .addTranslator(MetadataType.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityData.HURT_DIRECTION, entityMetadata.getValue())) // Rocking direction - .addTranslator(MetadataType.FLOAT, (boatEntity, entityMetadata) -> + .addTranslator(MetadataType.FLOAT, (boatEntity, entityMetadata) -> // 'Health' in Bedrock, damage taken in Java - it makes motion in Bedrock boatEntity.getDirtyMetadata().put(EntityData.HEALTH, 40 - ((int) ((FloatEntityMetadata) entityMetadata).getPrimitiveValue()))) .addTranslator(MetadataType.INT, BoatEntity::setVariant) @@ -220,7 +219,7 @@ public final class EntityDefinitions { .type(EntityType.END_CRYSTAL) .heightAndWidth(2.0f) .addTranslator(MetadataType.OPTIONAL_POSITION, EnderCrystalEntity::setBlockTarget) - .addTranslator(MetadataType.BOOLEAN, + .addTranslator(MetadataType.BOOLEAN, (enderCrystalEntity, entityMetadata) -> enderCrystalEntity.setFlag(EntityFlag.SHOW_BOTTOM, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) // There is a base located on the ender crystal .build(); EXPERIENCE_ORB = EntityDefinition.inherited((ExperienceOrbEntityFactory) ExpOrbEntity::new, entityBase) @@ -337,7 +336,7 @@ public final class EntityDefinitions { .type(EntityType.TRIDENT) .identifier("minecraft:thrown_trident") .addTranslator(null) // Loyalty - .addTranslator(MetadataType.BOOLEAN, (tridentEntity, entityMetadata) -> tridentEntity.setFlag(EntityFlag.ENCHANTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) + .addTranslator(MetadataType.BOOLEAN, (tridentEntity, entityMetadata) -> tridentEntity.setFlag(EntityFlag.ENCHANTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); // Item frames are handled differently as they are blocks, not items, in Bedrock @@ -356,7 +355,7 @@ public final class EntityDefinitions { .offset(0.35f) .addTranslator(MetadataType.INT, (minecartEntity, entityMetadata) -> minecartEntity.getDirtyMetadata().put(EntityData.HEALTH, entityMetadata.getValue())) .addTranslator(MetadataType.INT, (minecartEntity, entityMetadata) -> minecartEntity.getDirtyMetadata().put(EntityData.HURT_DIRECTION, entityMetadata.getValue())) // Direction in which the minecart is shaking - .addTranslator(MetadataType.FLOAT, (minecartEntity, entityMetadata) -> + .addTranslator(MetadataType.FLOAT, (minecartEntity, entityMetadata) -> // Power in Java, time in Bedrock minecartEntity.getDirtyMetadata().put(EntityData.HURT_TIME, Math.min((int) ((FloatEntityMetadata) entityMetadata).getPrimitiveValue(), 15))) .addTranslator(MetadataType.INT, MinecartEntity::setCustomBlock) @@ -371,7 +370,7 @@ public final class EntityDefinitions { .type(EntityType.MINECART_COMMAND_BLOCK) .identifier("minecraft: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()))) + .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) @@ -403,9 +402,9 @@ public final class EntityDefinitions { EntityDefinition livingEntityBase = EntityDefinition.inherited(LivingEntity::new, entityBase) .addTranslator(MetadataType.BYTE, LivingEntity::setLivingEntityFlags) .addTranslator(MetadataType.FLOAT, LivingEntity::setHealth) - .addTranslator(MetadataType.INT, + .addTranslator(MetadataType.INT, (livingEntity, entityMetadata) -> livingEntity.getDirtyMetadata().put(EntityData.EFFECT_COLOR, entityMetadata.getValue())) - .addTranslator(MetadataType.BOOLEAN, + .addTranslator(MetadataType.BOOLEAN, (livingEntity, entityMetadata) -> livingEntity.getDirtyMetadata().put(EntityData.EFFECT_AMBIENT, (byte) (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue() ? 1 : 0))) .addTranslator(null) // Arrow count .addTranslator(null) // Stinger count @@ -460,7 +459,7 @@ public final class EntityDefinitions { .height(1.7f).width(0.6f) .offset(1.62f) .addTranslator(MetadataType.INT, CreeperEntity::setSwelling) - .addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.POWERED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) + .addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.POWERED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataType.BOOLEAN, CreeperEntity::setIgnited) .build(); DOLPHIN = EntityDefinition.inherited(WaterEntity::new, mobEntityBase) @@ -746,12 +745,12 @@ public final class EntityDefinitions { MOOSHROOM = EntityDefinition.inherited(MooshroomEntity::new, ageableEntityBase) // TODO remove class .type(EntityType.MOOSHROOM) .height(1.4f).width(0.9f) - .addTranslator(MetadataType.STRING, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.VARIANT, entityMetadata.getValue().equals("brown") ? 1 : 0)) + .addTranslator(MetadataType.STRING, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.VARIANT, entityMetadata.getValue().equals("brown") ? 1 : 0)) .build(); OCELOT = EntityDefinition.inherited(OcelotEntity::new, ageableEntityBase) .type(EntityType.OCELOT) .height(0.35f).width(0.3f) - .addTranslator(MetadataType.BOOLEAN, (ocelotEntity, entityMetadata) -> ocelotEntity.setFlag(EntityFlag.TRUSTING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) + .addTranslator(MetadataType.BOOLEAN, (ocelotEntity, entityMetadata) -> ocelotEntity.setFlag(EntityFlag.TRUSTING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); PANDA = EntityDefinition.inherited(PandaEntity::new, ageableEntityBase) .type(EntityType.PANDA) @@ -766,13 +765,13 @@ public final class EntityDefinitions { PIG = EntityDefinition.inherited(PigEntity::new, ageableEntityBase) .type(EntityType.PIG) .heightAndWidth(0.9f) - .addTranslator(MetadataType.BOOLEAN, (pigEntity, entityMetadata) -> pigEntity.setFlag(EntityFlag.SADDLED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) + .addTranslator(MetadataType.BOOLEAN, (pigEntity, entityMetadata) -> pigEntity.setFlag(EntityFlag.SADDLED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(null) // Boost time .build(); POLAR_BEAR = EntityDefinition.inherited(PolarBearEntity::new, ageableEntityBase) .type(EntityType.POLAR_BEAR) .height(1.4f).width(1.3f) - .addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.STANDING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) + .addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.STANDING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); RABBIT = EntityDefinition.inherited(RabbitEntity::new, ageableEntityBase) .type(EntityType.RABBIT) @@ -839,7 +838,7 @@ public final class EntityDefinitions { .height(1.6f).width(1.3965f) .build(); EntityDefinition chestedHorseEntityBase = EntityDefinition.inherited(ChestedHorseEntity::new, abstractHorseEntityBase) - .addTranslator(MetadataType.BOOLEAN, (horseEntity, entityMetadata) -> horseEntity.setFlag(EntityFlag.CHESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) + .addTranslator(MetadataType.BOOLEAN, (horseEntity, entityMetadata) -> horseEntity.setFlag(EntityFlag.CHESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); DONKEY = EntityDefinition.inherited(chestedHorseEntityBase.factory(), chestedHorseEntityBase) .type(EntityType.DONKEY) @@ -852,7 +851,7 @@ public final class EntityDefinitions { LLAMA = EntityDefinition.inherited(LlamaEntity::new, chestedHorseEntityBase) .type(EntityType.LLAMA) .height(1.87f).width(0.9f) - .addTranslator(MetadataType.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.STRENGTH, entityMetadata.getValue())) + .addTranslator(MetadataType.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.STRENGTH, entityMetadata.getValue())) .addTranslator(MetadataType.INT, LlamaEntity::setCarpetedColor) .addTranslator(MetadataType.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.VARIANT, entityMetadata.getValue())) .build(); @@ -883,7 +882,7 @@ public final class EntityDefinitions { .type(EntityType.WOLF) .height(0.85f).width(0.6f) // "Begging" on wiki.vg, "Interested" in Nukkit - the tilt of the head - .addTranslator(MetadataType.BOOLEAN, (wolfEntity, entityMetadata) -> wolfEntity.setFlag(EntityFlag.INTERESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) + .addTranslator(MetadataType.BOOLEAN, (wolfEntity, entityMetadata) -> wolfEntity.setFlag(EntityFlag.INTERESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataType.INT, WolfEntity::setCollarColor) .addTranslator(MetadataType.INT, WolfEntity::setWolfAngerTime) .build(); diff --git a/connector/src/main/java/org/geysermc/connector/entity/EntityMetadataTranslator.java b/connector/src/main/java/org/geysermc/connector/entity/EntityMetadataTranslator.java index e0936559d..8023ce47c 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/EntityMetadataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/entity/EntityMetadataTranslator.java @@ -33,8 +33,7 @@ import java.util.function.BiConsumer; /** * Translates a given Java {@link EntityMetadata} into a similar/same construct for Bedrock */ - -public record EntityMetadataTranslator( - MetadataType acceptedType, - BiConsumer> translateFunction) { +public record EntityMetadataTranslator>>( + MetadataType acceptedType, + BiConsumer translateFunction) { } diff --git a/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java b/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java index 5c5b4dde8..c57eaa02a 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -49,9 +48,9 @@ public class FallingBlockEntity extends Entity { } @Override - public void setGravity(EntityMetadata entityMetadata) { + public void setGravity(BooleanEntityMetadata entityMetadata) { super.setGravity(entityMetadata); // Set the NO_AI flag based on the no gravity flag to prevent movement - setFlag(EntityFlag.NO_AI, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); + setFlag(EntityFlag.NO_AI, entityMetadata.getPrimitiveValue()); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/FireworkEntity.java b/connector/src/main/java/org/geysermc/connector/entity/FireworkEntity.java index fae7ca421..deac6b0dd 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/FireworkEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/FireworkEntity.java @@ -53,7 +53,7 @@ public class FireworkEntity extends Entity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setFireworkItem(EntityMetadata entityMetadata) { + public void setFireworkItem(EntityMetadata entityMetadata) { ItemStack item = entityMetadata.getValue(); if (item == null) { return; @@ -135,7 +135,7 @@ public class FireworkEntity extends Entity { dirtyMetadata.put(EntityData.DISPLAY_ITEM, builder.build()); } - public void setPlayerGliding(EntityMetadata entityMetadata) { + public void setPlayerGliding(EntityMetadata entityMetadata) { OptionalInt optional = entityMetadata.getValue(); // Checks if the firework has an entity ID (used when a player is gliding) // and checks to make sure the player that is gliding is the one getting sent the packet diff --git a/connector/src/main/java/org/geysermc/connector/entity/FishingHookEntity.java b/connector/src/main/java/org/geysermc/connector/entity/FishingHookEntity.java index 8efb2db83..84d7e686a 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/FishingHookEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/FishingHookEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -76,8 +75,8 @@ public class FishingHookEntity extends ThrowableEntity { super.spawnEntity(); } - public void setHookedEntity(EntityMetadata entityMetadata) { - int hookedEntityId = ((IntEntityMetadata) entityMetadata).getPrimitiveValue() - 1; + public void setHookedEntity(IntEntityMetadata entityMetadata) { + int hookedEntityId = entityMetadata.getPrimitiveValue() - 1; Entity entity; if (session.getPlayerEntity().getEntityId() == hookedEntityId) { entity = session.getPlayerEntity(); diff --git a/connector/src/main/java/org/geysermc/connector/entity/FurnaceMinecartEntity.java b/connector/src/main/java/org/geysermc/connector/entity/FurnaceMinecartEntity.java index d6791a15b..13116e9d7 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/FurnaceMinecartEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/FurnaceMinecartEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -41,8 +40,8 @@ public class FurnaceMinecartEntity extends DefaultBlockMinecartEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setHasFuel(EntityMetadata entityMetadata) { - hasFuel = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setHasFuel(BooleanEntityMetadata entityMetadata) { + hasFuel = entityMetadata.getPrimitiveValue(); updateDefaultBlockMetadata(); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/ItemEntity.java b/connector/src/main/java/org/geysermc/connector/entity/ItemEntity.java index 04ea9f299..f27aa8227 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/ItemEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/ItemEntity.java @@ -84,7 +84,7 @@ public class ItemEntity extends ThrowableEntity { } } - public void setItem(EntityMetadata entityMetadata) { + public void setItem(EntityMetadata entityMetadata) { ItemData item = ItemTranslator.translateToBedrock(session, entityMetadata.getValue()); if (this.item == null) { this.item = item; diff --git a/connector/src/main/java/org/geysermc/connector/entity/ItemFrameEntity.java b/connector/src/main/java/org/geysermc/connector/entity/ItemFrameEntity.java index 2ff653a06..c4210f074 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/ItemFrameEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/ItemFrameEntity.java @@ -109,7 +109,7 @@ public class ItemFrameEntity extends Entity { valid = true; } - public void setItemInFrame(EntityMetadata entityMetadata) { + public void setItemInFrame(EntityMetadata entityMetadata) { if (entityMetadata.getValue() != null) { this.heldItem = entityMetadata.getValue(); ItemData itemData = ItemTranslator.translateToBedrock(session, heldItem); @@ -134,8 +134,8 @@ public class ItemFrameEntity extends Entity { } } - public void setItemRotation(EntityMetadata entityMetadata) { - rotation = ((IntEntityMetadata) entityMetadata).getPrimitiveValue() * 45; + public void setItemRotation(IntEntityMetadata entityMetadata) { + rotation = entityMetadata.getPrimitiveValue() * 45; if (cachedTag == null) { return; } diff --git a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java index 0a7a0da5c..40e65690e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java @@ -31,6 +31,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3i; import com.nukkitx.protocol.bedrock.data.AttributeData; @@ -53,6 +54,7 @@ import org.geysermc.connector.utils.ChunkUtils; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.UUID; @Getter @@ -87,8 +89,8 @@ public class LivingEntity extends Entity { dirtyMetadata.put(EntityData.HEALTH, 1); } - public void setLivingEntityFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setLivingEntityFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); // Blocking gets triggered when using a bow, but if we set USING_ITEM for all items, it may look like // you're "mining" with ex. a shield. @@ -102,8 +104,8 @@ public class LivingEntity extends Entity { setFlag(EntityFlag.DAMAGE_NEARBY_MOBS, (xd & 0x04) == 0x04); } - public void setHealth(EntityMetadata entityMetadata) { - this.health = ((FloatEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setHealth(FloatEntityMetadata entityMetadata) { + this.health = entityMetadata.getPrimitiveValue(); AttributeData healthData = createHealthAttribute(); UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); @@ -112,9 +114,10 @@ public class LivingEntity extends Entity { session.sendUpstreamPacket(attributesPacket); } - public Vector3i setBedPosition(EntityMetadata entityMetadata) { - Position bedPosition = entityMetadata.getValue(); - if (bedPosition != null) { + public Vector3i setBedPosition(EntityMetadata, ?> entityMetadata) { + Optional optionalPos = entityMetadata.getValue(); + if (optionalPos.isPresent()) { + Position bedPosition = optionalPos.get(); Vector3i vector = Vector3i.from(bedPosition.getX(), bedPosition.getY(), bedPosition.getZ()); dirtyMetadata.put(EntityData.BED_POSITION, vector); int bed = session.getConnector().getWorldManager().getBlockAt(session, bedPosition); @@ -148,7 +151,7 @@ public class LivingEntity extends Entity { } @Override - public float setFreezing(EntityMetadata entityMetadata) { + public float setFreezing(IntEntityMetadata entityMetadata) { float freezingPercentage = super.setFreezing(entityMetadata); this.isMaxFrozenState = freezingPercentage >= 1.0f; setFlag(EntityFlag.SHAKING, isShaking()); diff --git a/connector/src/main/java/org/geysermc/connector/entity/MinecartEntity.java b/connector/src/main/java/org/geysermc/connector/entity/MinecartEntity.java index 5b514310d..cbc30561c 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/MinecartEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/MinecartEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; @@ -40,18 +39,18 @@ public class MinecartEntity extends Entity { super(session, entityId, geyserId, uuid, definition, position.add(0d, definition.offset(), 0d), motion, yaw, pitch, headYaw); } - public void setCustomBlock(EntityMetadata entityMetadata) { - dirtyMetadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(((IntEntityMetadata) entityMetadata).getPrimitiveValue())); + public void setCustomBlock(IntEntityMetadata entityMetadata) { + dirtyMetadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(entityMetadata.getPrimitiveValue())); } - public void setCustomBlockOffset(EntityMetadata entityMetadata) { - dirtyMetadata.put(EntityData.DISPLAY_OFFSET, entityMetadata.getValue()); + public void setCustomBlockOffset(IntEntityMetadata entityMetadata) { + dirtyMetadata.put(EntityData.DISPLAY_OFFSET, entityMetadata.getPrimitiveValue()); } - public void setShowCustomBlock(EntityMetadata entityMetadata) { + public void setShowCustomBlock(BooleanEntityMetadata entityMetadata) { // If the custom block should be enabled // Needs a byte based off of Java's boolean - dirtyMetadata.put(EntityData.CUSTOM_DISPLAY, (byte) (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue() ? 1 : 0)); + dirtyMetadata.put(EntityData.CUSTOM_DISPLAY, (byte) (entityMetadata.getPrimitiveValue() ? 1 : 0)); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/entity/TNTEntity.java b/connector/src/main/java/org/geysermc/connector/entity/TNTEntity.java index 39482b16e..d71b1f1e7 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/TNTEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/TNTEntity.java @@ -42,7 +42,7 @@ public class TNTEntity extends Entity implements Tickable { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setFuseLength(EntityMetadata entityMetadata) { + public void setFuseLength(IntEntityMetadata entityMetadata) { currentTick = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); setFlag(EntityFlag.IGNITED, true); dirtyMetadata.put(EntityData.FUSE_LENGTH, currentTick); diff --git a/connector/src/main/java/org/geysermc/connector/entity/ThrownPotionEntity.java b/connector/src/main/java/org/geysermc/connector/entity/ThrownPotionEntity.java index 6f5b6a88e..7c108dda9 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/ThrownPotionEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/ThrownPotionEntity.java @@ -47,7 +47,7 @@ public class ThrownPotionEntity extends ThrowableItemEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setPotion(EntityMetadata entityMetadata) { + public void setPotion(EntityMetadata entityMetadata) { ItemStack itemStack = entityMetadata.getValue(); ItemMapping mapping = session.getItemMappings().getMapping(itemStack); if (mapping.getJavaIdentifier().endsWith("potion") && itemStack.getNbt() != null) { diff --git a/connector/src/main/java/org/geysermc/connector/entity/TippedArrowEntity.java b/connector/src/main/java/org/geysermc/connector/entity/TippedArrowEntity.java index d05cb5d2a..df0f12854 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/TippedArrowEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/TippedArrowEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -43,8 +42,8 @@ public class TippedArrowEntity extends AbstractArrowEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setPotionEffectColor(EntityMetadata entityMetadata) { - int potionColor = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setPotionEffectColor(IntEntityMetadata entityMetadata) { + int potionColor = entityMetadata.getPrimitiveValue(); // -1 means no color if (potionColor == -1) { dirtyMetadata.put(EntityData.CUSTOM_DISPLAY, 0); diff --git a/connector/src/main/java/org/geysermc/connector/entity/WitherSkullEntity.java b/connector/src/main/java/org/geysermc/connector/entity/WitherSkullEntity.java index 936a6c091..643757329 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/WitherSkullEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/WitherSkullEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import org.geysermc.connector.network.session.GeyserSession; @@ -41,8 +40,8 @@ public class WitherSkullEntity extends ItemedFireballEntity { this.futureTicks = 1; } - public void setDangerous(EntityMetadata entityMetadata) { - boolean newDangerous = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setDangerous(BooleanEntityMetadata entityMetadata) { + boolean newDangerous = entityMetadata.getPrimitiveValue(); if (newDangerous != isCharged) { isCharged = newDangerous; // Is an entirely new entity in Bedrock but just a metadata type in Java diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/AgeableEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/AgeableEntity.java index b864b8e7b..1bb4caef0 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/AgeableEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/AgeableEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -41,8 +40,8 @@ public class AgeableEntity extends CreatureEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setBaby(EntityMetadata entityMetadata) { - boolean isBaby = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setBaby(BooleanEntityMetadata entityMetadata) { + boolean isBaby = entityMetadata.getPrimitiveValue(); dirtyMetadata.put(EntityData.SCALE, isBaby ? getBabySize() : getAdultSize()); setFlag(EntityFlag.BABY, isBaby); diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/ArmorStandEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/ArmorStandEntity.java index e2d34f2b8..685232381 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/ArmorStandEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/ArmorStandEntity.java @@ -40,6 +40,7 @@ import org.geysermc.connector.entity.EntityDefinitions; import org.geysermc.connector.entity.LivingEntity; import org.geysermc.connector.network.session.GeyserSession; +import java.util.Optional; import java.util.UUID; public class ArmorStandEntity extends LivingEntity { @@ -117,13 +118,13 @@ public class ArmorStandEntity extends LivingEntity { } @Override - public void setDisplayName(EntityMetadata entityMetadata) { + public void setDisplayName(EntityMetadata, ?> entityMetadata) { super.setDisplayName(entityMetadata); updateSecondEntityStatus(false); } - public void setArmorStandFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setArmorStandFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); // isSmall boolean newIsSmall = (xd & 0x01) == 0x01; @@ -161,27 +162,27 @@ public class ArmorStandEntity extends LivingEntity { setFlag(EntityFlag.ADMIRING, (xd & 0x08) == 0x08); // Has no baseplate } - public void setHeadRotation(EntityMetadata entityMetadata) { + public void setHeadRotation(EntityMetadata entityMetadata) { onRotationUpdate(EntityData.MARK_VARIANT, EntityFlag.INTERESTED, EntityFlag.CHARGED, EntityFlag.POWERED, entityMetadata.getValue()); } - public void setBodyRotation(EntityMetadata entityMetadata) { + public void setBodyRotation(EntityMetadata entityMetadata) { onRotationUpdate(EntityData.VARIANT, EntityFlag.IN_LOVE, EntityFlag.CELEBRATING, EntityFlag.CELEBRATING_SPECIAL, entityMetadata.getValue()); } - public void setLeftArmRotation(EntityMetadata entityMetadata) { + public void setLeftArmRotation(EntityMetadata entityMetadata) { onRotationUpdate(EntityData.TRADE_TIER, EntityFlag.CHARGING, EntityFlag.CRITICAL, EntityFlag.DANCING, entityMetadata.getValue()); } - public void setRightArmRotation(EntityMetadata entityMetadata) { + public void setRightArmRotation(EntityMetadata entityMetadata) { onRotationUpdate(EntityData.MAX_TRADE_TIER, EntityFlag.ELDER, EntityFlag.EMOTING, EntityFlag.IDLING, entityMetadata.getValue()); } - public void setLeftLegRotation(EntityMetadata entityMetadata) { + public void setLeftLegRotation(EntityMetadata entityMetadata) { onRotationUpdate(EntityData.SKIN_ID, EntityFlag.IS_ILLAGER_CAPTAIN, EntityFlag.IS_IN_UI, EntityFlag.LINGERING, entityMetadata.getValue()); } - public void setRightLegRotation(EntityMetadata entityMetadata) { + public void setRightLegRotation(EntityMetadata entityMetadata) { onRotationUpdate(EntityData.HURT_DIRECTION, EntityFlag.IS_PREGNANT, EntityFlag.SHEARED, EntityFlag.STALKING, entityMetadata.getValue()); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/BatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/BatEntity.java index 4f5bd1ead..ed6f39f39 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/BatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/BatEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; @@ -40,8 +39,8 @@ public class BatEntity extends AmbientEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setBatFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setBatFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.RESTING, (xd & 0x01) == 0x01); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/MobEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/MobEntity.java index 3c603a61e..605f901f5 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/MobEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/MobEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -54,8 +53,8 @@ public class MobEntity extends LivingEntity { setLeashHolderBedrockId(-1); } - public void setMobFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setMobFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.NO_AI, (xd & 0x01) == 0x01); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/SlimeEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/SlimeEntity.java index b533a6613..7ab1fad0e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/SlimeEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/SlimeEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -40,7 +39,7 @@ public class SlimeEntity extends MobEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setScale(EntityMetadata entityMetadata) { - dirtyMetadata.put(EntityData.SCALE, 0.10f + ((IntEntityMetadata) entityMetadata).getPrimitiveValue()); + public void setScale(IntEntityMetadata entityMetadata) { + dirtyMetadata.put(EntityData.SCALE, 0.10f + entityMetadata.getPrimitiveValue()); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/SnowGolemEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/SnowGolemEntity.java index 7dafd4853..afd6daf5d 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/SnowGolemEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/SnowGolemEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; @@ -40,8 +39,8 @@ public class SnowGolemEntity extends GolemEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setSnowGolemFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setSnowGolemFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); // Handle the visibility of the pumpkin setFlag(EntityFlag.SHEARED, (xd & 0x10) != 0x10); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/AxolotlEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/AxolotlEntity.java index e0bfc577e..38f5a10a8 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/AxolotlEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/AxolotlEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.animal; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; @@ -42,8 +41,8 @@ public class AxolotlEntity extends AnimalEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setVariant(EntityMetadata entityMetadata) { - int variant = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setVariant(IntEntityMetadata entityMetadata) { + int variant = entityMetadata.getPrimitiveValue(); switch (variant) { case 1 -> variant = 3; // Java - "Wild" (brown) case 3 -> variant = 1; // Java - cyan @@ -51,8 +50,8 @@ public class AxolotlEntity extends AnimalEntity { dirtyMetadata.put(EntityData.VARIANT, variant); } - public void setPlayingDead(EntityMetadata entityMetadata) { - setFlag(EntityFlag.PLAYING_DEAD, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); + public void setPlayingDead(BooleanEntityMetadata entityMetadata) { + setFlag(EntityFlag.PLAYING_DEAD, entityMetadata.getPrimitiveValue()); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java index a2524566d..7e6e8f1a8 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.animal; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; 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.nukkitx.math.vector.Vector3f; @@ -45,8 +44,8 @@ public class BeeEntity extends AnimalEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setBeeFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setBeeFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); // Bee is performing sting attack; trigger animation if ((xd & 0x02) == 0x02) { EntityEventPacket packet = new EntityEventPacket(); @@ -61,9 +60,9 @@ public class BeeEntity extends AnimalEntity { setFlag(EntityFlag.POWERED, (xd & 0x08) == 0x08); } - public void setAngerTime(EntityMetadata entityMetadata) { + public void setAngerTime(IntEntityMetadata entityMetadata) { // Converting "anger time" to a boolean - setFlag(EntityFlag.ANGRY, ((IntEntityMetadata) entityMetadata).getPrimitiveValue() > 0); + setFlag(EntityFlag.ANGRY, entityMetadata.getPrimitiveValue() > 0); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/FoxEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/FoxEntity.java index a10201155..84b2f1071 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/FoxEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/FoxEntity.java @@ -25,8 +25,8 @@ package org.geysermc.connector.entity.living.animal; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; 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.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; @@ -42,12 +42,12 @@ public class FoxEntity extends AnimalEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setFoxVariant(EntityMetadata entityMetadata) { - dirtyMetadata.put(EntityData.VARIANT, entityMetadata.getValue()); + public void setFoxVariant(IntEntityMetadata entityMetadata) { + dirtyMetadata.put(EntityData.VARIANT, entityMetadata.getPrimitiveValue()); } - public void setFoxFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setFoxFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01); setFlag(EntityFlag.SNEAKING, (xd & 0x04) == 0x04); setFlag(EntityFlag.INTERESTED, (xd & 0x08) == 0x08); diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/GoatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/GoatEntity.java index 568be2d21..5b5843480 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/GoatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/GoatEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.animal; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; 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.nukkitx.math.vector.Vector3f; @@ -46,9 +45,9 @@ public class GoatEntity extends AnimalEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setScreamer(EntityMetadata entityMetadata) { + public void setScreamer(BooleanEntityMetadata entityMetadata) { // Metadata not used in Bedrock Edition - isScreamer = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + isScreamer = entityMetadata.getPrimitiveValue(); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/HoglinEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/HoglinEntity.java index fb2c68fd2..81f340578 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/HoglinEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/HoglinEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.animal; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; @@ -43,9 +42,9 @@ public class HoglinEntity extends AnimalEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setImmuneToZombification(EntityMetadata entityMetadata) { + public void setImmuneToZombification(BooleanEntityMetadata entityMetadata) { // Apply shaking effect if not in the nether and zombification is possible - this.isImmuneToZombification = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + this.isImmuneToZombification = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.SHAKING, isShaking()); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PandaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PandaEntity.java index 376079387..6ddc66ab9 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PandaEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PandaEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.animal; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; 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.nukkitx.math.vector.Vector3f; @@ -47,8 +46,8 @@ public class PandaEntity extends AnimalEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setEatingCounter(EntityMetadata entityMetadata) { - int count = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setEatingCounter(IntEntityMetadata entityMetadata) { + int count = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.EATING, count > 0); dirtyMetadata.put(EntityData.EATING_COUNTER, count); if (count != 0) { @@ -61,18 +60,18 @@ public class PandaEntity extends AnimalEntity { } } - public void setMainGene(EntityMetadata entityMetadata) { - mainGene = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setMainGene(ByteEntityMetadata entityMetadata) { + mainGene = entityMetadata.getPrimitiveValue(); updateAppearance(); } - public void setHiddenGene(EntityMetadata entityMetadata) { - hiddenGene = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setHiddenGene(ByteEntityMetadata entityMetadata) { + hiddenGene = entityMetadata.getPrimitiveValue(); updateAppearance(); } - public void setPandaFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setPandaFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.SNEEZING, (xd & 0x02) == 0x02); setFlag(EntityFlag.ROLLING, (xd & 0x04) == 0x04); setFlag(EntityFlag.SITTING, (xd & 0x08) == 0x08); diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PufferFishEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PufferFishEntity.java index e2c9039de..9baddf321 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PufferFishEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PufferFishEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.animal; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -41,8 +40,8 @@ public class PufferFishEntity extends AbstractFishEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setPufferfishSize(EntityMetadata entityMetadata) { - int puffsize = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setPufferfishSize(IntEntityMetadata entityMetadata) { + int puffsize = entityMetadata.getPrimitiveValue(); dirtyMetadata.put(EntityData.PUFFERFISH_SIZE, (byte) puffsize); dirtyMetadata.put(EntityData.VARIANT, puffsize); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/RabbitEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/RabbitEntity.java index 02d6db67e..38129d923 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/RabbitEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/RabbitEntity.java @@ -25,7 +25,7 @@ package org.geysermc.connector.entity.living.animal; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -43,12 +43,12 @@ public class RabbitEntity extends AnimalEntity { } @Override - public void setBaby(EntityMetadata entityMetadata) { + public void setBaby(BooleanEntityMetadata entityMetadata) { super.setBaby(entityMetadata); } - public void setRabbitVariant(EntityMetadata entityMetadata) { - int variant = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setRabbitVariant(IntEntityMetadata entityMetadata) { + int variant = entityMetadata.getPrimitiveValue(); // Change the killer bunny to display as white since it only exists on Java Edition boolean isKillerBunny = variant == 99; diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/SheepEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/SheepEntity.java index c063188c5..6fa2b59df 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/SheepEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/SheepEntity.java @@ -41,7 +41,7 @@ public class SheepEntity extends AnimalEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setSheepFlags(EntityMetadata entityMetadata) { + public void setSheepFlags(ByteEntityMetadata entityMetadata) { byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); setFlag(EntityFlag.SHEARED, (xd & 0x10) == 0x10); dirtyMetadata.put(EntityData.COLOR, xd); diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/StriderEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/StriderEntity.java index b2934e507..8fa51d48f 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/StriderEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/StriderEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.animal; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; @@ -47,12 +46,12 @@ public class StriderEntity extends AnimalEntity { setFlag(EntityFlag.BREATHING, true); } - public void setCold(EntityMetadata entityMetadata) { - isCold = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setCold(BooleanEntityMetadata entityMetadata) { + isCold = entityMetadata.getPrimitiveValue(); } - public void setSaddled(EntityMetadata entityMetadata) { - setFlag(EntityFlag.SADDLED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); + public void setSaddled(BooleanEntityMetadata entityMetadata) { + setFlag(EntityFlag.SADDLED, entityMetadata.getPrimitiveValue()); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/TropicalFishEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/TropicalFishEntity.java index cd652f6a3..e699cfa98 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/TropicalFishEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/TropicalFishEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.animal; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.google.common.collect.ImmutableList; import com.nukkitx.math.vector.Vector3f; @@ -53,8 +52,8 @@ public class TropicalFishEntity extends AbstractFishEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setFishVariant(EntityMetadata entityMetadata) { - int varNumber = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setFishVariant(IntEntityMetadata entityMetadata) { + int varNumber = entityMetadata.getPrimitiveValue(); dirtyMetadata.put(EntityData.VARIANT, getShape(varNumber)); // Shape 0-1 dirtyMetadata.put(EntityData.MARK_VARIANT, getPattern(varNumber)); // Pattern 0-5 diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/TurtleEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/TurtleEntity.java index 495bc64a0..1eb0da891 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/TurtleEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/TurtleEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.animal; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; @@ -41,12 +40,12 @@ public class TurtleEntity extends AnimalEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setPregnant(EntityMetadata entityMetadata) { - setFlag(EntityFlag.IS_PREGNANT, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); + public void setPregnant(BooleanEntityMetadata entityMetadata) { + setFlag(EntityFlag.IS_PREGNANT, entityMetadata.getPrimitiveValue()); } - public void setLayingEgg(EntityMetadata entityMetadata) { - setFlag(EntityFlag.LAYING_EGG, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); + public void setLayingEgg(BooleanEntityMetadata entityMetadata) { + setFlag(EntityFlag.LAYING_EGG, entityMetadata.getPrimitiveValue()); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/AbstractHorseEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/AbstractHorseEntity.java index 1b3ffbd71..25e5eaaf7 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/AbstractHorseEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/AbstractHorseEntity.java @@ -25,7 +25,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.entity.metadata.type.ByteEntityMetadata; import com.google.common.collect.ImmutableSet; import com.nukkitx.math.vector.Vector3f; @@ -79,8 +78,8 @@ public class AbstractHorseEntity extends AnimalEntity { session.sendUpstreamPacket(attributesPacket); } - public void setHorseFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setHorseFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); boolean tamed = (xd & 0x02) == 0x02; boolean saddled = (xd & 0x04) == 0x04; setFlag(EntityFlag.TAMED, tamed); diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/HorseEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/HorseEntity.java index 97354d047..d997171ea 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/HorseEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/HorseEntity.java @@ -25,7 +25,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.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -40,8 +39,8 @@ public class HorseEntity extends AbstractHorseEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setHorseVariant(EntityMetadata entityMetadata) { - int value = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setHorseVariant(IntEntityMetadata entityMetadata) { + int value = entityMetadata.getPrimitiveValue(); dirtyMetadata.put(EntityData.VARIANT, value & 255); dirtyMetadata.put(EntityData.MARK_VARIANT, (value >> 8) % 5); } 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 204261620..7a4af6a2a 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 @@ -25,7 +25,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.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -48,12 +47,12 @@ public class LlamaEntity extends ChestedHorseEntity { /** * Color equipped on the llama */ - public void setCarpetedColor(EntityMetadata entityMetadata) { + public void setCarpetedColor(IntEntityMetadata entityMetadata) { // Bedrock treats llama decoration as armor MobArmorEquipmentPacket equipmentPacket = new MobArmorEquipmentPacket(); equipmentPacket.setRuntimeEntityId(geyserId); // -1 means no armor - int carpetIndex = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + int carpetIndex = entityMetadata.getPrimitiveValue(); if (carpetIndex > -1 && carpetIndex <= 15) { // The damage value is the dye color that Java sends us, for pre-1.16.220 // The item is always going to be a carpet diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index 035044a93..52f20b75f 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -25,8 +25,8 @@ 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.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.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -61,7 +61,7 @@ public class CatEntity extends TameableEntity { } @Override - public void setTameableFlags(EntityMetadata entityMetadata) { + public void setTameableFlags(ByteEntityMetadata entityMetadata) { super.setTameableFlags(entityMetadata); // Update collar color if tamed if (getFlag(EntityFlag.TAMED)) { @@ -69,9 +69,9 @@ public class CatEntity extends TameableEntity { } } - public void setCatVariant(EntityMetadata entityMetadata) { + public void setCatVariant(IntEntityMetadata entityMetadata) { // Different colors in Java and Bedrock for some reason - int metadataValue = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + int metadataValue = entityMetadata.getPrimitiveValue(); int variantColor = switch (metadataValue) { case 0 -> 8; case 8 -> 0; @@ -82,12 +82,12 @@ public class CatEntity extends TameableEntity { dirtyMetadata.put(EntityData.VARIANT, variantColor); } - public void setResting(EntityMetadata entityMetadata) { - setFlag(EntityFlag.RESTING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); + public void setResting(BooleanEntityMetadata entityMetadata) { + setFlag(EntityFlag.RESTING, entityMetadata.getPrimitiveValue()); } - public void setCollarColor(EntityMetadata entityMetadata) { - collarColor = (byte) ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setCollarColor(IntEntityMetadata entityMetadata) { + collarColor = (byte) entityMetadata.getPrimitiveValue(); // Needed or else wild cats are a red color if (getFlag(EntityFlag.TAMED)) { dirtyMetadata.put(EntityData.COLOR, collarColor); diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java index a07ce3b9b..198330ded 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java @@ -36,6 +36,7 @@ import org.geysermc.connector.entity.EntityDefinition; import org.geysermc.connector.entity.living.animal.AnimalEntity; import org.geysermc.connector.network.session.GeyserSession; +import java.util.Optional; import java.util.UUID; public class TameableEntity extends AnimalEntity { @@ -49,18 +50,18 @@ public class TameableEntity extends AnimalEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setTameableFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setTameableFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01); setFlag(EntityFlag.ANGRY, (xd & 0x02) == 0x02); setFlag(EntityFlag.TAMED, (xd & 0x04) == 0x04); } - public void setOwner(EntityMetadata entityMetadata) { + public void setOwner(EntityMetadata, ?> entityMetadata) { // Note: Must be set for wolf collar color to work - if (entityMetadata.getValue() != null) { + if (entityMetadata.getValue().isPresent()) { // Owner UUID of entity - Entity entity = session.getEntityCache().getPlayerEntity(entityMetadata.getValue()); + Entity entity = session.getEntityCache().getPlayerEntity(entityMetadata.getValue().get()); // Used as both a check since the player isn't in the entity cache and a normal fallback if (entity == null) { entity = session.getPlayerEntity(); diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java index f828ce014..c38c1c8af 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java @@ -25,7 +25,6 @@ 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.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.google.common.collect.ImmutableSet; @@ -55,18 +54,18 @@ public class WolfEntity extends TameableEntity { } @Override - public void setTameableFlags(EntityMetadata entityMetadata) { + public void setTameableFlags(ByteEntityMetadata entityMetadata) { super.setTameableFlags(entityMetadata); // Reset wolf color - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + byte xd = entityMetadata.getPrimitiveValue(); boolean angry = (xd & 0x02) == 0x02; if (angry) { dirtyMetadata.put(EntityData.COLOR, (byte) 0); } } - public void setCollarColor(EntityMetadata entityMetadata) { - collarColor = (byte) ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setCollarColor(IntEntityMetadata entityMetadata) { + collarColor = (byte) entityMetadata.getPrimitiveValue(); if (getFlag(EntityFlag.ANGRY)) { return; } @@ -80,8 +79,8 @@ public class WolfEntity extends TameableEntity { } // 1.16+ - public void setWolfAngerTime(EntityMetadata entityMetadata) { - int time = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setWolfAngerTime(IntEntityMetadata entityMetadata) { + int time = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.ANGRY, time != 0); dirtyMetadata.put(EntityData.COLOR, time != 0 ? (byte) 0 : collarColor); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java index 234b065d4..c231e8e86 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java @@ -40,6 +40,7 @@ import org.geysermc.connector.entity.EntityDefinition; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.registry.BlockRegistries; +import java.util.Optional; import java.util.UUID; public class VillagerEntity extends AbstractMerchantEntity { @@ -91,7 +92,7 @@ public class VillagerEntity extends AbstractMerchantEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setVillagerData(EntityMetadata entityMetadata) { + public void setVillagerData(EntityMetadata entityMetadata) { VillagerData villagerData = entityMetadata.getValue(); // Profession int profession = VILLAGER_PROFESSIONS.get(villagerData.getProfession()); @@ -105,7 +106,7 @@ public class VillagerEntity extends AbstractMerchantEntity { } @Override - public Vector3i setBedPosition(EntityMetadata entityMetadata) { + public Vector3i setBedPosition(EntityMetadata, ?> entityMetadata) { return bedPosition = super.setBedPosition(entityMetadata); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/AbstractSkeletonEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/AbstractSkeletonEntity.java index 9997dd968..abbe8b6d3 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/AbstractSkeletonEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/AbstractSkeletonEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -41,9 +40,9 @@ public class AbstractSkeletonEntity extends MonsterEntity { } @Override - public void setMobFlags(EntityMetadata entityMetadata) { + public void setMobFlags(ByteEntityMetadata entityMetadata) { super.setMobFlags(entityMetadata); - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + byte xd = entityMetadata.getPrimitiveValue(); // A bit of a loophole so the hands get raised - set the target ID to its own ID dirtyMetadata.put(EntityData.TARGET_EID, ((xd & 4) == 4) ? geyserId : 0); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/BasePiglinEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/BasePiglinEntity.java index e092d3099..a9b274875 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/BasePiglinEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/BasePiglinEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; @@ -42,9 +41,9 @@ public class BasePiglinEntity extends MonsterEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setImmuneToZombification(EntityMetadata entityMetadata) { + public void setImmuneToZombification(BooleanEntityMetadata entityMetadata) { // Apply shaking effect if not in the nether and zombification is possible - this.isImmuneToZombification = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + this.isImmuneToZombification = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.SHAKING, isShaking()); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/BlazeEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/BlazeEntity.java index 33afdf81d..5eed05db9 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/BlazeEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/BlazeEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; @@ -40,8 +39,8 @@ public class BlazeEntity extends MonsterEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setBlazeFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setBlazeFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.ON_FIRE, (xd & 0x01) == 0x01); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/CreeperEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/CreeperEntity.java index 0f561f8d2..0b05d8822 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/CreeperEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/CreeperEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; @@ -37,8 +36,8 @@ import java.util.UUID; public class CreeperEntity extends MonsterEntity { /** - * Whether the creeper has been ignited and is using {@link #setIgnited(EntityMetadata)}. - * In this instance we ignore {@link #setSwelling(EntityMetadata)} since it's sending us -1 which confuses poor Bedrock. + * Whether the creeper has been ignited and is using {@link #setIgnited(BooleanEntityMetadata)}. + * In this instance we ignore {@link #setSwelling(IntEntityMetadata)} since it's sending us -1 which confuses poor Bedrock. */ private boolean ignitedByFlintAndSteel = false; @@ -46,14 +45,14 @@ public class CreeperEntity extends MonsterEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setSwelling(EntityMetadata entityMetadata) { + public void setSwelling(IntEntityMetadata entityMetadata) { if (!ignitedByFlintAndSteel) { - setFlag(EntityFlag.IGNITED, ((IntEntityMetadata) entityMetadata).getPrimitiveValue() == 1); + setFlag(EntityFlag.IGNITED, entityMetadata.getPrimitiveValue() == 1); } } - public void setIgnited(EntityMetadata entityMetadata) { - ignitedByFlintAndSteel = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setIgnited(BooleanEntityMetadata entityMetadata) { + ignitedByFlintAndSteel = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.IGNITED, ignitedByFlintAndSteel); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/EnderDragonEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/EnderDragonEntity.java index 3d381972d..12d0c4f3a 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/EnderDragonEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/EnderDragonEntity.java @@ -25,7 +25,7 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.LevelEventType; @@ -90,7 +90,7 @@ public class EnderDragonEntity extends MobEntity implements Tickable { } @Override - public void setHealth(EntityMetadata entityMetadata) { + public void setHealth(FloatEntityMetadata entityMetadata) { super.setHealth(entityMetadata); if (phase == 9 && this.health <= 0) { // Dying phase EntityEventPacket entityEventPacket = new EntityEventPacket(); @@ -101,8 +101,8 @@ public class EnderDragonEntity extends MobEntity implements Tickable { } } - public void setPhase(EntityMetadata entityMetadata) { - phase = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setPhase(IntEntityMetadata entityMetadata) { + phase = entityMetadata.getPrimitiveValue(); phaseTicks = 0; setFlag(EntityFlag.SITTING, isSitting()); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/EndermanEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/EndermanEntity.java index 94265f7e4..744e2480c 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/EndermanEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/EndermanEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; @@ -44,17 +43,17 @@ public class EndermanEntity extends MonsterEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setCarriedBlock(EntityMetadata entityMetadata) { - dirtyMetadata.put(EntityData.CARRIED_BLOCK, session.getBlockMappings().getBedrockBlockId(((IntEntityMetadata) entityMetadata).getPrimitiveValue())); + public void setCarriedBlock(IntEntityMetadata entityMetadata) { + dirtyMetadata.put(EntityData.CARRIED_BLOCK, session.getBlockMappings().getBedrockBlockId(entityMetadata.getPrimitiveValue())); } /** * Controls the screaming sound */ - public void setScreaming(EntityMetadata entityMetadata) { + public void setScreaming(BooleanEntityMetadata entityMetadata) { //TODO see if Bedrock controls this differently // Java Edition this controls which ambient sound is used - if (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()) { + if (entityMetadata.getPrimitiveValue()) { LevelSoundEvent2Packet packet = new LevelSoundEvent2Packet(); packet.setSound(SoundEvent.STARE); packet.setPosition(this.position); @@ -64,8 +63,8 @@ public class EndermanEntity extends MonsterEntity { } } - public void setAngry(EntityMetadata entityMetadata) { + public void setAngry(BooleanEntityMetadata entityMetadata) { // "Is staring/provoked" - controls visuals - setFlag(EntityFlag.ANGRY, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); + setFlag(EntityFlag.ANGRY, entityMetadata.getPrimitiveValue()); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/GhastEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/GhastEntity.java index e281db30b..7c13ec577 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/GhastEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/GhastEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -41,8 +40,8 @@ public class GhastEntity extends FlyingEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setGhastAttacking(EntityMetadata entityMetadata) { + public void setGhastAttacking(BooleanEntityMetadata entityMetadata) { // If the ghast is attacking - dirtyMetadata.put(EntityData.CHARGE_AMOUNT, (byte) (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue() ? 1 : 0)); + dirtyMetadata.put(EntityData.CHARGE_AMOUNT, (byte) (entityMetadata.getPrimitiveValue() ? 1 : 0)); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/GuardianEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/GuardianEntity.java index caffb5d9e..0c4156e71 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/GuardianEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/GuardianEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -41,8 +40,8 @@ public class GuardianEntity extends MonsterEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setGuardianTarget(EntityMetadata entityMetadata) { - int entityId = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setGuardianTarget(IntEntityMetadata entityMetadata) { + int entityId = entityMetadata.getPrimitiveValue(); Entity entity; if (session.getPlayerEntity().getEntityId() == entityId) { entity = session.getPlayerEntity(); diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/PhantomEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/PhantomEntity.java index 651d1aa66..f9136f701 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/PhantomEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/PhantomEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -40,8 +39,8 @@ public class PhantomEntity extends FlyingEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setPhantomScale(EntityMetadata entityMetadata) { - int size = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setPhantomScale(IntEntityMetadata entityMetadata) { + int size = entityMetadata.getPrimitiveValue(); float modelScale = 1f + 0.15f * size; float boundsScale = (1f + (0.2f * size) / definition.width()) / modelScale; diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/PiglinEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/PiglinEntity.java index 61fb36bf4..ab0625e64 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/PiglinEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/PiglinEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -41,18 +40,18 @@ public class PiglinEntity extends BasePiglinEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setBaby(EntityMetadata entityMetadata) { - boolean isBaby = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setBaby(BooleanEntityMetadata entityMetadata) { + boolean isBaby = entityMetadata.getPrimitiveValue(); dirtyMetadata.put(EntityData.SCALE, isBaby? .55f : 1f); setFlag(EntityFlag.BABY, isBaby); } - public void setChargingCrossbow(EntityMetadata entityMetadata) { - setFlag(EntityFlag.CHARGING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); + public void setChargingCrossbow(BooleanEntityMetadata entityMetadata) { + setFlag(EntityFlag.CHARGING, entityMetadata.getPrimitiveValue()); } - public void setDancing(EntityMetadata entityMetadata) { - setFlag(EntityFlag.DANCING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); + public void setDancing(BooleanEntityMetadata entityMetadata) { + setFlag(EntityFlag.DANCING, entityMetadata.getPrimitiveValue()); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/ShulkerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/ShulkerEntity.java index e16df7211..e881e252f 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/ShulkerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/ShulkerEntity.java @@ -27,13 +27,13 @@ package org.geysermc.connector.entity.living.monster; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; +import com.github.steveice10.mc.protocol.data.game.entity.object.Direction; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.connector.entity.EntityDefinition; import org.geysermc.connector.entity.living.GolemEntity; import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.utils.Direction; import java.util.UUID; @@ -45,17 +45,17 @@ public class ShulkerEntity extends GolemEntity { setFlag(EntityFlag.BRIBED, true); } - public void setAttachedFace(EntityMetadata entityMetadata) { + public void setAttachedFace(EntityMetadata entityMetadata) { Direction direction = entityMetadata.getValue(); dirtyMetadata.put(EntityData.SHULKER_ATTACH_FACE, (byte) direction.ordinal()); } - public void setShulkerHeight(EntityMetadata entityMetadata) { - int height = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setShulkerHeight(ByteEntityMetadata entityMetadata) { + int height = entityMetadata.getPrimitiveValue(); dirtyMetadata.put(EntityData.SHULKER_PEEK_ID, height); } - public void setShulkerColor(EntityMetadata entityMetadata) { + public void setShulkerColor(ByteEntityMetadata entityMetadata) { byte color = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); if (color == 16) { // 16 is default on both editions diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/SkeletonEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/SkeletonEntity.java index 984590db1..63b021ba3 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/SkeletonEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/SkeletonEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; @@ -41,8 +40,8 @@ public class SkeletonEntity extends AbstractSkeletonEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setConvertingToStray(EntityMetadata entityMetadata) { - this.convertingToStray = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setConvertingToStray(BooleanEntityMetadata entityMetadata) { + this.convertingToStray = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.SHAKING, isShaking()); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/SpiderEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/SpiderEntity.java index f2f151eae..45e963618 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/SpiderEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/SpiderEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; @@ -40,8 +39,8 @@ public class SpiderEntity extends MonsterEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setSpiderFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setSpiderFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.WALL_CLIMBING, (xd & 0x01) == 0x01); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/VexEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/VexEntity.java index d6e05b387..2582665a7 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/VexEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/VexEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -40,8 +39,8 @@ public class VexEntity extends MonsterEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setVexFlags(EntityMetadata entityMetadata) { - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setVexFlags(ByteEntityMetadata entityMetadata) { + byte xd = entityMetadata.getPrimitiveValue(); // Set the target to the player to force the attack animation // even if the player isn't the target as we dont get the target on Java dirtyMetadata.put(EntityData.TARGET_EID, (xd & 0x01) == 0x01 ? session.getPlayerEntity().getGeyserId() : 0); diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/WitherEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/WitherEntity.java index befb464fe..0dd6565f2 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/WitherEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/WitherEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -47,20 +46,20 @@ public class WitherEntity extends MonsterEntity { dirtyMetadata.put(EntityData.WITHER_AERIAL_ATTACK, (short) 1); } - public void setTarget1(EntityMetadata entityMetadata) { + public void setTarget1(IntEntityMetadata entityMetadata) { setTargetId(EntityData.WITHER_TARGET_1, entityMetadata); } - public void setTarget2(EntityMetadata entityMetadata) { + public void setTarget2(IntEntityMetadata entityMetadata) { setTargetId(EntityData.WITHER_TARGET_2, entityMetadata); } - public void setTarget3(EntityMetadata entityMetadata) { + public void setTarget3(IntEntityMetadata entityMetadata) { setTargetId(EntityData.WITHER_TARGET_3, entityMetadata); } - private void setTargetId(EntityData entityData, EntityMetadata entityMetadata) { - int entityId = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + private void setTargetId(EntityData entityData, IntEntityMetadata entityMetadata) { + int entityId = entityMetadata.getPrimitiveValue(); Entity entity; if (session.getPlayerEntity().getEntityId() == entityId) { entity = session.getPlayerEntity(); @@ -73,8 +72,8 @@ public class WitherEntity extends MonsterEntity { } } - public void setInvulnerableTicks(EntityMetadata entityMetadata) { - int value = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setInvulnerableTicks(IntEntityMetadata entityMetadata) { + int value = entityMetadata.getPrimitiveValue(); dirtyMetadata.put(EntityData.WITHER_INVULNERABLE_TICKS, value); // Show the shield for the first few seconds of spawning (like Java) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZoglinEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZoglinEntity.java index 4773b2d80..07876673d 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZoglinEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZoglinEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -41,8 +40,8 @@ public class ZoglinEntity extends MonsterEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setBaby(EntityMetadata entityMetadata) { - boolean isBaby = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setBaby(BooleanEntityMetadata entityMetadata) { + boolean isBaby = entityMetadata.getPrimitiveValue(); dirtyMetadata.put(EntityData.SCALE, isBaby? .55f : 1f); setFlag(EntityFlag.BABY, isBaby); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieEntity.java index fd9218cd7..d2b25ce8f 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -42,14 +41,14 @@ public class ZombieEntity extends MonsterEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setZombieBaby(EntityMetadata entityMetadata) { - boolean isBaby = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setZombieBaby(BooleanEntityMetadata entityMetadata) { + boolean isBaby = entityMetadata.getPrimitiveValue(); dirtyMetadata.put(EntityData.SCALE, isBaby ? .55f : 1.0f); setFlag(EntityFlag.BABY, isBaby); } - public void setConvertingToDrowned(EntityMetadata entityMetadata) { - convertingToDrowned = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setConvertingToDrowned(BooleanEntityMetadata entityMetadata) { + convertingToDrowned = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.SHAKING, isShaking()); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieVillagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieVillagerEntity.java index 744d3e559..b78aff8d8 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieVillagerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieVillagerEntity.java @@ -44,13 +44,13 @@ public class ZombieVillagerEntity extends ZombieEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - public void setTransforming(EntityMetadata entityMetadata) { - isTransforming = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setTransforming(BooleanEntityMetadata entityMetadata) { + isTransforming = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.IS_TRANSFORMING, isTransforming); setFlag(EntityFlag.SHAKING, isShaking()); } - public void setZombieVillagerData(EntityMetadata entityMetadata) { + public void setZombieVillagerData(EntityMetadata entityMetadata) { VillagerData villagerData = entityMetadata.getValue(); dirtyMetadata.put(EntityData.VARIANT, VillagerEntity.VILLAGER_PROFESSIONS.get(villagerData.getProfession())); // Actually works properly with the OptionalPack dirtyMetadata.put(EntityData.MARK_VARIANT, VillagerEntity.VILLAGER_REGIONS.get(villagerData.getType())); diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/SpellcasterIllagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/SpellcasterIllagerEntity.java index 1dca4fd0a..6c91b1720 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/SpellcasterIllagerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/SpellcasterIllagerEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster.raid; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -47,8 +46,8 @@ public class SpellcasterIllagerEntity extends AbstractIllagerEntity { setFlag(EntityFlag.BRIBED, this.definition == EntityDefinitions.ILLUSIONER); } - public void setSpellType(EntityMetadata entityMetadata) { - int spellType = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + public void setSpellType(ByteEntityMetadata entityMetadata) { + int spellType = entityMetadata.getPrimitiveValue(); // Summon vex, attack, or wololo setFlag(EntityFlag.CASTING, spellType == 1 || spellType == 2 || spellType == 3); int rgbData = switch (spellType) { diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/VindicatorEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/VindicatorEntity.java index 74616806c..db2225f37 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/VindicatorEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/VindicatorEntity.java @@ -25,7 +25,6 @@ package org.geysermc.connector.entity.living.monster.raid; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; @@ -41,10 +40,10 @@ public class VindicatorEntity extends AbstractIllagerEntity { } @Override - public void setMobFlags(EntityMetadata entityMetadata) { + public void setMobFlags(ByteEntityMetadata entityMetadata) { super.setMobFlags(entityMetadata); // Allow the axe to be shown if necessary - byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); + byte xd = entityMetadata.getPrimitiveValue(); setFlag(EntityFlag.ANGRY, (xd & 4) == 4); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java index 8c2471526..946ee2549 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java @@ -29,6 +29,7 @@ import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; +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.FloatEntityMetadata; import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardPosition; @@ -60,6 +61,7 @@ import org.geysermc.connector.scoreboard.UpdateType; import javax.annotation.Nullable; import java.util.Collections; +import java.util.Optional; import java.util.concurrent.TimeUnit; @Getter @Setter @@ -255,33 +257,33 @@ public class PlayerEntity extends LivingEntity { } @Override - public Vector3i setBedPosition(EntityMetadata entityMetadata) { + public Vector3i setBedPosition(EntityMetadata, ?> entityMetadata) { return bedPosition = super.setBedPosition(entityMetadata); } - public void setAbsorptionHearts(EntityMetadata entityMetadata) { + public void setAbsorptionHearts(FloatEntityMetadata entityMetadata) { // Extra hearts - is not metadata but an attribute on Bedrock UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); attributesPacket.setRuntimeEntityId(geyserId); // Setting to a higher maximum since plugins/datapacks can probably extend the Bedrock soft limit attributesPacket.setAttributes(Collections.singletonList( - new AttributeData("minecraft:absorption", 0.0f, 1024f, ((FloatEntityMetadata) entityMetadata).getPrimitiveValue(), 0.0f))); + new AttributeData("minecraft:absorption", 0.0f, 1024f, entityMetadata.getPrimitiveValue(), 0.0f))); session.sendUpstreamPacket(attributesPacket); } - public void setSkinVisibility(EntityMetadata entityMetadata) { + public void setSkinVisibility(ByteEntityMetadata entityMetadata) { // OptionalPack usage for toggling skin bits // In Java Edition, a bit being set means that part should be enabled // However, to ensure that the pack still works on other servers, we invert the bit so all values by default // are true (0). - dirtyMetadata.put(EntityData.MARK_VARIANT, ~((ByteEntityMetadata) entityMetadata).getPrimitiveValue() & 0xff); + dirtyMetadata.put(EntityData.MARK_VARIANT, ~entityMetadata.getPrimitiveValue() & 0xff); } - public void setLeftParrot(EntityMetadata entityMetadata) { + public void setLeftParrot(EntityMetadata entityMetadata) { setParrot(entityMetadata.getValue(), true); } - public void setRightParrot(EntityMetadata entityMetadata) { + public void setRightParrot(EntityMetadata entityMetadata) { setParrot(entityMetadata.getValue(), false); } @@ -330,7 +332,7 @@ public class PlayerEntity extends LivingEntity { } @Override - public void setDisplayName(EntityMetadata entityMetadata) { + public void setDisplayName(EntityMetadata, ?> entityMetadata) { // Doesn't do anything for players } @@ -385,7 +387,7 @@ public class PlayerEntity extends LivingEntity { } @Override - public void setDisplayNameVisible(EntityMetadata entityMetadata) { + public void setDisplayNameVisible(BooleanEntityMetadata entityMetadata) { // Doesn't do anything for players } diff --git a/connector/src/main/java/org/geysermc/connector/entity/player/SessionPlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/player/SessionPlayerEntity.java index bc6d4077a..9a367874e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/player/SessionPlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/player/SessionPlayerEntity.java @@ -110,14 +110,14 @@ public class SessionPlayerEntity extends PlayerEntity { } @Override - public void setFlags(EntityMetadata entityMetadata) { + public void setFlags(ByteEntityMetadata entityMetadata) { super.setFlags(entityMetadata); - session.setSwimmingInWater((((ByteEntityMetadata) entityMetadata).getPrimitiveValue() & 0x10) == 0x10 && getFlag(EntityFlag.SPRINTING)); + session.setSwimmingInWater((entityMetadata.getPrimitiveValue() & 0x10) == 0x10 && getFlag(EntityFlag.SPRINTING)); refreshSpeed = true; } @Override - public void setPose(EntityMetadata entityMetadata) { + public void setPose(EntityMetadata entityMetadata) { super.setPose(entityMetadata); session.setPose(entityMetadata.getValue()); refreshSpeed = true; @@ -132,11 +132,11 @@ public class SessionPlayerEntity extends PlayerEntity { } @Override - protected void setAir(int amount) { + protected void setAirSupply(int amount) { if (amount == getMaxAir()) { - super.setAir(0); // Hide the bubble counter from the UI for the player + super.setAirSupply(0); // Hide the bubble counter from the UI for the player } else { - super.setAir(amount); + super.setAirSupply(amount); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaSetEntityDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaSetEntityDataTranslator.java index 5b60fd3e3..25a7958df 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaSetEntityDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaSetEntityDataTranslator.java @@ -26,8 +26,10 @@ package org.geysermc.connector.network.translators.java.entity; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundSetEntityDataPacket; import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.EntityDefinition; import org.geysermc.connector.entity.EntityMetadataTranslator; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -39,6 +41,7 @@ import java.util.List; @Translator(packet = ClientboundSetEntityDataPacket.class) public class JavaSetEntityDataTranslator extends PacketTranslator { + @SuppressWarnings({"rawtypes", "unchecked"}) @Override public void translate(GeyserSession session, ClientboundSetEntityDataPacket packet) { Entity entity; @@ -49,30 +52,17 @@ public class JavaSetEntityDataTranslator extends PacketTranslator> translators = (List>) entity.getDefinition().translators(); - - for (EntityMetadata metadata : packet.getMetadata()) { - if (metadata.getId() >= translators.size()) { - session.getConnector().getLogger().warning("Metadata ID " + metadata.getId() + " is out of bounds of known entity metadata size " + translators.size() + " for entity type " + entity.getDefinition().entityType()); + EntityDefinition definition = entity.getDefinition(); + for (EntityMetadata metadata : packet.getMetadata()) { + if (metadata.getId() >= definition.translators().size()) { + session.getConnector().getLogger().warning("Metadata ID " + metadata.getId() + " is out of bounds of known entity metadata size " + definition.translators().size() + " for entity type " + entity.getDefinition().entityType()); if (session.getConnector().getConfig().isDebugMode()) { session.getConnector().getLogger().debug(metadata.toString()); } continue; } - EntityMetadataTranslator translator = (EntityMetadataTranslator) translators.get(metadata.getId()); - if (translator == null) { - // This can safely happen; it means we don't translate this entity metadata - continue; - } - if (translator.acceptedType() != metadata.getType()) { - session.getConnector().getLogger().warning("Metadata ID " + metadata.getId() + " was received with type " + metadata.getType() + " but we expected " + translator.acceptedType() + " for " + entity.getDefinition().entityType()); - if (session.getConnector().getConfig().isDebugMode()) { - session.getConnector().getLogger().debug(metadata.toString()); - } - continue; - } - translator.translateFunction().accept(entity, (EntityMetadata) metadata); + ((EntityDefinition) definition).translateMetadata(entity, metadata); } entity.updateBedrockMetadata(); diff --git a/connector/src/main/java/org/geysermc/connector/registry/loader/EnchantmentRegistryLoader.java b/connector/src/main/java/org/geysermc/connector/registry/loader/EnchantmentRegistryLoader.java index a1a95fe1a..05fed47eb 100644 --- a/connector/src/main/java/org/geysermc/connector/registry/loader/EnchantmentRegistryLoader.java +++ b/connector/src/main/java/org/geysermc/connector/registry/loader/EnchantmentRegistryLoader.java @@ -39,6 +39,7 @@ import org.geysermc.connector.utils.FileUtils; import java.io.InputStream; import java.util.EnumMap; import java.util.EnumSet; +import java.util.HashMap; import java.util.Iterator; import java.util.Map; diff --git a/connector/src/main/java/org/geysermc/connector/registry/loader/ParticleTypesRegistryLoader.java b/connector/src/main/java/org/geysermc/connector/registry/loader/ParticleTypesRegistryLoader.java index 5ebd903c0..ca2940845 100644 --- a/connector/src/main/java/org/geysermc/connector/registry/loader/ParticleTypesRegistryLoader.java +++ b/connector/src/main/java/org/geysermc/connector/registry/loader/ParticleTypesRegistryLoader.java @@ -32,6 +32,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.registry.type.ParticleMapping; +import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Map;