Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions patches/minecraft/net/minecraft/entity/EntityLiving.java.patch
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
--- before/net/minecraft/entity/EntityLiving.java
+++ after/net/minecraft/entity/EntityLiving.java
@@ -171,6 +171,7 @@
@@ -171,6 +171,6 @@
public void setAttackTarget(@Nullable EntityLivingBase entitylivingbaseIn)
{
this.attackTarget = entitylivingbaseIn;
+ net.minecraftforge.common.ForgeHooks.onLivingSetAttackTarget(this, entitylivingbaseIn);
- this.attackTarget = entitylivingbaseIn;
+ this.attackTarget = net.minecraftforge.common.ForgeHooks.onLivingSetAttackTarget(this, entitylivingbaseIn);
}

public boolean canAttackClass(Class <? extends EntityLivingBase > cls)
@@ -601,7 +602,7 @@
@@ -601,7 +601,7 @@
super.onLivingUpdate();
this.world.profiler.startSection("looting");

Expand All @@ -17,7 +17,7 @@
{
for (EntityItem entityitem : this.world.getEntitiesWithinAABB(EntityItem.class, this.getEntityBoundingBox().grow(1.0, 0.0, 1.0)))
{
@@ -729,10 +730,22 @@
@@ -729,10 +729,22 @@

protected void despawnEntity()
{
Expand All @@ -40,15 +40,15 @@
else
{
Entity entity = this.world.getClosestPlayerToEntity(this, -1.0);
@@ -870,7 +883,6 @@
@@ -870,7 +882,6 @@
&& this.world.checkNoEntityCollision(this.getEntityBoundingBox(), this);
}

- @SideOnly(Side.CLIENT)
public float getRenderSizeModifier()
{
return 1.0F;
@@ -1033,6 +1045,8 @@
@@ -1033,6 +1044,8 @@

public static EntityEquipmentSlot getSlotForItemStack(ItemStack stack)
{
Expand All @@ -57,7 +57,7 @@
if (stack.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN) || stack.getItem() == Items.SKULL)
{
return EntityEquipmentSlot.HEAD;
@@ -1047,7 +1061,7 @@
@@ -1047,7 +1060,7 @@
}
else
{
Expand All @@ -66,7 +66,7 @@
}
}

@@ -1490,5 +1504,19 @@
@@ -1490,5 +1503,19 @@
ON_GROUND,
IN_AIR,
IN_WATER;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/net/minecraftforge/common/ForgeHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityMinecartContainer;
Expand Down Expand Up @@ -576,11 +577,20 @@ public static void onDifficultyChange(EnumDifficulty difficulty, EnumDifficulty
//Optifine Helper Functions u.u, these are here specifically for Optifine
//Note: When using Optifine, these methods are invoked using reflection, which
//incurs a major performance penalty.
@Deprecated(since = "15.24.0.3026")
public static void onLivingSetAttackTarget(EntityLivingBase entity, EntityLivingBase target)
{
MinecraftForge.EVENT_BUS.post(new LivingSetAttackTargetEvent(entity, target));
}

public static EntityLivingBase onLivingSetAttackTarget(EntityLiving living, EntityLivingBase target)
{
LivingSetAttackTargetEvent event = new LivingSetAttackTargetEvent(living, target);
if (MinecraftForge.EVENT_BUS.post(event)){
return living.getAttackTarget();
}else return event.getTarget();
}

public static boolean onLivingUpdate(EntityLivingBase entity)
{
return MinecraftForge.EVENT_BUS.post(new LivingUpdateEvent(entity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,59 @@
* This event is fired whenever an Entity sets a target to attack in
* {@link EntityLiving#setAttackTarget(EntityLivingBase)}.<br>
* <br>
* This event is fired via the {@link ForgeHooks#onLivingSetAttackTarget(EntityLivingBase, EntityLivingBase)}.<br>
* This event is fired via the {@link ForgeHooks#onLivingSetAttackTarget(EntityLiving, EntityLivingBase)}.<br>
* <br>
* {@link #target} contains the newly targeted Entity.<br>
* {@link #originalTarget} contains the newly targeted Entity.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* {@link #newTarget} contains the redirected Targeted Entity.<br>
* <br>
* This event is {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class LivingSetAttackTargetEvent extends LivingEvent
{

private final EntityLivingBase target;
@Cancelable
public class LivingSetAttackTargetEvent extends LivingEvent{
private final EntityLivingBase originalTarget;
private EntityLivingBase newTarget;
private boolean isModified;

public LivingSetAttackTargetEvent(EntityLivingBase entity, EntityLivingBase target)
{
super(entity);
this.target = target;
this.originalTarget = target;
this.newTarget = null;
this.isModified = false;
}

/**
* Get the target that will be actually applied
**/
public EntityLivingBase getTarget()
{
return target;
return isModified ? newTarget : originalTarget;
}

/**
* return the original attack target
**/
public EntityLivingBase getOriginalTarget(){
return originalTarget;
}

/**
* Set the attack target of the living's, null if remove it
**/
public void setNewTarget(EntityLivingBase living){
this.newTarget = living;
this.isModified = true;
}

/**
* Is the attack target is modified
**/
public boolean isModified(){
Comment thread
Ecdcaeb marked this conversation as resolved.
return this.isModified;
}
}