From 249f04441dedbf4fb480d9fd6cf49f90d1afd788 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Fri, 4 Jun 2021 22:26:29 -0400 Subject: [PATCH] Set entity dimensions for goat long jumping --- .../org/geysermc/connector/entity/Entity.java | 35 ++++++------------- .../connector/entity/LivingEntity.java | 11 ++++++ .../entity/living/animal/GoatEntity.java | 14 ++++++++ .../connector/entity/player/PlayerEntity.java | 21 +++++++++++ 4 files changed, 56 insertions(+), 25 deletions(-) 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 bdd01ee4e..505278653 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -303,31 +303,7 @@ public class Entity { metadata.getFlags().setFlag(EntityFlag.SLEEPING, pose.equals(Pose.SLEEPING)); // Triggered when crawling metadata.getFlags().setFlag(EntityFlag.SWIMMING, pose.equals(Pose.SWIMMING)); - float width = entityType.getWidth(); - float height = entityType.getHeight(); - switch (pose) { - case SLEEPING: - if (this instanceof LivingEntity) { - width = 0.2f; - height = 0.2f; - } - break; - case SNEAKING: - if (entityType == EntityType.PLAYER) { - height = 1.5f; - } - break; - case FALL_FLYING: - case SPIN_ATTACK: - case SWIMMING: - if (entityType == EntityType.PLAYER) { - // Seems like this is only cared about for players; nothing else - height = 0.6f; - } - break; - } - metadata.put(EntityData.BOUNDING_BOX_WIDTH, width); - metadata.put(EntityData.BOUNDING_BOX_HEIGHT, height); + setDimensions(pose); break; case 7: //TODO check @@ -349,6 +325,15 @@ public class Entity { session.sendUpstreamPacket(entityDataPacket); } + /** + * Set the height and width of the entity's bounding box + */ + protected void setDimensions(Pose pose) { + // No flexibility options for basic entities + metadata.put(EntityData.BOUNDING_BOX_WIDTH, entityType.getWidth()); + metadata.put(EntityData.BOUNDING_BOX_HEIGHT, entityType.getHeight()); + } + /** * x = Pitch, y = HeadYaw, z = Yaw * 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 66244da86..9ccb91fc1 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java @@ -26,6 +26,7 @@ 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.Pose; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3i; @@ -111,6 +112,16 @@ public class LivingEntity extends Entity { super.updateBedrockMetadata(entityMetadata, session); } + @Override + protected void setDimensions(Pose pose) { + if (pose == Pose.SLEEPING) { + metadata.put(EntityData.BOUNDING_BOX_WIDTH, 0.2f); + metadata.put(EntityData.BOUNDING_BOX_HEIGHT, 0.2f); + } else { + super.setDimensions(pose); + } + } + public void updateAllEquipment(GeyserSession session) { if (!valid) return; 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 00e163496..e0c5066d6 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 @@ -26,11 +26,16 @@ 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.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.entity.EntityData; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; public class GoatEntity extends AnimalEntity { + private static final float LONG_JUMPING_HEIGHT = 1.3f * 0.7f; + private static final float LONG_JUMPING_WIDTH = 0.9f * 0.7f; + public GoatEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { super(entityId, geyserId, entityType, position, motion, rotation); } @@ -39,6 +44,15 @@ public class GoatEntity extends AnimalEntity { public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { super.updateBedrockMetadata(entityMetadata, session); + } + @Override + protected void setDimensions(Pose pose) { + if (pose == Pose.LONG_JUMPING) { + metadata.put(EntityData.BOUNDING_BOX_WIDTH, LONG_JUMPING_WIDTH); + metadata.put(EntityData.BOUNDING_BOX_HEIGHT, LONG_JUMPING_HEIGHT); + } else { + super.setDimensions(pose); + } } } 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 f057438cb..3cda303cd 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 @@ -27,6 +27,7 @@ package org.geysermc.connector.entity.player; 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.opennbt.tag.builtin.CompoundTag; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3i; @@ -334,6 +335,26 @@ public class PlayerEntity extends LivingEntity { } } + @Override + protected void setDimensions(Pose pose) { + float height; + switch (pose) { + case SNEAKING: + height = 1.5f; + break; + case FALL_FLYING: + case SPIN_ATTACK: + case SWIMMING: + height = 0.6f; + break; + default: + super.setDimensions(pose); + return; + } + metadata.put(EntityData.BOUNDING_BOX_WIDTH, entityType.getWidth()); + metadata.put(EntityData.BOUNDING_BOX_HEIGHT, height); + } + @Override public void updateBedrockAttributes(GeyserSession session) { // TODO: Don't use duplicated code if (!valid) return;