Added event to allow modification of player visibility to mobs/AI (#3382)

(cherry picked from commit 0a5ef64d6ea96fe85d7c62107081ced649e6a3e9)
This commit is contained in:
LexManos 2016-11-16 15:10:14 -08:00
parent def75dc092
commit f0d9bf7886
3 changed files with 60 additions and 10 deletions

View file

@ -692,7 +692,16 @@
}
public boolean func_175640_z(BlockPos p_175640_1_)
@@ -3240,7 +3427,7 @@
@@ -3179,6 +3366,8 @@
d2 *= ((Double)Objects.firstNonNull(p_184150_11_.apply(entityplayer1), Double.valueOf(1.0D))).doubleValue();
}
+ d2 = net.minecraftforge.common.ForgeHooks.getPlayerVisibilityDistance(entityplayer1, d2, p_184150_9_);
+
if ((p_184150_9_ < 0.0D || Math.abs(entityplayer1.field_70163_u - p_184150_3_) < p_184150_9_ * p_184150_9_) && (p_184150_7_ < 0.0D || d1 < d2 * d2) && (d0 == -1.0D || d1 < d0))
{
d0 = d1;
@@ -3240,7 +3429,7 @@
public long func_72905_C()
{
@ -701,7 +710,7 @@
}
public long func_82737_E()
@@ -3250,17 +3437,17 @@
@@ -3250,17 +3439,17 @@
public long func_72820_D()
{
@ -722,7 +731,7 @@
if (!this.func_175723_af().func_177746_a(blockpos))
{
@@ -3272,7 +3459,7 @@
@@ -3272,7 +3461,7 @@
public void func_175652_B(BlockPos p_175652_1_)
{
@ -731,7 +740,7 @@
}
@SideOnly(Side.CLIENT)
@@ -3292,12 +3479,18 @@
@@ -3292,12 +3481,18 @@
if (!this.field_72996_f.contains(p_72897_1_))
{
@ -750,7 +759,7 @@
return true;
}
@@ -3391,8 +3584,7 @@
@@ -3391,8 +3586,7 @@
public boolean func_180502_D(BlockPos p_180502_1_)
{
@ -760,7 +769,7 @@
}
@Nullable
@@ -3453,12 +3645,12 @@
@@ -3453,12 +3647,12 @@
public int func_72800_K()
{
@ -775,7 +784,7 @@
}
public Random func_72843_D(int p_72843_1_, int p_72843_2_, int p_72843_3_)
@@ -3502,7 +3694,7 @@
@@ -3502,7 +3696,7 @@
@SideOnly(Side.CLIENT)
public double func_72919_O()
{
@ -784,7 +793,7 @@
}
public void func_175715_c(int p_175715_1_, BlockPos p_175715_2_, int p_175715_3_)
@@ -3536,7 +3728,7 @@
@@ -3536,7 +3730,7 @@
public void func_175666_e(BlockPos p_175666_1_, Block p_175666_2_)
{
@ -793,7 +802,7 @@
{
BlockPos blockpos = p_175666_1_.func_177972_a(enumfacing);
@@ -3621,6 +3813,112 @@
@@ -3621,6 +3815,112 @@
return i >= -128 && i <= 128 && j >= -128 && j <= 128;
}

View file

@ -116,6 +116,7 @@ import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
import net.minecraftforge.event.entity.living.LootingLevelEvent;
import net.minecraftforge.event.entity.player.AnvilRepairEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.NoteBlockEvent;
@ -586,6 +587,14 @@ public class ForgeHooks
return event.getLootingLevel();
}
public static double getPlayerVisibilityDistance(EntityPlayer player, double xzDistance, double maxXZDistance)
{
PlayerEvent.Visibility event = new PlayerEvent.Visibility(player);
MinecraftForge.EVENT_BUS.post(event);
double value = event.getVisibilityModifier() * xzDistance;
return value >= maxXZDistance ? maxXZDistance : value;
}
public static boolean isLivingOnLadder(IBlockState state, World world, BlockPos pos, EntityLivingBase entity)
{
boolean isSpectator = (entity instanceof EntityPlayer && ((EntityPlayer)entity).isSpectator());

View file

@ -351,4 +351,36 @@ public class PlayerEvent extends LivingEvent
return playerUUID;
}
}
/**
* Fired when the world checks if a player is near enough to be attacked by an entity.
* The resulting visibility modifier is multiplied by the one calculated by Minecraft (based on sneaking and more) and used to calculate the radius a player has to be in (targetDistance*modifier).
* This can also be used to increase the visibility of a player, if it was decreased by Minecraft or other mods. But the resulting value cannot be higher than the standard target distance.
*/
public static class Visibility extends PlayerEvent
{
private double visibilityModifier = 1D;
public Visibility(EntityPlayer player)
{
super(player);
}
/**
* @param mod Is multiplied with the current modifier
*/
public void modifyVisibility(double mod)
{
visibilityModifier *= mod;
}
/**
* @return The current modifier
*/
public double getVisibilityModifier()
{
return visibilityModifier;
}
}
}