remove more imports and cleanup
This commit is contained in:
@@ -29,11 +29,12 @@ import net.minecraft.world.entity.raid.Raider;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
|
||||
public class ActivationRange
|
||||
{
|
||||
public final class ActivationRange {
|
||||
|
||||
public enum ActivationType
|
||||
{
|
||||
private ActivationRange() {
|
||||
}
|
||||
|
||||
public enum ActivationType {
|
||||
WATER, // Paper
|
||||
FLYING_MONSTER, // Paper
|
||||
VILLAGER, // Paper
|
||||
@@ -42,10 +43,10 @@ public class ActivationRange
|
||||
RAIDER,
|
||||
MISC;
|
||||
|
||||
AABB boundingBox = new AABB( 0, 0, 0, 0, 0, 0 );
|
||||
AABB boundingBox = new AABB(0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
static AABB maxBB = new AABB( 0, 0, 0, 0, 0, 0 );
|
||||
static AABB maxBB = new AABB(0, 0, 0, 0, 0, 0);
|
||||
|
||||
/**
|
||||
* Initializes an entities type on construction to specify what group this
|
||||
@@ -54,19 +55,14 @@ public class ActivationRange
|
||||
* @param entity
|
||||
* @return group id
|
||||
*/
|
||||
public static ActivationType initializeEntityActivationType(Entity entity)
|
||||
{
|
||||
if ( entity instanceof Raider )
|
||||
{
|
||||
public static ActivationType initializeEntityActivationType(final Entity entity) {
|
||||
if (entity instanceof Raider) {
|
||||
return ActivationType.RAIDER;
|
||||
} else if ( entity instanceof Monster || entity instanceof Slime )
|
||||
{
|
||||
} else if (entity instanceof Monster || entity instanceof Slime) {
|
||||
return ActivationType.MONSTER;
|
||||
} else if ( entity instanceof PathfinderMob || entity instanceof AmbientCreature )
|
||||
{
|
||||
} else if (entity instanceof PathfinderMob || entity instanceof AmbientCreature) {
|
||||
return ActivationType.ANIMAL;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
return ActivationType.MISC;
|
||||
}
|
||||
}
|
||||
@@ -78,31 +74,25 @@ public class ActivationRange
|
||||
* @param config
|
||||
* @return boolean If it should always tick.
|
||||
*/
|
||||
public static boolean initializeEntityActivationState(Entity entity, SpigotWorldConfig config)
|
||||
{
|
||||
if ( ( entity.activationType == ActivationType.MISC && config.miscActivationRange == 0 )
|
||||
|| ( entity.activationType == ActivationType.RAIDER && config.raiderActivationRange == 0 )
|
||||
|| ( entity.activationType == ActivationType.ANIMAL && config.animalActivationRange == 0 )
|
||||
|| ( entity.activationType == ActivationType.MONSTER && config.monsterActivationRange == 0 )
|
||||
|| entity instanceof Player
|
||||
|| entity instanceof ThrowableProjectile
|
||||
|| entity instanceof EnderDragon
|
||||
|| entity instanceof EnderDragonPart
|
||||
|| entity instanceof WitherBoss
|
||||
|| entity instanceof AbstractHurtingProjectile
|
||||
|| entity instanceof LightningBolt
|
||||
|| entity instanceof PrimedTnt
|
||||
|| entity instanceof net.minecraft.world.entity.item.FallingBlockEntity // Paper - Always tick falling blocks
|
||||
|| entity instanceof net.minecraft.world.entity.vehicle.AbstractMinecart // Paper
|
||||
|| entity instanceof net.minecraft.world.entity.vehicle.AbstractBoat // Paper
|
||||
|| entity instanceof EndCrystal
|
||||
|| entity instanceof FireworkRocketEntity
|
||||
|| entity instanceof ThrownTrident )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
public static boolean initializeEntityActivationState(final Entity entity, final SpigotWorldConfig config) {
|
||||
return (entity.activationType == ActivationType.MISC && config.miscActivationRange == 0)
|
||||
|| (entity.activationType == ActivationType.RAIDER && config.raiderActivationRange == 0)
|
||||
|| (entity.activationType == ActivationType.ANIMAL && config.animalActivationRange == 0)
|
||||
|| (entity.activationType == ActivationType.MONSTER && config.monsterActivationRange == 0)
|
||||
|| entity instanceof Player
|
||||
|| entity instanceof ThrowableProjectile
|
||||
|| entity instanceof EnderDragon
|
||||
|| entity instanceof EnderDragonPart
|
||||
|| entity instanceof WitherBoss
|
||||
|| entity instanceof AbstractHurtingProjectile
|
||||
|| entity instanceof LightningBolt
|
||||
|| entity instanceof PrimedTnt
|
||||
|| entity instanceof net.minecraft.world.entity.item.FallingBlockEntity // Paper - Always tick falling blocks
|
||||
|| entity instanceof net.minecraft.world.entity.vehicle.AbstractMinecart // Paper
|
||||
|| entity instanceof net.minecraft.world.entity.vehicle.AbstractBoat // Paper
|
||||
|| entity instanceof EndCrystal
|
||||
|| entity instanceof FireworkRocketEntity
|
||||
|| entity instanceof ThrownTrident;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,31 +101,28 @@ public class ActivationRange
|
||||
*
|
||||
* @param world
|
||||
*/
|
||||
public static void activateEntities(Level world)
|
||||
{
|
||||
public static void activateEntities(final Level world) {
|
||||
final int miscActivationRange = world.spigotConfig.miscActivationRange;
|
||||
final int raiderActivationRange = world.spigotConfig.raiderActivationRange;
|
||||
final int animalActivationRange = world.spigotConfig.animalActivationRange;
|
||||
final int monsterActivationRange = world.spigotConfig.monsterActivationRange;
|
||||
|
||||
int maxRange = Math.max( monsterActivationRange, animalActivationRange );
|
||||
maxRange = Math.max( maxRange, raiderActivationRange );
|
||||
maxRange = Math.max( maxRange, miscActivationRange );
|
||||
maxRange = Math.min( ( world.spigotConfig.simulationDistance << 4 ) - 8, maxRange );
|
||||
int maxRange = Math.max(monsterActivationRange, animalActivationRange);
|
||||
maxRange = Math.max(maxRange, raiderActivationRange);
|
||||
maxRange = Math.max(maxRange, miscActivationRange);
|
||||
maxRange = Math.min((world.spigotConfig.simulationDistance << 4) - 8, maxRange);
|
||||
|
||||
for ( Player player : world.players() )
|
||||
{
|
||||
for (final Player player : world.players()) {
|
||||
player.activatedTick = MinecraftServer.currentTick;
|
||||
if ( world.spigotConfig.ignoreSpectatorActivation && player.isSpectator() )
|
||||
{
|
||||
if (world.spigotConfig.ignoreSpectatorActivation && player.isSpectator()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ActivationRange.maxBB = player.getBoundingBox().inflate( maxRange, 256, maxRange );
|
||||
ActivationType.MISC.boundingBox = player.getBoundingBox().inflate( miscActivationRange, 256, miscActivationRange );
|
||||
ActivationType.RAIDER.boundingBox = player.getBoundingBox().inflate( raiderActivationRange, 256, raiderActivationRange );
|
||||
ActivationType.ANIMAL.boundingBox = player.getBoundingBox().inflate( animalActivationRange, 256, animalActivationRange );
|
||||
ActivationType.MONSTER.boundingBox = player.getBoundingBox().inflate( monsterActivationRange, 256, monsterActivationRange );
|
||||
ActivationRange.maxBB = player.getBoundingBox().inflate(maxRange, 256, maxRange);
|
||||
ActivationType.MISC.boundingBox = player.getBoundingBox().inflate(miscActivationRange, 256, miscActivationRange);
|
||||
ActivationType.RAIDER.boundingBox = player.getBoundingBox().inflate(raiderActivationRange, 256, raiderActivationRange);
|
||||
ActivationType.ANIMAL.boundingBox = player.getBoundingBox().inflate(animalActivationRange, 256, animalActivationRange);
|
||||
ActivationType.MONSTER.boundingBox = player.getBoundingBox().inflate(monsterActivationRange, 256, monsterActivationRange);
|
||||
|
||||
world.getEntities().get(ActivationRange.maxBB, ActivationRange::activateEntity);
|
||||
}
|
||||
@@ -146,17 +133,13 @@ public class ActivationRange
|
||||
*
|
||||
* @param entity
|
||||
*/
|
||||
private static void activateEntity(Entity entity)
|
||||
{
|
||||
if ( MinecraftServer.currentTick > entity.activatedTick )
|
||||
{
|
||||
if ( entity.defaultActivationState )
|
||||
{
|
||||
private static void activateEntity(final Entity entity) {
|
||||
if (MinecraftServer.currentTick > entity.activatedTick) {
|
||||
if (entity.defaultActivationState) {
|
||||
entity.activatedTick = MinecraftServer.currentTick;
|
||||
return;
|
||||
}
|
||||
if ( entity.activationType.boundingBox.intersects( entity.getBoundingBox() ) )
|
||||
{
|
||||
if (entity.activationType.boundingBox.intersects(entity.getBoundingBox())) {
|
||||
entity.activatedTick = MinecraftServer.currentTick;
|
||||
}
|
||||
}
|
||||
@@ -169,60 +152,43 @@ public class ActivationRange
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkEntityImmunities(Entity entity)
|
||||
{
|
||||
public static boolean checkEntityImmunities(final Entity entity) {
|
||||
// quick checks.
|
||||
if ( entity.isInWater() || entity.getRemainingFireTicks() > 0 )
|
||||
{
|
||||
if (entity.isInWater() || entity.getRemainingFireTicks() > 0) {
|
||||
return true;
|
||||
}
|
||||
if ( !( entity instanceof AbstractArrow ) )
|
||||
{
|
||||
if ( !entity.onGround() || !entity.getPassengers().isEmpty() || entity.isPassenger() )
|
||||
{
|
||||
if (!(entity instanceof final AbstractArrow abstractArrow)) {
|
||||
if (!entity.onGround() || !entity.getPassengers().isEmpty() || entity.isPassenger()) {
|
||||
return true;
|
||||
}
|
||||
} else if ( !( (AbstractArrow) entity ).isInGround() )
|
||||
{
|
||||
} else if (!abstractArrow.isInGround()) {
|
||||
return true;
|
||||
}
|
||||
// special cases.
|
||||
if ( entity instanceof LivingEntity )
|
||||
{
|
||||
LivingEntity living = (LivingEntity) entity;
|
||||
if ( /*TODO: Missed mapping? living.attackTicks > 0 || */ living.hurtTime > 0 || living.activeEffects.size() > 0 )
|
||||
{
|
||||
if (entity instanceof final LivingEntity living) {
|
||||
if ( /*TODO: Missed mapping? living.attackTicks > 0 || */ living.hurtTime > 0 || !living.activeEffects.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if ( entity instanceof PathfinderMob && ( (PathfinderMob) entity ).getTarget() != null )
|
||||
{
|
||||
if (entity instanceof final PathfinderMob pathfinderMob && pathfinderMob.getTarget() != null) {
|
||||
return true;
|
||||
}
|
||||
if ( entity instanceof Villager && ( (Villager) entity ).canBreed() )
|
||||
{
|
||||
if (entity instanceof final Villager villager && villager.canBreed()) {
|
||||
return true;
|
||||
}
|
||||
if ( entity instanceof Animal )
|
||||
{
|
||||
Animal animal = (Animal) entity;
|
||||
if ( animal.isBaby() || animal.isInLove() )
|
||||
{
|
||||
if (entity instanceof final Animal animal) {
|
||||
if (animal.isBaby() || animal.isInLove()) {
|
||||
return true;
|
||||
}
|
||||
if ( entity instanceof Sheep && ( (Sheep) entity ).isSheared() )
|
||||
{
|
||||
if (entity instanceof final Sheep sheep && sheep.isSheared()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (entity instanceof Creeper && ((Creeper) entity).isIgnited()) { // isExplosive
|
||||
if (entity instanceof final Creeper creeper && creeper.isIgnited()) { // isExplosive
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// SPIGOT-6644: Otherwise the target refresh tick will be missed
|
||||
if (entity instanceof ExperienceOrb) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return entity instanceof ExperienceOrb;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,8 +197,7 @@ public class ActivationRange
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkIfActive(Entity entity)
|
||||
{
|
||||
public static boolean checkIfActive(final Entity entity) {
|
||||
// Never safe to skip fireworks or item gravity
|
||||
if (entity instanceof FireworkRocketEntity || (entity instanceof ItemEntity && (entity.tickCount + entity.getId()) % 4 == 0)) { // Paper - Needed for item gravity, see ItemEntity tick
|
||||
return true;
|
||||
@@ -241,13 +206,10 @@ public class ActivationRange
|
||||
boolean isActive = entity.activatedTick >= MinecraftServer.currentTick || entity.defaultActivationState;
|
||||
|
||||
// Should this entity tick?
|
||||
if ( !isActive )
|
||||
{
|
||||
if ( ( MinecraftServer.currentTick - entity.activatedTick - 1 ) % 20 == 0 )
|
||||
{
|
||||
if (!isActive) {
|
||||
if ((MinecraftServer.currentTick - entity.activatedTick - 1) % 20 == 0) {
|
||||
// Check immunities every 20 ticks.
|
||||
if ( ActivationRange.checkEntityImmunities( entity ) )
|
||||
{
|
||||
if (ActivationRange.checkEntityImmunities(entity)) {
|
||||
// Triggered some sort of immunity, give 20 full ticks before we check again.
|
||||
entity.activatedTick = MinecraftServer.currentTick + 20;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@ import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.entity.decoration.Painting;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
|
||||
public class TrackingRange
|
||||
{
|
||||
public final class TrackingRange {
|
||||
|
||||
private TrackingRange() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the range an entity should be 'tracked' by players and visible in
|
||||
@@ -19,17 +21,14 @@ public class TrackingRange
|
||||
* @param defaultRange Default range defined by Mojang
|
||||
* @return
|
||||
*/
|
||||
public static int getEntityTrackingRange(Entity entity, int defaultRange)
|
||||
{
|
||||
if ( defaultRange == 0 )
|
||||
{
|
||||
public static int getEntityTrackingRange(final Entity entity, final int defaultRange) {
|
||||
if (defaultRange == 0) {
|
||||
return defaultRange;
|
||||
}
|
||||
SpigotWorldConfig config = entity.level().spigotConfig;
|
||||
if ( entity instanceof ServerPlayer )
|
||||
{
|
||||
final SpigotWorldConfig config = entity.level().spigotConfig;
|
||||
if (entity instanceof ServerPlayer) {
|
||||
return config.playerTrackingRange;
|
||||
// Paper start - Simplify and set water mobs to animal tracking range
|
||||
// Paper start - Simplify and set water mobs to animal tracking range
|
||||
}
|
||||
switch (entity.activationType) {
|
||||
case RAIDER:
|
||||
@@ -42,16 +41,15 @@ public class TrackingRange
|
||||
return config.animalTrackingRange;
|
||||
case MISC:
|
||||
}
|
||||
if ( entity instanceof ItemFrame || entity instanceof Painting || entity instanceof ItemEntity || entity instanceof ExperienceOrb )
|
||||
if (entity instanceof ItemFrame || entity instanceof Painting || entity instanceof ItemEntity || entity instanceof ExperienceOrb) {
|
||||
// Paper end
|
||||
{
|
||||
return config.miscTrackingRange;
|
||||
} else if ( entity instanceof Display )
|
||||
{
|
||||
} else if (entity instanceof Display) {
|
||||
return config.displayTrackingRange;
|
||||
} else
|
||||
{
|
||||
if (entity instanceof net.minecraft.world.entity.boss.enderdragon.EnderDragon) return ((net.minecraft.server.level.ServerLevel)(entity.getCommandSenderWorld())).getChunkSource().chunkMap.serverViewDistance; // Paper - enderdragon is exempt
|
||||
} else {
|
||||
if (entity instanceof net.minecraft.world.entity.boss.enderdragon.EnderDragon) {
|
||||
return ((net.minecraft.server.level.ServerLevel) (entity.getCommandSenderWorld())).getChunkSource().chunkMap.serverViewDistance; // Paper - enderdragon is exempt
|
||||
}
|
||||
return config.otherTrackingRange;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user