mirror of
https://github.com/PaperMC/Paper.git
synced 2025-07-25 17:22:02 -07:00
Entity Activation Range
This feature gives 3 new configurable ranges that if an entity of the matching type is outside of this radius of any player, will tick at 5% of its normal rate. This will drastically cut down on tick timings for entities that are not in range of a user to actually be "used". This change can have dramatic impact on gameplay if configured too low. Balance according to your servers desired gameplay. By: Aikar <aikar@aikar.co>
This commit is contained in:
@@ -79,7 +79,7 @@
|
||||
+ // CraftBukkit start
|
||||
+ public final LevelStorageSource.LevelStorageAccess convertable;
|
||||
+ public final UUID uuid;
|
||||
+
|
||||
|
||||
+ public LevelChunk getChunkIfLoaded(int x, int z) {
|
||||
+ return this.chunkSource.getChunk(x, z, false);
|
||||
+ }
|
||||
@@ -103,7 +103,7 @@
|
||||
+ ChunkGenerator chunkgenerator = worlddimension.generator();
|
||||
+ // CraftBukkit start
|
||||
+ this.serverLevelData.setWorld(this);
|
||||
|
||||
+
|
||||
+ if (biomeProvider != null) {
|
||||
+ BiomeSource worldChunkManager = new CustomWorldChunkManager(this.getWorld(), biomeProvider, this.server.registryAccess().lookupOrThrow(Registries.BIOME));
|
||||
+ if (chunkgenerator instanceof NoiseBasedChunkGenerator cga) {
|
||||
@@ -230,7 +230,7 @@
|
||||
|
||||
if (flag1) {
|
||||
this.resetEmptyTime();
|
||||
@@ -353,12 +413,14 @@
|
||||
@@ -353,12 +413,15 @@
|
||||
|
||||
if (flag1 || this.emptyTime++ < 300) {
|
||||
gameprofilerfiller.push("entities");
|
||||
@@ -241,11 +241,12 @@
|
||||
gameprofilerfiller.pop();
|
||||
}
|
||||
|
||||
+ org.spigotmc.ActivationRange.activateEntities(this); // Spigot
|
||||
+ this.timings.entityTick.startTiming(); // Spigot
|
||||
this.entityTickList.forEach((entity) -> {
|
||||
if (!entity.isRemoved()) {
|
||||
if (!tickratemanager.isEntityFrozen(entity)) {
|
||||
@@ -383,6 +445,8 @@
|
||||
@@ -383,6 +446,8 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -254,7 +255,7 @@
|
||||
gameprofilerfiller.pop();
|
||||
this.tickBlockEntities();
|
||||
}
|
||||
@@ -429,7 +493,7 @@
|
||||
@@ -429,7 +494,7 @@
|
||||
|
||||
private void wakeUpAllPlayers() {
|
||||
this.sleepStatus.removeAllSleepers();
|
||||
@@ -263,7 +264,7 @@
|
||||
entityplayer.stopSleepInBed(false, false);
|
||||
});
|
||||
}
|
||||
@@ -456,7 +520,7 @@
|
||||
@@ -456,7 +521,7 @@
|
||||
entityhorseskeleton.setTrap(true);
|
||||
entityhorseskeleton.setAge(0);
|
||||
entityhorseskeleton.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
|
||||
@@ -272,7 +273,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,7 +529,7 @@
|
||||
@@ -465,7 +530,7 @@
|
||||
if (entitylightning != null) {
|
||||
entitylightning.moveTo(Vec3.atBottomCenterOf(blockposition));
|
||||
entitylightning.setVisualOnly(flag1);
|
||||
@@ -281,7 +282,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -521,7 +585,7 @@
|
||||
@@ -521,7 +586,7 @@
|
||||
Biome biomebase = (Biome) this.getBiome(blockposition1).value();
|
||||
|
||||
if (biomebase.shouldFreeze(this, blockposition2)) {
|
||||
@@ -290,7 +291,7 @@
|
||||
}
|
||||
|
||||
if (this.isRaining()) {
|
||||
@@ -537,10 +601,10 @@
|
||||
@@ -537,10 +602,10 @@
|
||||
BlockState iblockdata1 = (BlockState) iblockdata.setValue(SnowLayerBlock.LAYERS, j + 1);
|
||||
|
||||
Block.pushEntitiesUp(iblockdata, iblockdata1, this, blockposition1);
|
||||
@@ -303,7 +304,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,33 +765,67 @@
|
||||
@@ -701,33 +766,67 @@
|
||||
this.rainLevel = Mth.clamp(this.rainLevel, 0.0F, 1.0F);
|
||||
}
|
||||
|
||||
@@ -379,15 +380,22 @@
|
||||
}
|
||||
|
||||
public void resetEmptyTime() {
|
||||
@@ -754,6 +852,7 @@
|
||||
@@ -754,6 +853,14 @@
|
||||
}
|
||||
|
||||
public void tickNonPassenger(Entity entity) {
|
||||
+ // Spigot start
|
||||
+ if (!org.spigotmc.ActivationRange.checkIfActive(entity)) {
|
||||
+ entity.tickCount++;
|
||||
+ entity.inactiveTick();
|
||||
+ return;
|
||||
+ }
|
||||
+ // Spigot end
|
||||
+ entity.tickTimer.startTiming(); // Spigot
|
||||
entity.setOldPosAndRot();
|
||||
ProfilerFiller gameprofilerfiller = Profiler.get();
|
||||
|
||||
@@ -763,6 +862,7 @@
|
||||
@@ -763,6 +870,7 @@
|
||||
});
|
||||
gameprofilerfiller.incrementCounter("tickNonPassenger");
|
||||
entity.tick();
|
||||
@@ -395,7 +403,7 @@
|
||||
gameprofilerfiller.pop();
|
||||
Iterator iterator = entity.getPassengers().iterator();
|
||||
|
||||
@@ -771,6 +871,7 @@
|
||||
@@ -771,6 +879,7 @@
|
||||
|
||||
this.tickPassenger(entity, entity1);
|
||||
}
|
||||
@@ -403,7 +411,7 @@
|
||||
|
||||
}
|
||||
|
||||
@@ -786,6 +887,7 @@
|
||||
@@ -786,6 +895,7 @@
|
||||
});
|
||||
gameprofilerfiller.incrementCounter("tickPassenger");
|
||||
passenger.rideTick();
|
||||
@@ -411,7 +419,7 @@
|
||||
gameprofilerfiller.pop();
|
||||
Iterator iterator = passenger.getPassengers().iterator();
|
||||
|
||||
@@ -810,6 +912,7 @@
|
||||
@@ -810,6 +920,7 @@
|
||||
ServerChunkCache chunkproviderserver = this.getChunkSource();
|
||||
|
||||
if (!savingDisabled) {
|
||||
@@ -419,7 +427,7 @@
|
||||
if (progressListener != null) {
|
||||
progressListener.progressStartNoAbort(Component.translatable("menu.savingLevel"));
|
||||
}
|
||||
@@ -827,11 +930,19 @@
|
||||
@@ -827,11 +938,19 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -440,7 +448,7 @@
|
||||
}
|
||||
|
||||
DimensionDataStorage worldpersistentdata = this.getChunkSource().getDataStorage();
|
||||
@@ -903,18 +1014,40 @@
|
||||
@@ -903,18 +1022,40 @@
|
||||
|
||||
@Override
|
||||
public boolean addFreshEntity(Entity entity) {
|
||||
@@ -484,7 +492,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -939,24 +1072,38 @@
|
||||
@@ -939,24 +1080,38 @@
|
||||
this.entityManager.addNewEntity(player);
|
||||
}
|
||||
|
||||
@@ -527,7 +535,7 @@
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -967,13 +1114,35 @@
|
||||
@@ -967,13 +1122,35 @@
|
||||
}
|
||||
|
||||
public void removePlayerImmediately(ServerPlayer player, Entity.RemovalReason reason) {
|
||||
@@ -564,7 +572,7 @@
|
||||
while (iterator.hasNext()) {
|
||||
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
||||
|
||||
@@ -982,6 +1151,12 @@
|
||||
@@ -982,6 +1159,12 @@
|
||||
double d1 = (double) pos.getY() - entityplayer.getY();
|
||||
double d2 = (double) pos.getZ() - entityplayer.getZ();
|
||||
|
||||
@@ -577,7 +585,7 @@
|
||||
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
|
||||
entityplayer.connection.send(new ClientboundBlockDestructionPacket(entityId, pos, progress));
|
||||
}
|
||||
@@ -1060,7 +1235,18 @@
|
||||
@@ -1060,7 +1243,18 @@
|
||||
Iterator iterator = this.navigatingMobs.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
@@ -597,7 +605,7 @@
|
||||
PathNavigation navigationabstract = entityinsentient.getNavigation();
|
||||
|
||||
if (navigationabstract.shouldRecomputePath(pos)) {
|
||||
@@ -1126,9 +1312,15 @@
|
||||
@@ -1126,9 +1320,15 @@
|
||||
|
||||
@Override
|
||||
public void explode(@Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Level.ExplosionInteraction explosionSourceType, ParticleOptions smallParticle, ParticleOptions largeParticle, Holder<SoundEvent> soundEvent) {
|
||||
@@ -614,7 +622,7 @@
|
||||
case NONE:
|
||||
explosion_effect = Explosion.BlockInteraction.KEEP;
|
||||
break;
|
||||
@@ -1144,16 +1336,26 @@
|
||||
@@ -1144,16 +1344,26 @@
|
||||
case TRIGGER:
|
||||
explosion_effect = Explosion.BlockInteraction.TRIGGER_BLOCK;
|
||||
break;
|
||||
@@ -644,7 +652,7 @@
|
||||
Iterator iterator = this.players.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
@@ -1162,10 +1364,11 @@
|
||||
@@ -1162,10 +1372,11 @@
|
||||
if (entityplayer.distanceToSqr(vec3d) < 4096.0D) {
|
||||
Optional<Vec3> optional = Optional.ofNullable((Vec3) serverexplosion.getHitPlayers().get(entityplayer));
|
||||
|
||||
@@ -657,7 +665,7 @@
|
||||
}
|
||||
|
||||
private Explosion.BlockInteraction getDestroyType(GameRules.Key<GameRules.BooleanValue> decayRule) {
|
||||
@@ -1226,17 +1429,24 @@
|
||||
@@ -1226,17 +1437,24 @@
|
||||
}
|
||||
|
||||
public <T extends ParticleOptions> int sendParticles(T parameters, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double speed) {
|
||||
@@ -685,7 +693,7 @@
|
||||
++j;
|
||||
}
|
||||
}
|
||||
@@ -1292,7 +1502,7 @@
|
||||
@@ -1292,7 +1510,7 @@
|
||||
|
||||
@Nullable
|
||||
public BlockPos findNearestMapStructure(TagKey<Structure> structureTag, BlockPos pos, int radius, boolean skipReferencedStructures) {
|
||||
@@ -694,7 +702,7 @@
|
||||
return null;
|
||||
} else {
|
||||
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().lookupOrThrow(Registries.STRUCTURE).get(structureTag);
|
||||
@@ -1334,11 +1544,22 @@
|
||||
@@ -1334,11 +1552,22 @@
|
||||
@Nullable
|
||||
@Override
|
||||
public MapItemSavedData getMapData(MapId id) {
|
||||
@@ -718,7 +726,7 @@
|
||||
this.getServer().overworld().getDataStorage().set(id.key(), state);
|
||||
}
|
||||
|
||||
@@ -1649,6 +1870,11 @@
|
||||
@@ -1649,6 +1878,11 @@
|
||||
@Override
|
||||
public void blockUpdated(BlockPos pos, Block block) {
|
||||
if (!this.isDebug()) {
|
||||
@@ -730,7 +738,7 @@
|
||||
this.updateNeighborsAt(pos, block);
|
||||
}
|
||||
|
||||
@@ -1668,12 +1894,12 @@
|
||||
@@ -1668,12 +1902,12 @@
|
||||
}
|
||||
|
||||
public boolean isFlat() {
|
||||
@@ -745,7 +753,7 @@
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -1696,7 +1922,7 @@
|
||||
@@ -1696,7 +1930,7 @@
|
||||
private static <T> String getTypeCount(Iterable<T> items, Function<T, String> classifier) {
|
||||
try {
|
||||
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
|
||||
@@ -754,7 +762,7 @@
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
T t0 = iterator.next();
|
||||
@@ -1705,7 +1931,7 @@
|
||||
@@ -1705,7 +1939,7 @@
|
||||
object2intopenhashmap.addTo(s, 1);
|
||||
}
|
||||
|
||||
@@ -763,7 +771,7 @@
|
||||
String s1 = (String) entry.getKey();
|
||||
|
||||
return s1 + ":" + entry.getIntValue();
|
||||
@@ -1717,6 +1943,7 @@
|
||||
@@ -1717,6 +1951,7 @@
|
||||
|
||||
@Override
|
||||
public LevelEntityGetter<Entity> getEntities() {
|
||||
@@ -771,7 +779,7 @@
|
||||
return this.entityManager.getEntityGetter();
|
||||
}
|
||||
|
||||
@@ -1836,6 +2063,7 @@
|
||||
@@ -1836,6 +2071,7 @@
|
||||
}
|
||||
|
||||
public void onTrackingStart(Entity entity) {
|
||||
@@ -779,7 +787,7 @@
|
||||
ServerLevel.this.getChunkSource().addEntity(entity);
|
||||
if (entity instanceof ServerPlayer entityplayer) {
|
||||
ServerLevel.this.players.add(entityplayer);
|
||||
@@ -1864,9 +2092,12 @@
|
||||
@@ -1864,9 +2100,12 @@
|
||||
}
|
||||
|
||||
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
|
||||
@@ -792,7 +800,7 @@
|
||||
ServerLevel.this.getChunkSource().removeEntity(entity);
|
||||
if (entity instanceof ServerPlayer entityplayer) {
|
||||
ServerLevel.this.players.remove(entityplayer);
|
||||
@@ -1895,6 +2126,14 @@
|
||||
@@ -1895,6 +2134,14 @@
|
||||
}
|
||||
|
||||
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);
|
||||
|
Reference in New Issue
Block a user