forked from LeavesMC/Lumina
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): add optimize from Gale
- Loading branch information
1 parent
94c41d1
commit 6460398
Showing
14 changed files
with
1,515 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
patches/server/0023-Gale-Variable-entity-wake-up-duration.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: MrHua269 <novau233@163.com> | ||
Date: Wed, 7 Feb 2024 06:00:22 +0000 | ||
Subject: [PATCH] Gale Variable entity wake-up duration | ||
|
||
|
||
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java | ||
index 483b59ec89d612f8ea09b7241ccce605d7c5826d..8f94b0a008326148811339082515f148a7b8eaca 100644 | ||
--- a/src/main/java/org/spigotmc/ActivationRange.java | ||
+++ b/src/main/java/org/spigotmc/ActivationRange.java | ||
@@ -75,28 +75,41 @@ public class ActivationRange | ||
if (entity.activationType == ActivationType.VILLAGER) { | ||
if (inactiveFor > config.wakeUpInactiveVillagersEvery && worldData.wakeupInactiveRemainingVillagers > 0) { // Folia - threaded regions | ||
worldData.wakeupInactiveRemainingVillagers--; // Folia - threaded regions | ||
- return config.wakeUpInactiveVillagersFor; | ||
+ return getWakeUpDurationWithVariance(entity, config.wakeUpInactiveVillagersFor); // Gale - variable entity wake-up duration | ||
} | ||
} else if (entity.activationType == ActivationType.ANIMAL) { | ||
if (inactiveFor > config.wakeUpInactiveAnimalsEvery && worldData.wakeupInactiveRemainingAnimals > 0) { // Folia - threaded regions | ||
worldData.wakeupInactiveRemainingAnimals--; // Folia - threaded regions | ||
- return config.wakeUpInactiveAnimalsFor; | ||
+ return getWakeUpDurationWithVariance(entity, config.wakeUpInactiveAnimalsFor); // Gale - variable entity wake-up duration | ||
} | ||
} else if (entity.activationType == ActivationType.FLYING_MONSTER) { | ||
if (inactiveFor > config.wakeUpInactiveFlyingEvery && worldData.wakeupInactiveRemainingFlying > 0) { // Folia - threaded regions | ||
worldData.wakeupInactiveRemainingFlying--; // Folia - threaded regions | ||
- return config.wakeUpInactiveFlyingFor; | ||
+ return getWakeUpDurationWithVariance(entity, config.wakeUpInactiveFlyingFor); // Gale - variable entity wake-up duration | ||
} | ||
} else if (entity.activationType == ActivationType.MONSTER || entity.activationType == ActivationType.RAIDER) { | ||
if (inactiveFor > config.wakeUpInactiveMonstersEvery && worldData.wakeupInactiveRemainingMonsters > 0) { // Folia - threaded regions | ||
worldData.wakeupInactiveRemainingMonsters--; // Folia - threaded regions | ||
- return config.wakeUpInactiveMonstersFor; | ||
+ return getWakeUpDurationWithVariance(entity, config.wakeUpInactiveMonstersFor); // Gale - variable entity wake-up duration | ||
} | ||
} | ||
return -1; | ||
} | ||
// Paper end | ||
|
||
+ // Gale start - variable entity wake-up duration | ||
+ private static final java.util.concurrent.ThreadLocalRandom wakeUpDurationRandom = java.util.concurrent.ThreadLocalRandom.current(); | ||
+ | ||
+ private static int getWakeUpDurationWithVariance(Entity entity, int wakeUpDuration) { | ||
+ double deviation = org.leavesmc.lumina.config.modules.optimizations.GaleVariableEntityWakeupConfig.entityWakeUpDurationRatioStandardDeviation; | ||
+ if (deviation <= 0) { | ||
+ return wakeUpDuration; | ||
+ } | ||
+ return (int) Math.min(Integer.MAX_VALUE, Math.max(1, Math.round(wakeUpDuration * wakeUpDurationRandom.nextGaussian(1, deviation)))); | ||
+ } | ||
+ // Gale end - variable entity wake-up duration | ||
+ | ||
+ | ||
// Folia - threaded regions - replaced by local variable | ||
|
||
/** |
78 changes: 78 additions & 0 deletions
78
patches/server/0024-Gale-Don-t-load-chunks-to-activate-climbing-entities.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: MrHua269 <novau233@163.com> | ||
Date: Wed, 7 Feb 2024 06:03:02 +0000 | ||
Subject: [PATCH] Gale Don't load chunks to activate climbing entities | ||
|
||
|
||
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java | ||
index 73f9a8f6bb26339f6dbaad830d406e114aa49607..fee6ad72811e78a01a5a5eca9c144bff4f7b80e5 100644 | ||
--- a/src/main/java/net/minecraft/world/entity/Entity.java | ||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java | ||
@@ -5415,6 +5415,16 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S | ||
return this.feetBlockState; | ||
} | ||
|
||
+ // Gale start - don't load chunks to activate climbing entities | ||
+ public @Nullable BlockState getFeetBlockStateIfLoaded() { | ||
+ if (this.feetBlockState == null) { | ||
+ this.feetBlockState = this.level.getBlockStateIfLoaded(this.blockPosition()); | ||
+ } | ||
+ | ||
+ return this.feetBlockState; | ||
+ } | ||
+ // Gale end - don't load chunks to activate climbing entities | ||
+ | ||
public ChunkPos chunkPosition() { | ||
return this.chunkPosition; | ||
} | ||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java | ||
index 632b17411bdc06c15011174a5fddad129b49caa9..e9cd0c25eb6aa112fb2b87dd67aab5f462ed0eee 100644 | ||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java | ||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java | ||
@@ -2062,19 +2062,43 @@ public abstract class LivingEntity extends Entity implements Attackable { | ||
|
||
public boolean onClimableCached() { | ||
if (!this.blockPosition().equals(this.lastClimbingPosition)) { | ||
- this.cachedOnClimable = this.onClimbable(); | ||
- this.lastClimbingPosition = this.blockPosition(); | ||
+ // Gale start - don't load chunks to activate climbing entities | ||
+ Boolean onClimbableIfLoaded = this.onClimbable(org.leavesmc.lumina.config.modules.optimizations.LoadChunksToActiveClimbingEntitiesConfig.allow); | ||
+ if (onClimbableIfLoaded != null) { | ||
+ this.cachedOnClimable = onClimbableIfLoaded; | ||
+ this.lastClimbingPosition = this.blockPosition(); | ||
+ } else { | ||
+ this.cachedOnClimable = false; | ||
+ this.lastClimbingPosition = null; | ||
+ } | ||
+ // Gale end - don't load chunks to activate climbing entities | ||
} | ||
return this.cachedOnClimable; | ||
} | ||
// Pufferfish end | ||
|
||
public boolean onClimbable() { | ||
+ // Gale start - don't load chunks to activate climbing entities | ||
+ return onClimbable(true); | ||
+ } | ||
+ | ||
+ public Boolean onClimbable(boolean loadChunk) { | ||
+ // Gale end - don't load chunks to activate climbing entities | ||
if (this.isSpectator()) { | ||
return false; | ||
} else { | ||
BlockPos blockposition = this.blockPosition(); | ||
- BlockState iblockdata = this.getFeetBlockState(); | ||
+ // Gale start - don't load chunks to activate climbing entities | ||
+ BlockState iblockdata; | ||
+ if (loadChunk) { | ||
+ iblockdata = this.getFeetBlockState(); | ||
+ } else { | ||
+ iblockdata = this.getFeetBlockStateIfLoaded(); | ||
+ if (iblockdata == null) { | ||
+ return null; | ||
+ } | ||
+ } | ||
+ // Gale end - don't load chunks to activate climbing entities | ||
|
||
if (iblockdata.is(BlockTags.CLIMBABLE)) { | ||
this.lastClimbablePos = Optional.of(blockposition); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: M2ke4U <79621885+MrHua269@users.noreply.github.com> | ||
Date: Sun, 26 Nov 2023 17:21:44 +0800 | ||
Subject: [PATCH] Gale Optimize sun burn tick | ||
|
||
|
||
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java | ||
index fee6ad72811e78a01a5a5eca9c144bff4f7b80e5..7be3516ec4b6a3a285661b78667b3a2ada3bfbe4 100644 | ||
--- a/src/main/java/net/minecraft/world/entity/Entity.java | ||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java | ||
@@ -308,7 +308,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S | ||
public double xo; | ||
public double yo; | ||
public double zo; | ||
- private Vec3 position; | ||
+ public Vec3 position; // Gale - JettPack - optimize sun burn tick - private -> public | ||
public BlockPos blockPosition; // Pufferfish - private->public | ||
private ChunkPos chunkPosition; | ||
private Vec3 deltaMovement; | ||
@@ -2036,9 +2036,17 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S | ||
/** @deprecated */ | ||
@Deprecated | ||
public float getLightLevelDependentMagicValue() { | ||
- return this.level().hasChunkAt(this.getBlockX(), this.getBlockZ()) ? this.level().getLightLevelDependentMagicValue(BlockPos.containing(this.getX(), this.getEyeY(), this.getZ())) : 0.0F; | ||
+ return this.getLightLevelDependentMagicValue(BlockPos.containing(this.getX(), this.getEyeY(), this.getZ())); // Gale - JettPack - optimize sun burn tick - allow passing BlockPos to getLightLevelDependentMagicValue | ||
} | ||
|
||
+ // Gale start - JettPack - optimize sun burn tick - allow passing BlockPos to getLightLevelDependentMagicValue | ||
+ /** @deprecated */ | ||
+ @Deprecated | ||
+ public float getLightLevelDependentMagicValue(BlockPos pos) { | ||
+ return this.level().hasChunkAt(this.getBlockX(), this.getBlockZ()) ? this.level.getLightLevelDependentMagicValue(pos) : 0.0F; | ||
+ } | ||
+ // Gale end - JettPack - optimize sun burn tick - allow passing BlockPos to getLightLevelDependentMagicValue | ||
+ | ||
public void absMoveTo(double x, double y, double z, float yaw, float pitch) { | ||
this.absMoveTo(x, y, z); | ||
this.setYRot(yaw % 360.0F); | ||
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java | ||
index 8680718047c20195d31b2b7b582de063fb55753f..88ab17e273e416006185e024d7f5e9bc381be969 100644 | ||
--- a/src/main/java/net/minecraft/world/entity/Mob.java | ||
+++ b/src/main/java/net/minecraft/world/entity/Mob.java | ||
@@ -1749,13 +1749,29 @@ public abstract class Mob extends LivingEntity implements Targeting { | ||
|
||
} | ||
|
||
+ // Gale start - JettPack - optimize sun burn tick - cache eye blockpos | ||
+ private BlockPos cached_eye_blockpos; | ||
+ private int cached_position_hashcode; | ||
+ // Gale end - JettPack - optimize sun burn tick - cache eye blockpos | ||
+ | ||
public boolean isSunBurnTick() { | ||
if (this.level().isDay() && !this.level().isClientSide) { | ||
- float f = this.getLightLevelDependentMagicValue(); | ||
- BlockPos blockposition = BlockPos.containing(this.getX(), this.getEyeY(), this.getZ()); | ||
+ // Gale start - JettPack - optimize sun burn tick - optimizations and cache eye blockpos | ||
+ int positionHashCode = this.position.hashCode(); | ||
+ if (this.cached_position_hashcode != positionHashCode) { | ||
+ this.cached_eye_blockpos = BlockPos.containing(this.getX(), this.getEyeY(), this.getZ()); | ||
+ this.cached_position_hashcode = positionHashCode; | ||
+ } | ||
+ | ||
+ float f = this.getLightLevelDependentMagicValue(cached_eye_blockpos); // Pass BlockPos to getBrightness | ||
+ | ||
+ // Check brightness first | ||
+ if (f <= 0.5F) return false; | ||
+ if (this.random.nextFloat() * 30.0F >= (f - 0.4F) * 2.0F) return false; | ||
+ // Gale end - JettPack - optimize sun burn tick - optimizations and cache eye blockpos | ||
boolean flag = this.isInWaterRainOrBubble() || this.isInPowderSnow || this.wasInPowderSnow; | ||
|
||
- if (f > 0.5F && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && !flag && this.level().canSeeSky(blockposition)) { | ||
+ if (!flag && this.level().canSeeSky(this.cached_eye_blockpos)) { // Gale - JettPack - optimize sun burn tick - optimizations and cache eye blockpos | ||
return true; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
patches/server/0026-Gale-Check-frozen-ticks-before-landing-block.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: MrHua269 <novau233@163.com> | ||
Date: Sun, 28 Jan 2024 09:30:22 +0000 | ||
Subject: [PATCH] Gale Check frozen ticks before landing block | ||
|
||
|
||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java | ||
index e9cd0c25eb6aa112fb2b87dd67aab5f462ed0eee..3f86b078cc379443b76b68e8dc90da5c3f6fb0eb 100644 | ||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java | ||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java | ||
@@ -597,11 +597,10 @@ public abstract class LivingEntity extends Entity implements Attackable { | ||
} | ||
|
||
protected void tryAddFrost() { | ||
- if (!this.getBlockStateOnLegacy().isAir()) { | ||
int i = this.getTicksFrozen(); | ||
|
||
if (i > 0) { | ||
- AttributeInstance attributemodifiable = this.getAttribute(Attributes.MOVEMENT_SPEED); | ||
+ AttributeInstance attributemodifiable = this.getBlockStateOnLegacy().isAir() ? null : this.getAttribute(Attributes.MOVEMENT_SPEED); // Gale - Lithium - check frozen ticks before landing block | ||
|
||
if (attributemodifiable == null) { | ||
return; | ||
@@ -611,7 +610,6 @@ public abstract class LivingEntity extends Entity implements Attackable { | ||
|
||
attributemodifiable.addTransientModifier(new AttributeModifier(LivingEntity.SPEED_MODIFIER_POWDER_SNOW_UUID, "Powder snow slow", (double) f, AttributeModifier.Operation.ADDITION)); | ||
} | ||
- } | ||
|
||
} | ||
|
19 changes: 19 additions & 0 deletions
19
patches/server/0027-Gale-Don-t-trigger-lootable-refresh-for-non-player-i.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: MrHua269 <novau233@163.com> | ||
Date: Sun, 28 Jan 2024 09:31:27 +0000 | ||
Subject: [PATCH] Gale Don't trigger lootable refresh for non-player | ||
interaction | ||
|
||
|
||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java | ||
index a5cd70b6ada2b44f64db0985483ee5eadc67003f..e49be65c2d379027c2821c0db7f151bc3cd20a4b 100644 | ||
--- a/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java | ||
+++ b/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java | ||
@@ -68,6 +68,7 @@ public abstract class RandomizableContainerBlockEntity extends BaseContainerBloc | ||
|
||
@Override | ||
public void unpackLootTable(@org.jetbrains.annotations.Nullable final Player player) { | ||
+ if (player == null) return; // Gale - EMC - don't trigger lootable refresh for non-player interaction | ||
// Copied from super with changes, always check the original method | ||
net.minecraft.world.level.Level level = this.getLevel(); | ||
BlockPos blockPos = this.getBlockPos(); |
Oops, something went wrong.