Skip to content

Commit

Permalink
Remove separate eye height field from EntityEvent.Size (#1171)
Browse files Browse the repository at this point in the history
  • Loading branch information
sciwhiz12 authored Jun 24, 2024
1 parent e6b59aa commit 28d0463
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 55 deletions.
17 changes: 4 additions & 13 deletions patches/net/minecraft/world/entity/Entity.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -453,7 +452,7 @@
}

public void checkDespawn() {
@@ -3450,6 +_,117 @@
@@ -3450,6 +_,109 @@
public boolean mayInteract(Level p_146843_, BlockPos p_146844_) {
return true;
}
Expand Down Expand Up @@ -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<net.neoforged.neoforge.fluids.FluidType> 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) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/neoforged/neoforge/event/EventHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -807,14 +807,14 @@ public static void onCommandRegister(CommandDispatcher<CommandSourceStack> 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;
}
Expand Down
49 changes: 11 additions & 38 deletions src/main/java/net/neoforged/neoforge/event/entity/EntityEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,29 @@ public boolean didChunkChange() {
}

/**
* This event is fired whenever the {@link Pose} changes, and in a few other hardcoded scenarios.<br>
* CAREFUL: This is also fired in the Entity constructor. Therefore the entity(subclass) might not be fully initialized. Check Entity#isAddedToWorld() or !Entity#firstUpdate.<br>
* If you change the player's size, you probably want to set the eye height accordingly as well<br>
* <br>
* This event is not {@link ICancellableEvent}.<br>
* <br>
* This event does not have a result. {@link HasResult}
* <br>
* This event is fired on the {@link NeoForge#EVENT_BUS}.<br>
* Fired whenever the entity's {@link Pose} changes for manipulating the resulting {@link EntityDimensions}.
*
* <p><strong>Note:</strong> 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}.
*
* <p>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() {
Expand All @@ -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;
}
}
}

0 comments on commit 28d0463

Please sign in to comment.