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

This commit is contained in:
Max Becker authored and LexManos committed 2016-11-16 15:04:05 -08:00
1 parent c177219ff3
commit 0a5ef64d6e
3 files changed
+51 -1

No files matched your search

@@ -115,6 +115,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;
@@ -540,6 +541,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());
@@ -1163,7 +1172,7 @@ public class ForgeHooks
{
return MinecraftForge.EVENT_BUS.post(new ThrowableImpactEvent(throwable, ray));
}
public static boolean onCropsGrowPre(World worldIn, BlockPos pos, IBlockState state, boolean def)
{
BlockEvent ev = new BlockEvent.CropGrowEvent.Pre(worldIn,pos,state);
@@ -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;
}
}
}