Revert EntityEvent.Size changes to before #9018 was called. (#9679)

Kept newly added methods for binary compatibility but deprecated them all for removal.
The entire pose/eye/size system needs to be reevaluated and address some of Mojang's changes.
However this should fix any bugs that pulling that PR may of caused.
This commit is contained in:
LexManos authored and GitHub committed 2023-07-21 23:44:01 -07:00
1 parent 93a615e900
commit f157567d2a
5 files changed
+47 -120

No files matched your search

@@ -430,12 +430,10 @@ public interface IForgeEntity extends ICapabilitySerializable<CompoundTag>
return false;
}
@Deprecated(forRemoval = true, since = "1.20.1") // Remove Entity Eye/Size hooks, as they need to be redesigned
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();
return self().getEyeHeightAccess(pose, size);
}
/**
@@ -40,11 +40,13 @@ 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.EntityDimensions;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.LightningBolt;
import net.minecraft.world.entity.item.ItemEntity;
@@ -89,6 +91,7 @@ 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;
@@ -268,7 +271,7 @@ public class ForgeEventFactory
* @see MobSpawnEvent.FinalizeSpawn
* @see Mob#finalizeSpawn(ServerLevelAccessor, DifficultyInstance, MobSpawnType, SpawnGroupData, CompoundTag)
* @apiNote Callers do not need to check if the entity's spawn was cancelled, as the spawn will be blocked by Forge.
* @implNote Changes to the signature of this method must be reflected in the method redirector coremod.
* @implNote Changes to the signature of this method must be reflected in the method redirector coremod.
*/
@Nullable
@SuppressWarnings("deprecation") // Call to deprecated Mob#finalizeSpawn is expected.
@@ -789,6 +792,22 @@ public class ForgeEventFactory
MinecraftForge.EVENT_BUS.post(event);
}
@Deprecated(forRemoval = true, since = "1.20.1") // Remove Entity Eye/Size hooks, as they need to be redesigned
public static net.minecraftforge.event.entity.EntityEvent.Size getEntitySizeForge(Entity entity, Pose pose, EntityDimensions size, float eyeHeight)
{
var evt = new EntityEvent.Size(entity, pose, size, eyeHeight);
MinecraftForge.EVENT_BUS.post(evt);
return evt;
}
@Deprecated(forRemoval = true, since = "1.20.1") // Remove Entity Eye/Size hooks, as they need to be redesigned
public static net.minecraftforge.event.entity.EntityEvent.Size getEntitySizeForge(Entity entity, Pose pose, EntityDimensions oldSize, EntityDimensions newSize, float newEyeHeight)
{
var 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));
@@ -128,7 +128,6 @@ public class EntityEvent extends Event
}
/**
* This event is fired whenever {@link Entity#getDimensionsForge(Pose)} gets called.<br>
* CAREFUL: This is also fired in the Entity constructor. Therefore, the entity (subclass) might not be fully initialized. Check {@link Entity#isAddedToWorld()} or {@code !Entity.firstUpdate}.<br>
* If you change the player's size, you probably want to set the eye height accordingly as well<br>
* <br>
@@ -138,28 +137,23 @@ public class EntityEvent extends Event
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Size extends EntityEvent
{
@Deprecated(forRemoval = true, since = "1.20.1") // Remove Entity Eye/Size hooks, as they need to be redesigned
public static class Size extends EntityEvent {
private final Pose pose;
private final EntityDimensions originalSize;
private EntityDimensions newSize;
private final float oldEyeHeight;
private float newEyeHeight;
public Size(Entity entity, Pose pose, EntityDimensions size)
{
public Size(Entity entity, Pose pose, EntityDimensions size) {
this(entity, pose, size, 1.0f); // Eye height doesn't matter this is just for binary compatibility.
}
@Deprecated(forRemoval = true, since = "1.20.1")
public Size(Entity entity, Pose pose, EntityDimensions size, float defaultEyeHeight)
{
public Size(Entity entity, Pose pose, EntityDimensions size, float defaultEyeHeight) {
this(entity, pose, size, size, defaultEyeHeight, defaultEyeHeight);
}
@Deprecated(forRemoval = true, since = "1.20.1")
public Size(Entity entity, Pose pose, EntityDimensions oldSize, EntityDimensions newSize, float oldEyeHeight, float newEyeHeight)
{
public Size(Entity entity, Pose pose, EntityDimensions oldSize, EntityDimensions newSize, float oldEyeHeight, float newEyeHeight) {
super(entity);
this.pose = pose;
this.originalSize = oldSize;
@@ -169,50 +163,33 @@ public class EntityEvent extends Event
}
public Pose getPose() { return pose; }
/** @deprecated Use {@link #getOriginalSize()} */
@Deprecated(forRemoval = true, since = "1.20.1")
public EntityDimensions getOldSize() { return this.getOriginalSize(); }
public EntityDimensions getOriginalSize() { return originalSize; }
public EntityDimensions getNewSize() { return newSize; }
public void setNewSize(EntityDimensions size) { this.newSize = size; }
/** @deprecated Use {@link EyeHeight} to hook into changes to eye height. Updating the eye height will not actually so anything anymore. */
@Deprecated(forRemoval = true)
public void setNewSize(EntityDimensions size, boolean updateEyeHeight)
{
public void setNewSize(EntityDimensions size, boolean updateEyeHeight) {
this.setNewSize(size);
if (updateEyeHeight)
{
if (updateEyeHeight) {
this.newEyeHeight = this.getEntity().getEyeHeightAccess(this.getPose(), this.newSize);
}
}
/** @deprecated Use {@link EyeHeight} to hook into changes to eye height. */
@Deprecated(forRemoval = true, since = "1.20.1")
public float getOldEyeHeight() { return oldEyeHeight; }
/** @deprecated Use {@link EyeHeight} to hook into changes to eye height. */
@Deprecated(forRemoval = true, since = "1.20.1")
public float getNewEyeHeight() { return newEyeHeight; }
public void setNewEyeHeight(float eyeHeight) { this.newEyeHeight = eyeHeight; }
}
/**
* This event is fired whenever {@link IForgeEntity#getEyeHeightForge(Pose, EntityDimensions)} gets called.<br>
* CAREFUL: This is also fired in the Entity constructor. Therefore, the entity (subclass) might not be fully initialized. Check {@link Entity#isAddedToWorld()} or {@code !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>
*Remove Entity Eye/Size hooks, as they need to be redesigned, this is no longer fired in any forge/vanilla code.
**/
public static class EyeHeight extends EntityEvent
{
@Deprecated(forRemoval = true, since = "1.20.1")
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)
{
public EyeHeight(Entity entity, Pose pose, EntityDimensions size, float eyeHeight) {
super(entity);
this.pose = pose;
this.size = size;