mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Fix entity size event not being fired, changed it to split eye height and size calculations. (#9535)
This commit is contained in:
1 parent
2c965fac90
commit
77fb08713f
6 files changed
+138
-59
No files matched your search
@@ -16,7 +16,9 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.entity.Pose;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.SpawnEggItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -26,9 +28,11 @@ import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.common.ForgeSpawnEggItem;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.SoundAction;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.minecraftforge.entity.PartEntity;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.fluids.FluidType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -424,4 +428,20 @@ public interface IForgeEntity extends ICapabilitySerializable<CompoundTag>
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
default EntityDimensions getDimensionsForge(Pose pose)
|
||||
{
|
||||
EntityDimensions size = self().getDimensions(pose);
|
||||
EntityEvent.Size evt = new EntityEvent.Size(self(), pose, size);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return evt.getNewSize();
|
||||
}
|
||||
|
||||
default float getEyeHeightForge(Pose pose, EntityDimensions size)
|
||||
{
|
||||
float eyeHeight = self().getEyeHeightAccess(pose, size);
|
||||
EntityEvent.EyeHeight evt = new EntityEvent.EyeHeight(self(), pose, size, eyeHeight);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return evt.getNewEyeHeight();
|
||||
}
|
||||
}
|
||||
@@ -40,10 +40,8 @@ import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.Pose;
|
||||
import net.minecraft.world.entity.SpawnGroupData;
|
||||
import net.minecraft.world.entity.SpawnPlacements;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.MobSpawnType;
|
||||
@@ -91,7 +89,6 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.event.brewing.PlayerBrewedPotionEvent;
|
||||
import net.minecraftforge.event.brewing.PotionBrewEvent;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.event.entity.EntityMobGriefingEvent;
|
||||
import net.minecraftforge.event.entity.EntityMountEvent;
|
||||
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
|
||||
@@ -792,20 +789,6 @@ public class ForgeEventFactory
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static net.minecraftforge.event.entity.EntityEvent.Size getEntitySizeForge(Entity entity, Pose pose, EntityDimensions size, float eyeHeight)
|
||||
{
|
||||
EntityEvent.Size evt = new EntityEvent.Size(entity, pose, size, eyeHeight);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return evt;
|
||||
}
|
||||
|
||||
public static net.minecraftforge.event.entity.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);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return evt;
|
||||
}
|
||||
|
||||
public static boolean canLivingConvert(LivingEntity entity, EntityType<? extends LivingEntity> outcome, Consumer<Integer> timer)
|
||||
{
|
||||
return !MinecraftForge.EVENT_BUS.post(new LivingConversionEvent.Pre(entity, outcome, timer));
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
import net.minecraft.world.entity.Pose;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.extensions.IForgeEntity;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
@@ -127,7 +128,7 @@ public class EntityEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired whenever the {@link Pose} changes, and in a few other hardcoded scenarios.<br>
|
||||
* This event is fired whenever {@link IForgeEntity#getDimensionsForge(Pose)} gets called.<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>
|
||||
@@ -140,48 +141,53 @@ public class EntityEvent extends Event
|
||||
public static class Size extends EntityEvent
|
||||
{
|
||||
private final Pose pose;
|
||||
private final EntityDimensions oldSize;
|
||||
private final EntityDimensions originalSize;
|
||||
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 oldSize, EntityDimensions newSize, float oldEyeHeight, float newEyeHeight)
|
||||
public Size(Entity entity, Pose pose, EntityDimensions size)
|
||||
{
|
||||
super(entity);
|
||||
this.pose = pose;
|
||||
this.oldSize = oldSize;
|
||||
this.newSize = newSize;
|
||||
this.oldEyeHeight = oldEyeHeight;
|
||||
this.newEyeHeight = newEyeHeight;
|
||||
this.originalSize = size;
|
||||
this.newSize = size;
|
||||
}
|
||||
|
||||
|
||||
public Pose getPose() { return pose; }
|
||||
public EntityDimensions getOldSize() { return oldSize; }
|
||||
public EntityDimensions getOriginalSize() { return originalSize; }
|
||||
public EntityDimensions getNewSize() { return newSize; }
|
||||
public void setNewSize(EntityDimensions size)
|
||||
public void setNewSize(EntityDimensions newSize) { this.newSize = newSize; }
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired whenever {@link IForgeEntity#getEyeHeightForge(Pose)} gets called.<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>
|
||||
* <br>
|
||||
* This event is not {@link Cancelable}.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static class EyeHeight extends EntityEvent
|
||||
{
|
||||
private final Pose pose;
|
||||
private final EntityDimensions size;
|
||||
private final float originalEyeHeight;
|
||||
private float newEyeHeight;
|
||||
|
||||
public EyeHeight(Entity entity, Pose pose, EntityDimensions size, float eyeHeight)
|
||||
{
|
||||
setNewSize(size, false);
|
||||
super(entity);
|
||||
this.pose = pose;
|
||||
this.size = size;
|
||||
this.originalEyeHeight = eyeHeight;
|
||||
this.newEyeHeight = eyeHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), this.newSize);
|
||||
}
|
||||
}
|
||||
public float getOldEyeHeight() { return oldEyeHeight; }
|
||||
public Pose getPose() { return pose; }
|
||||
public EntityDimensions getSize() { return size; }
|
||||
public float getOriginalEyeHeight() { return originalEyeHeight; }
|
||||
public float getNewEyeHeight() { return newEyeHeight; }
|
||||
public void setNewEyeHeight(float newHeight) { this.newEyeHeight = newHeight; }
|
||||
public void setNewEyeHeight(float newEyeHeight) { this.newEyeHeight = newEyeHeight; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user