mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Fix/Replace player visibility event (#7573)
This commit is contained in:
1 parent
75570079ae
commit
9017e24b40
4 files changed
+65
No files matched your search
@@ -147,6 +147,7 @@ import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDamageEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingFallEvent;
|
||||
@@ -394,6 +395,11 @@ public class ForgeHooks
|
||||
return event.getLootingLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 1.17 remove
|
||||
* Unused
|
||||
*/
|
||||
@Deprecated
|
||||
public static double getPlayerVisibilityDistance(PlayerEntity player, double xzDistance, double maxXZDistance)
|
||||
{
|
||||
PlayerEvent.Visibility event = new PlayerEvent.Visibility(player);
|
||||
@@ -402,6 +408,12 @@ public class ForgeHooks
|
||||
return value >= maxXZDistance ? maxXZDistance : value;
|
||||
}
|
||||
|
||||
public static double getEntityVisibilityMultiplier(LivingEntity entity, Entity lookingEntity, double originalMultiplier){
|
||||
LivingEvent.LivingVisibilityEvent event = new LivingEvent.LivingVisibilityEvent(entity, lookingEntity, originalMultiplier);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return Math.max(0,event.getVisibilityModifier());
|
||||
}
|
||||
|
||||
public static boolean isLivingOnLadder(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull LivingEntity entity)
|
||||
{
|
||||
boolean isSpectator = (entity instanceof PlayerEntity && ((PlayerEntity)entity).isSpectator());
|
||||
|
||||
@@ -19,12 +19,15 @@
|
||||
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* LivingEvent is fired whenever an event involving Living entities occurs.<br>
|
||||
* If a method utilizes this {@link net.minecraftforge.eventbus.api.Event} as its parameter, the method will
|
||||
@@ -84,4 +87,43 @@ public class LivingEvent extends EntityEvent
|
||||
{
|
||||
public LivingJumpEvent(LivingEntity e){ super(e); }
|
||||
}
|
||||
|
||||
public static class LivingVisibilityEvent extends LivingEvent
|
||||
{
|
||||
private double visibilityModifier;
|
||||
@Nullable
|
||||
private final Entity lookingEntity;
|
||||
|
||||
public LivingVisibilityEvent(LivingEntity livingEntity, @Nullable Entity lookingEntity, double originalMultiplier)
|
||||
{
|
||||
super(livingEntity);
|
||||
this.visibilityModifier = originalMultiplier;
|
||||
this.lookingEntity = lookingEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mod Is multiplied with the current modifier
|
||||
*/
|
||||
public void modifyVisibility(double mod)
|
||||
{
|
||||
visibilityModifier *= mod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current modifier
|
||||
*/
|
||||
public double getVisibilityModifier()
|
||||
{
|
||||
return visibilityModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The entity trying to see this LivingEntity, if available
|
||||
*/
|
||||
@Nullable
|
||||
public Entity getLookingEntity()
|
||||
{
|
||||
return lookingEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -361,10 +361,12 @@ public class PlayerEvent extends LivingEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 1.17 remove, unused
|
||||
* 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.
|
||||
*/
|
||||
@Deprecated
|
||||
public static class Visibility extends PlayerEvent
|
||||
{
|
||||
|
||||
|
||||
Reference in new issue
Block a user