diff --git a/patches/net/minecraft/world/entity/Entity.java.patch b/patches/net/minecraft/world/entity/Entity.java.patch index f8cf8c0824..9df92f179a 100644 --- a/patches/net/minecraft/world/entity/Entity.java.patch +++ b/patches/net/minecraft/world/entity/Entity.java.patch @@ -32,10 +32,9 @@ this.defineSynchedData(synchedentitydata$builder); this.entityData = synchedentitydata$builder.build(); this.setPos(0.0, 0.0, 0.0); -- this.eyeHeight = this.dimensions.eyeHeight(); -+ net.neoforged.neoforge.event.entity.EntityEvent.Size sizeEvent = net.neoforged.neoforge.event.EventHooks.getEntitySizeForge(this, Pose.STANDING, this.dimensions, this.dimensions.eyeHeight()); ++ net.neoforged.neoforge.event.entity.EntityEvent.Size sizeEvent = net.neoforged.neoforge.event.EventHooks.getEntitySizeForge(this, Pose.STANDING, this.dimensions); + this.dimensions = sizeEvent.getNewSize(); -+ this.eyeHeight = sizeEvent.getNewEyeHeight(); + this.eyeHeight = this.dimensions.eyeHeight(); + net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.event.entity.EntityEvent.EntityConstructing(this)); } @@ -325,7 +324,7 @@ EntityDimensions entitydimensions = this.dimensions; Pose pose = this.getPose(); EntityDimensions entitydimensions1 = this.getDimensions(pose); -+ net.neoforged.neoforge.event.entity.EntityEvent.Size sizeEvent = net.neoforged.neoforge.event.EventHooks.getEntitySizeForge(this, pose, entitydimensions, entitydimensions1, entitydimensions1.eyeHeight()); // Porting 1.20.5 check if this still works ++ net.neoforged.neoforge.event.entity.EntityEvent.Size sizeEvent = net.neoforged.neoforge.event.EventHooks.getEntitySizeForge(this, pose, entitydimensions, entitydimensions1); + entitydimensions1 = sizeEvent.getNewSize(); this.dimensions = entitydimensions1; this.eyeHeight = entitydimensions1.eyeHeight(); @@ -453,7 +452,7 @@ } public void checkDespawn() { -@@ -3450,6 +_,117 @@ +@@ -3450,6 +_,109 @@ public boolean mayInteract(Level p_146843_, BlockPos p_146844_) { return true; } @@ -508,14 +507,6 @@ + this.unsetRemoved(); + } + -+ // no AT because of overrides -+ /** -+ * Accessor method for {@link #getEyeHeight(Pose)} -+ */ -+ public float getEyeHeightAccess(Pose pose) { -+ return this.getEyeHeight(pose); -+ } -+ + protected Object2DoubleMap forgeFluidTypeHeight = new Object2DoubleArrayMap<>(net.neoforged.neoforge.fluids.FluidType.SIZE.get()); + private net.neoforged.neoforge.fluids.FluidType forgeFluidTypeOnEyes = net.neoforged.neoforge.common.NeoForgeMod.EMPTY_TYPE.value(); + protected final void setFluidTypeHeight(net.neoforged.neoforge.fluids.FluidType type, double height) { diff --git a/src/main/java/net/neoforged/neoforge/event/EventHooks.java b/src/main/java/net/neoforged/neoforge/event/EventHooks.java index 94909f0ab2..7975551521 100644 --- a/src/main/java/net/neoforged/neoforge/event/EventHooks.java +++ b/src/main/java/net/neoforged/neoforge/event/EventHooks.java @@ -807,14 +807,14 @@ public static void onCommandRegister(CommandDispatcher dispa NeoForge.EVENT_BUS.post(event); } - public static EntityEvent.Size getEntitySizeForge(Entity entity, Pose pose, EntityDimensions size, float eyeHeight) { - EntityEvent.Size evt = new EntityEvent.Size(entity, pose, size, eyeHeight); + public static EntityEvent.Size getEntitySizeForge(Entity entity, Pose pose, EntityDimensions size) { + EntityEvent.Size evt = new EntityEvent.Size(entity, pose, size); NeoForge.EVENT_BUS.post(evt); return evt; } - public static EntityEvent.Size getEntitySizeForge(Entity entity, Pose pose, EntityDimensions oldSize, EntityDimensions newSize, float newEyeHeight) { - EntityEvent.Size evt = new EntityEvent.Size(entity, pose, oldSize, newSize, entity.getEyeHeight(), newEyeHeight); + public static EntityEvent.Size getEntitySizeForge(Entity entity, Pose pose, EntityDimensions oldSize, EntityDimensions newSize) { + EntityEvent.Size evt = new EntityEvent.Size(entity, pose, oldSize, newSize); NeoForge.EVENT_BUS.post(evt); return evt; } diff --git a/src/main/java/net/neoforged/neoforge/event/entity/EntityEvent.java b/src/main/java/net/neoforged/neoforge/event/entity/EntityEvent.java index 199a4a5ffe..338fadf3f4 100644 --- a/src/main/java/net/neoforged/neoforge/event/entity/EntityEvent.java +++ b/src/main/java/net/neoforged/neoforge/event/entity/EntityEvent.java @@ -114,34 +114,29 @@ public boolean didChunkChange() { } /** - * This event is fired whenever the {@link Pose} changes, and in a few other hardcoded scenarios.
- * CAREFUL: This is also fired in the Entity constructor. Therefore the entity(subclass) might not be fully initialized. Check Entity#isAddedToWorld() or !Entity#firstUpdate.
- * If you change the player's size, you probably want to set the eye height accordingly as well
- *
- * This event is not {@link ICancellableEvent}.
- *
- * This event does not have a result. {@link HasResult} - *
- * This event is fired on the {@link NeoForge#EVENT_BUS}.
+ * Fired whenever the entity's {@link Pose} changes for manipulating the resulting {@link EntityDimensions}. + * + *

Note: This event is fired from the {@code Entity} constructor, and therefore the entity instance + * might not be fully initialized. Be cautious in using methods and fields from the instance, and check + * {@link Entity#isAddedToWorld()} or {@link Entity#firstTick}. + * + *

This event is not {@linkplain net.neoforged.bus.api.ICancellableEvent cancellable}, and is fired on the + * {@linkplain NeoForge#EVENT_BUS game event bus}. **/ public static class Size extends EntityEvent { private final Pose pose; private final EntityDimensions oldSize; private EntityDimensions newSize; - private final float oldEyeHeight; - private float newEyeHeight; - public Size(Entity entity, Pose pose, EntityDimensions size, float defaultEyeHeight) { - this(entity, pose, size, size, defaultEyeHeight, defaultEyeHeight); + public Size(Entity entity, Pose pose, EntityDimensions size) { + this(entity, pose, size, size); } - public Size(Entity entity, Pose pose, EntityDimensions oldSize, EntityDimensions newSize, float oldEyeHeight, float newEyeHeight) { + public Size(Entity entity, Pose pose, EntityDimensions oldSize, EntityDimensions newSize) { super(entity); this.pose = pose; this.oldSize = oldSize; this.newSize = newSize; - this.oldEyeHeight = oldEyeHeight; - this.newEyeHeight = newEyeHeight; } public Pose getPose() { @@ -157,29 +152,7 @@ public EntityDimensions getNewSize() { } public void setNewSize(EntityDimensions size) { - setNewSize(size, false); - } - - /** - * Set the new size of the entity. Set updateEyeHeight to true to also update the eye height according to the new size. - */ - public void setNewSize(EntityDimensions size, boolean updateEyeHeight) { this.newSize = size; - if (updateEyeHeight) { - this.newEyeHeight = this.getEntity().getEyeHeightAccess(this.getPose()); - } - } - - public float getOldEyeHeight() { - return oldEyeHeight; - } - - public float getNewEyeHeight() { - return newEyeHeight; - } - - public void setNewEyeHeight(float newHeight) { - this.newEyeHeight = newHeight; } } }