9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-28 11:19:08 +00:00

All patches applied

This commit is contained in:
Samsuik
2025-01-17 01:30:44 +00:00
parent 7dbdd69077
commit ca83d33506
28 changed files with 2095 additions and 3 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,35 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Sat, 25 Nov 2023 21:14:45 +0000
Subject: [PATCH] Allow explosions to destroy lava
diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java
index 040596183eb6c61369e59112fa928e9c129adb34..ad44fb3a3ee0b6595564031f73fc61c459a8d951 100644
--- a/net/minecraft/world/level/ServerExplosion.java
+++ b/net/minecraft/world/level/ServerExplosion.java
@@ -407,6 +407,11 @@ public class ServerExplosion implements Explosion {
return Optional.of(ZERO_RESISTANCE);
}
// Sakura end - destroy water logged blocks
+ // Sakura start - allow explosions to destroy lava
+ if (blockState.is(Blocks.LAVA) && this.level.sakuraConfig().cannons.explosion.explodeLava) {
+ return Optional.of(ZERO_RESISTANCE);
+ }
+ // Sakura end - allow explosions to destroy lava
}
return this.damageCalculator.getBlockExplosionResistance(this, this.level, pos, blockState, fluidState);
diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java
index 5473b4006f7e0266ea11a7b05cef78a113c30d97..0a233c18fbad92c59b9c001574be3464f2be9d2c 100644
--- a/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/net/minecraft/world/level/block/state/BlockBehaviour.java
@@ -204,7 +204,7 @@ public abstract class BlockBehaviour implements FeatureElement {
state.getDrops(builder).forEach(stack -> dropConsumer.accept(stack, pos));
}
- level.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
+ level.setBlock(pos, Blocks.AIR.defaultBlockState(), level.sakuraConfig().cannons.explosion.explodeLava && state.is(Blocks.LAVA) ? 2 : 3); // Sakura - allow explosions to destroy lava; don't cause block updates when blowing up lava
block.wasExploded(level, pos, explosion);
}
}

View File

@@ -0,0 +1,66 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Sun, 26 Nov 2023 17:57:50 +0000
Subject: [PATCH] Collide with non-solid blocks
diff --git a/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java b/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java
index 47c8ed946cb2ad81a4469daf60dabc40c5e8beda..16b66b19157081c7717f73ee3dc9111662a31922 100644
--- a/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java
+++ b/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java
@@ -1908,6 +1908,7 @@ public final class CollisionUtil {
public static final int COLLISION_FLAG_CHECK_BORDER = 1 << 2;
public static final int COLLISION_FLAG_CHECK_ONLY = 1 << 3;
public static final int COLLISION_FLAG_ADD_TICKET = 1 << 4; // Sakura - load chunks on movement
+ public static final int COLLISION_FLAG_FULL_BLOCKS = 1 << 5; // Sakura - collide with non-solid blocks
public static boolean getCollisionsForBlocksOrWorldBorder(final Level world, final Entity entity, final AABB aabb,
final List<VoxelShape> intoVoxel, final List<AABB> intoAABB,
@@ -1960,6 +1961,7 @@ public final class CollisionUtil {
final boolean loadChunks = (collisionFlags & COLLISION_FLAG_LOAD_CHUNKS) != 0;
final boolean addTicket = (collisionFlags & COLLISION_FLAG_ADD_TICKET) != 0; // Sakura - load chunks on movement
+ final boolean fullBlocks = (collisionFlags & COLLISION_FLAG_FULL_BLOCKS) != 0; // Sakura - collide with non-solid blocks
final ChunkSource chunkSource = world.getChunkSource();
for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) {
@@ -1999,7 +2001,7 @@ public final class CollisionUtil {
continue;
}
- final boolean hasSpecial = ((BlockCountingChunkSection)section).moonrise$hasSpecialCollidingBlocks();
+ final boolean hasSpecial = !fullBlocks && ((BlockCountingChunkSection)section).moonrise$hasSpecialCollidingBlocks(); // Sakura - collide with non-solid blocks
final int sectionAdjust = !hasSpecial ? 1 : 0;
final PalettedContainer<BlockState> blocks = section.states;
@@ -2038,6 +2040,11 @@ public final class CollisionUtil {
if (useEntityCollisionShape) {
mutablePos.set(blockX, blockY, blockZ);
blockCollision = collisionShape.getCollisionShape(blockData, world, mutablePos);
+ // Sakura start - collide with non-solid blocks
+ // todo: move this logic above emptyCollisionShape and consider all blocks as a solid except scaffolding and liquids
+ } else if (fullBlocks && blockData.moonrise$getConstantContextCollisionShape() != null) {
+ blockCollision = net.minecraft.world.phys.shapes.Shapes.block();
+ // Sakura end - collide with non-solid blocks
} else if (blockCollision == null) {
mutablePos.set(blockX, blockY, blockZ);
blockCollision = blockData.getCollisionShape(world, mutablePos, collisionShape);
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index a6a47d9d0d8e475d936ce867cdbb8d597e71ff4e..7c3b536ee056cfd938f19a0a22b1d128f0fa2733 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -541,6 +541,14 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
flags |= ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_ADD_TICKET;
}
+ // Sakura start - collide with non-solid blocks
+ if (this.level().sakuraConfig().cannons.treatAllBlocksAsFullWhenMoving && (this.isPrimedTNT || this.isFallingBlock)) {
+ double horizontalMovementSqr = this.getDeltaMovement().horizontalDistanceSqr();
+ if (horizontalMovementSqr > Math.pow(this.level().sakuraConfig().cannons.treatAllBlocksAsFullWhenMovingFasterThan, 2.0)) {
+ flags |= ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_FULL_BLOCKS;
+ }
+ }
+ // Sakura end - collide with non-solid blocks
return flags;
}
// Sakura end - load chunks on movement

View File

@@ -0,0 +1,55 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Thu, 30 Nov 2023 15:54:49 +0000
Subject: [PATCH] Reduce entity tracker player updates
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index e096463443639e9eef5311d7154f6d2ac1517883..ec166e88f0257890eb87efa3ec9c5fd6725d3569 100644
--- a/net/minecraft/server/level/ChunkMap.java
+++ b/net/minecraft/server/level/ChunkMap.java
@@ -953,7 +953,11 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
if (tracker == null) {
continue;
}
- ((ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerTrackedEntity)tracker).moonrise$tick(((ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity)entity).moonrise$getChunkData().nearbyPlayers);
+ // Sakura start - reduce entity tracker player updates
+ if (tracker.shouldUpdatePlayers()) {
+ ((ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerTrackedEntity)tracker).moonrise$tick(((ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity)entity).moonrise$getChunkData().nearbyPlayers);
+ }
+ // Sakura end - reduce entity tracker player updates
if (((ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerTrackedEntity)tracker).moonrise$hasPlayers()
|| ((ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity)entity).moonrise$getChunkStatus().isOrAfter(FullChunkStatus.ENTITY_TICKING)) {
tracker.serverEntity.sendChanges();
@@ -1197,12 +1201,31 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
return state != me.samsuik.sakura.player.visibility.VisibilityState.OFF;
}
// Sakura end - client visibility settings; entity visibility
+ // Sakura start - reduce entity tracker player updates
+ private final int playerUpdateInterval;
+ private net.minecraft.world.phys.Vec3 entityPosition;
+
+ public final boolean shouldUpdatePlayers() {
+ // We have to always update players otherwise they can turn invisible on teleports (why?)
+ if (this.entity instanceof net.minecraft.world.entity.player.Player || this.entity.tickCount % this.playerUpdateInterval == 0) {
+ return true;
+ }
+ final net.minecraft.world.phys.Vec3 lastPosition = this.entityPosition;
+ this.entityPosition = this.entity.position();
+ return this.entity.position().distanceToSqr(lastPosition) >= (double) this.range / 2.0;
+ }
+ // Sakura start - reduce entity tracker player updates
public TrackedEntity(final Entity entity, final int range, final int updateInterval, final boolean trackDelta) {
this.serverEntity = new ServerEntity(ChunkMap.this.level, entity, updateInterval, trackDelta, this::broadcast, this.seenBy); // CraftBukkit
this.entity = entity;
this.range = range;
this.lastSectionPos = SectionPos.of(entity);
+ // Sakura end - client visibility settings; entity visibility
+ // Sakura start - reduce entity tracker player updates
+ this.playerUpdateInterval = Math.min(j, 20);
+ this.entityPosition = entity.position();
+ // Sakura start - reduce entity tracker player updates
}
@Override

View File

@@ -0,0 +1,56 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Sat, 2 Dec 2023 15:14:15 +0000
Subject: [PATCH] Legacy lava block formation
diff --git a/net/minecraft/world/level/block/LiquidBlock.java b/net/minecraft/world/level/block/LiquidBlock.java
index e719be50ff73610046696a21053671332951ca9c..9f8f71c95086b18be4d9254ca8aa7f93674fb598 100644
--- a/net/minecraft/world/level/block/LiquidBlock.java
+++ b/net/minecraft/world/level/block/LiquidBlock.java
@@ -194,7 +194,14 @@ public class LiquidBlock extends Block implements BucketPickup {
final FluidState fluidState = state.getFluidState();
final Block block = fluidState.isSource() ? Blocks.OBSIDIAN : Blocks.COBBLESTONE;
if (block == Blocks.COBBLESTONE) {
- final me.samsuik.sakura.physics.PhysicsVersion physics = level.localConfig().config(pos).physicsVersion;
+ // Sakura start - legacy lava block formation
+ final me.samsuik.sakura.physics.PhysicsVersion physics;
+ if (world.sakuraConfig().environment.blockGeneration.legacyBlockFormation) {
+ physics = me.samsuik.sakura.physics.PhysicsVersion.v1_12;
+ } else {
+ physics = level.localConfig().config(pos).physicsVersion;
+ }
+ // Sakura end - legacy lava block formation
// SANITY: In legacy a patch by paper removes the fluid level condition from vanilla.
if (physics.before(1_16_0) && !physics.isLegacy() &&
diff --git a/net/minecraft/world/level/material/LavaFluid.java b/net/minecraft/world/level/material/LavaFluid.java
index 9b714ddad7208dd9509bf9f8434f1acea5a6f213..d073864e6d4be4e8001ff6e6a0a1dd92e95a9323 100644
--- a/net/minecraft/world/level/material/LavaFluid.java
+++ b/net/minecraft/world/level/material/LavaFluid.java
@@ -174,7 +174,8 @@ public abstract class LavaFluid extends FlowingFluid {
public boolean canBeReplacedWith(FluidState fluidState, BlockGetter blockReader, BlockPos pos, Fluid fluid, Direction direction) {
// Sakura start - configure cannon physics
return fluidState.getHeight(blockReader, pos) >= 0.44444445F && fluid.is(FluidTags.WATER)
- && blockReader instanceof Level level && level.localConfig().config(pos).physicsVersion.afterOrEqual(1_13_0);
+ && blockReader instanceof Level level && level.localConfig().config(pos).physicsVersion.afterOrEqual(1_13_0)
+ && !level.sakuraConfig().environment.blockGeneration.legacyBlockFormation; // Sakura - legacy lava block formation
// Sakura end - configure cannon physics
}
diff --git a/net/minecraft/world/level/material/WaterFluid.java b/net/minecraft/world/level/material/WaterFluid.java
index 6f478324e9edaf52f8938fb6e24208495463454f..a1677a683dc530c0af5f2ead275cf57482860737 100644
--- a/net/minecraft/world/level/material/WaterFluid.java
+++ b/net/minecraft/world/level/material/WaterFluid.java
@@ -118,7 +118,10 @@ public abstract class WaterFluid extends FlowingFluid {
if (direction == Direction.DOWN && !fluid.is(FluidTags.WATER) || !(blockReader instanceof Level level)) {
return true;
}
- return fluid.is(FluidTags.LAVA) && level.localConfig().config(pos).physicsVersion.before(1_13_0);
+ // Sakura start - legacy lava block formation
+ return fluid.is(FluidTags.LAVA) && (level.localConfig().config(pos).physicsVersion.before(1_13_0)
+ || level.sakuraConfig().environment.blockGeneration.legacyBlockFormation);
+ // Sakura end - legacy lava block formation
// Sakura end - configure cannon physics
}

View File

@@ -0,0 +1,54 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Tue, 20 Feb 2024 19:16:16 +0000
Subject: [PATCH] Add entity travel distance limits
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index ee44ba44773f245d351aac9461bd6cff18204f01..12f5f0002d2b298c4f9bd021d13626ddb5719317 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -1292,6 +1292,11 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
final boolean isActive = io.papermc.paper.entity.activation.ActivationRange.checkIfActive(entity); // Paper - EAR 2
if (isActive) { // Paper - EAR 2
entity.tick();
+ // Sakura start - entity travel distance limits
+ if (entity.isPastTravelDistanceLimit()) {
+ entity.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN);
+ }
+ // Sakura end - entity travel distance limits
entity.postTick(); // CraftBukkit
} else {entity.inactiveTick();} // Paper - EAR 2
profilerFiller.pop();
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 7c3b536ee056cfd938f19a0a22b1d128f0fa2733..37d2ab5f3cfe10478e87d1649d072fe6b69fb914 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -595,6 +595,19 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return this.physics;
}
// Sakura end - configure cannon physics
+ // Sakura start - entity travel distance limits
+ private final double travelDistanceLimit;
+
+ public final boolean isPastTravelDistanceLimit() {
+ if (this.origin == null) {
+ return false;
+ }
+
+ double x = Math.pow(this.origin.getX() - this.position.x(), 2);
+ double z = Math.pow(this.origin.getZ() - this.position.z(), 2);
+ return Math.max(x, z) >= this.travelDistanceLimit;
+ }
+ // Sakura end - entity travel distance limits
public Entity(EntityType<?> entityType, Level level) {
this.type = entityType;
@@ -624,6 +637,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.setPos(0.0, 0.0, 0.0);
this.eyeHeight = this.dimensions.eyeHeight();
this.despawnTime = type == EntityType.PLAYER ? -1 : level.paperConfig().entities.spawning.despawnTime.getOrDefault(type, io.papermc.paper.configuration.type.number.IntOr.Disabled.DISABLED).or(-1); // Paper - entity despawn time limit
+ this.travelDistanceLimit = Math.pow(this.level.sakuraConfig().entity.chunkTravelLimit.getOrDefault(this.type, Integer.MAX_VALUE) * 16.0, 2); // Sakura - entity travel distance limits
}
public boolean isColliding(BlockPos pos, BlockState state) {

View File

@@ -0,0 +1,22 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Mon, 17 Jun 2024 14:04:12 +0100
Subject: [PATCH] Protect scaffolding from creepers
diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java
index ad44fb3a3ee0b6595564031f73fc61c459a8d951..d2d2bb0e60f4f12761fa02b1c6fb293d15e4efed 100644
--- a/net/minecraft/world/level/ServerExplosion.java
+++ b/net/minecraft/world/level/ServerExplosion.java
@@ -412,6 +412,11 @@ public class ServerExplosion implements Explosion {
return Optional.of(ZERO_RESISTANCE);
}
// Sakura end - allow explosions to destroy lava
+ // Sakura start - protect scaffolding from creepers
+ if (this.level.sakuraConfig().cannons.explosion.protectScaffoldingFromCreepers && blockState.is(Blocks.SCAFFOLDING) && this.source instanceof net.minecraft.world.entity.monster.Creeper) {
+ return Optional.of(Blocks.BARRIER.getExplosionResistance());
+ }
+ // Sakura end - protect scaffolding from creepers
}
return this.damageCalculator.getBlockExplosionResistance(this, this.level, pos, blockState, fluidState);

View File

@@ -0,0 +1,89 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Fri, 9 Aug 2024 20:43:53 +0100
Subject: [PATCH] Configurable left shooting and adjusting limits
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 37d2ab5f3cfe10478e87d1649d072fe6b69fb914..f9b9d81cc60785488a7cf57caabb4a5fdd84ecae 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -608,6 +608,46 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return Math.max(x, z) >= this.travelDistanceLimit;
}
// Sakura end - entity travel distance limits
+ // Sakura start - configurable left shooting and adjusting limits
+ public final void limitLeftShooting() {
+ Vec3 movement = this.getDeltaMovement();
+ int threshold = this.level.sakuraConfig().cannons.restrictions.leftShootingThreshold.or(-1);
+ if (threshold > 0 && (movement.x != 0.0 || movement.z != 0.0) && this.origin != null) {
+ double travelledX = Math.abs(this.getX() - this.origin.getX());
+ double travelledZ = Math.abs(this.getZ() - this.origin.getZ());
+ boolean xSmaller = travelledX < travelledZ; // intended
+
+ // Once entities have travelled past the threshold changing direction is restricted.
+ if (xSmaller && travelledX > threshold) {
+ this.setDeltaMovement(movement.multiply(1.0, 1.0, 0.0)); // limit z
+ } else if (!xSmaller && travelledZ > threshold) {
+ this.setDeltaMovement(movement.multiply(0.0, 1.0, 1.0)); // limit x
+ }
+ }
+ }
+
+ public final void limitAdjustMovement(AABB currBoundingBox, double dir, boolean xAdjust, List<VoxelShape> shapes) {
+ int adjustDistance = this.level.sakuraConfig().cannons.restrictions.maxAdjustDistance.or(-1);
+ if (adjustDistance > 0 && Math.abs(dir) > adjustDistance) {
+ double minX = Double.NEGATIVE_INFINITY;
+ double minZ = Double.NEGATIVE_INFINITY;
+ double maxX = Double.POSITIVE_INFINITY;
+ double maxZ = Double.POSITIVE_INFINITY;
+ if (xAdjust) { // limit x adjust
+ minX = Math.floor(currBoundingBox.minX) - adjustDistance;
+ maxX = Math.floor(currBoundingBox.maxX) + adjustDistance + 1;
+ } else { // limit z adjust
+ minZ = Math.floor(currBoundingBox.minZ) - adjustDistance;
+ maxZ = Math.floor(currBoundingBox.maxZ) + adjustDistance + 1;
+ }
+ VoxelShape safeSpace = Shapes.box(
+ minX, Double.NEGATIVE_INFINITY, minZ,
+ maxX, Double.POSITIVE_INFINITY, maxZ
+ );
+ shapes.add(Shapes.join(Shapes.INFINITY, safeSpace, BooleanOp.ONLY_FIRST));
+ }
+ }
+ // Sakura end - configurable left shooting and adjusting limits
public Entity(EntityType<?> entityType, Level level) {
this.type = entityType;
@@ -1641,6 +1681,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
if (xSmaller && z != 0.0) {
+ this.limitAdjustMovement(currBoundingBox, z, false, voxelList); // Sakura - configurable left shooting and adjusting limits
z = this.scanZ(currBoundingBox, z, voxelList, bbList);
if (z != 0.0) {
currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetZ(currBoundingBox, z);
@@ -1648,6 +1689,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
if (x != 0.0) {
+ // Sakura start - configurable left shooting and adjusting limits
+ if (!xSmaller) {
+ this.limitAdjustMovement(currBoundingBox, x, true, voxelList);
+ }
+ // Sakura end - configurable left shooting and adjusting limits
x = this.scanX(currBoundingBox, x, voxelList, bbList);
if (x != 0.0) {
currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetX(currBoundingBox, x);
diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java
index d82e5184515c14a819b70c4d621cc6d93d120cc9..77656b3e8b80b07e9aa44a4d2c9bca468c52d26b 100644
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -263,6 +263,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
// Sakura end - configure cannon physics
this.time++;
this.applyGravity();
+ this.limitLeftShooting(); // Sakura - configurable left shooting and adjusting limits
this.moveStripped(MoverType.SELF, this.getDeltaMovement()); // Sakura - optimise cannon entity movement
this.applyEffectsFromBlocks();
// Paper start - Configurable falling blocks height nerf

View File

@@ -0,0 +1,315 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Mon, 12 Aug 2024 15:35:57 +0100
Subject: [PATCH] Optimise hopper ticking
diff --git a/net/minecraft/world/CompoundContainer.java b/net/minecraft/world/CompoundContainer.java
index 82923c9db0c620fe83c4d4447e6eb0dd8a6bb334..0dbc419884bd407dcbd44f7f0aef89754526a18f 100644
--- a/net/minecraft/world/CompoundContainer.java
+++ b/net/minecraft/world/CompoundContainer.java
@@ -48,6 +48,15 @@ public class CompoundContainer implements Container {
return this.container1.getLocation(); // TODO: right?
}
// CraftBukkit end
+ // Sakura start - optimise hopper ticking
+ @Override
+ public final boolean addListener(net.minecraft.world.level.block.entity.BlockEntity.BlockEntityChangeListener listener) {
+ boolean result = false;
+ result |= this.container1.addListener(listener);
+ result |= this.container2.addListener(listener);
+ return result;
+ }
+ // Sakura end - optimise hopper ticking
public CompoundContainer(Container container1, Container container2) {
this.container1 = container1;
diff --git a/net/minecraft/world/Container.java b/net/minecraft/world/Container.java
index 2d3721e311851c1801b090e99d4f9d0daf4e5f99..2249f5338f97471a833acddcee95f6a769176ce8 100644
--- a/net/minecraft/world/Container.java
+++ b/net/minecraft/world/Container.java
@@ -12,6 +12,12 @@ import net.minecraft.world.level.block.entity.BlockEntity;
public interface Container extends Clearable {
float DEFAULT_DISTANCE_BUFFER = 4.0F;
+ // Sakura start - optimise hopper ticking
+ default boolean addListener(BlockEntity.BlockEntityChangeListener container) {
+ return false;
+ }
+ // Sakura end - optimise hopper ticking
+
int getContainerSize();
boolean isEmpty();
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
index eeb37d088cec5b2b8e1ac4bd48b4491eed0822e2..28fc6372b3e4815fa62217a27f265f182046fe73 100644
--- a/net/minecraft/world/level/Level.java
+++ b/net/minecraft/world/level/Level.java
@@ -1659,7 +1659,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
// Spigot end
if (tickingBlockEntity.isRemoved()) {
toRemove.add(tickingBlockEntity); // Paper - Fix MC-117075; use removeAll
- } else if (runsNormally && this.shouldTickBlocksAt(tickingBlockEntity.getPos())) {
+ } else if (runsNormally && tickingBlockEntity.isBlockEntityActive() && this.shouldTickBlocksAt(tickingBlockEntity.getPos())) { // Sakura - optimise hopper ticking
tickingBlockEntity.tick();
// Paper start - rewrite chunk system
if ((++tickedEntities & 7) == 0) {
diff --git a/net/minecraft/world/level/block/HopperBlock.java b/net/minecraft/world/level/block/HopperBlock.java
index 8ce44400279511f78a0773a23a2aafc3f887ade3..1457d9feee282e375a56b19423cc6fb561521d13 100644
--- a/net/minecraft/world/level/block/HopperBlock.java
+++ b/net/minecraft/world/level/block/HopperBlock.java
@@ -140,6 +140,12 @@ public class HopperBlock extends BaseEntityBlock {
private void checkPoweredState(Level level, BlockPos pos, BlockState state) {
boolean flag = !level.hasNeighborSignal(pos);
if (flag != state.getValue(ENABLED)) {
+ // Sakura start - optimise hopper ticking
+ final BlockEntity blockEntity = level.getBlockEntity(pos);
+ if (blockEntity instanceof HopperBlockEntity hbe && level.sakuraConfig().technical.optimiseIdleHopperTicking) {
+ hbe.setBlockEntityTicking(flag);
+ }
+ // Sakura end - optimise hopper ticking
level.setBlock(pos, state.setValue(ENABLED, Boolean.valueOf(flag)), 2);
}
}
diff --git a/net/minecraft/world/level/block/entity/BlockEntity.java b/net/minecraft/world/level/block/entity/BlockEntity.java
index 77618757c0e678532dbab814aceed83f7f1cd892..65d359c497b73c821b082a885c063a7328d378a9 100644
--- a/net/minecraft/world/level/block/entity/BlockEntity.java
+++ b/net/minecraft/world/level/block/entity/BlockEntity.java
@@ -40,6 +40,55 @@ public abstract class BlockEntity {
private BlockState blockState;
private DataComponentMap components = DataComponentMap.EMPTY;
+ // Sakura start - optimise hopper ticking
+ private final Set<BlockEntityChangeListener> listeners = new it.unimi.dsi.fastutil.objects.ReferenceArraySet<>(0);
+ private final java.util.List<BlockEntity> listeningBlocks = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(0);
+ private boolean blockEntityTicking = true;
+ private int tickCount = 0;
+
+ public final int getIdleTickCount() {
+ return this.tickCount;
+ }
+
+ public final boolean isBlockEntityActive() {
+ this.tickCount++;
+ return this.blockEntityTicking;
+ }
+
+ public final void setBlockEntityTicking(boolean blockEntityTicking) {
+ this.tickCount = 0;
+ this.blockEntityTicking = blockEntityTicking;
+ }
+
+ public final boolean addListener(BlockEntityChangeListener listener) {
+ if (this.listeners.add(listener)) {
+ ((BlockEntity) listener).listeningBlocks.add(this);
+ }
+ return true;
+ }
+
+ public final void updateListeners(boolean onRemove) {
+ for (BlockEntityChangeListener listener : this.listeners) {
+ if (onRemove) {
+ listener.neighborRemoved();
+ } else {
+ listener.neighborChange();
+ }
+ }
+ if (onRemove) {
+ this.listeningBlocks.forEach(blockEntity -> blockEntity.listeners.clear());
+ this.listeningBlocks.clear();
+ this.listeners.clear();
+ }
+ }
+
+ public interface BlockEntityChangeListener {
+ void neighborChange();
+
+ void neighborRemoved();
+ }
+ // Sakura end - optimise hopper ticking
+
public BlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) {
this.type = type;
this.worldPosition = pos.immutable();
@@ -198,11 +247,22 @@ public abstract class BlockEntity {
public void setChanged() {
if (this.level != null) {
if (ignoreBlockEntityUpdates) return; // Paper - Perf: Optimize Hoppers
- setChanged(this.level, this.worldPosition, this.blockState);
+ setChanged(this.level, this.worldPosition, this.blockState, this); // Sakura - optimise hopper ticking
}
}
protected static void setChanged(Level level, BlockPos pos, BlockState state) {
+ // Sakura start - optimise hopper ticking
+ net.minecraft.world.level.chunk.LevelChunk chunk = level.getChunkIfLoaded(pos);
+ BlockEntity blockEntity = chunk != null ? chunk.getBlockEntity(pos) : null;
+ setChanged(level, pos, state, blockEntity);
+ }
+
+ protected static void setChanged(Level level, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity) {
+ if (blockEntity != null) {
+ blockEntity.updateListeners(false);
+ }
+ // Sakura end - optimise hopper ticking
level.blockEntityChanged(pos);
if (!state.isAir()) {
level.updateNeighbourForOutputSignal(pos, state.getBlock());
@@ -232,6 +292,7 @@ public abstract class BlockEntity {
public void setRemoved() {
this.remove = true;
+ this.updateListeners(true); // Sakura - optimise hopper ticking
}
public void clearRemoved() {
diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
index 5cd1326ad5d046c88b2b3449d610a78fa880b4cd..900ed60d6294a8afea48800808a7b89a8a8b27ad 100644
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
@@ -28,7 +28,7 @@ import net.minecraft.world.level.block.HopperBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
-public class HopperBlockEntity extends RandomizableContainerBlockEntity implements Hopper {
+public class HopperBlockEntity extends RandomizableContainerBlockEntity implements Hopper, BlockEntity.BlockEntityChangeListener { // Sakura - optimise hopper ticking
public static final int MOVE_ITEM_SPEED = 8;
public static final int HOPPER_CONTAINER_SIZE = 5;
private static final int[][] CACHED_SLOTS = new int[54][];
@@ -66,6 +66,58 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
this.maxStack = size;
}
// CraftBukkit end
+ // Sakura start - optimise hopper ticking
+ private static final int SOURCE_CONTAINER = 1 << 0;
+ private static final int ATTACHED_CONTAINER = 1 << 1;
+ private int connectedContainers = 0;
+
+ @Override
+ public final void neighborChange() {
+ this.startTicking();
+ }
+
+ @Override
+ public final void neighborRemoved() {
+ this.connectedContainers = 0;
+ this.startTicking();
+ }
+
+ private void startTicking() {
+ this.cooldownTime -= this.getIdleTickCount();
+ this.setBlockEntityTicking(true);
+ }
+
+ private void waitForChange(int fullState) {
+ if ((fullState == HOPPER_IS_FULL || (this.connectedContainers & SOURCE_CONTAINER) != 0) && (this.connectedContainers & ATTACHED_CONTAINER) != 0) {
+ this.addListener(this);
+ this.setBlockEntityTicking(false);
+ }
+ }
+
+ private static @Nullable Container sakura_getSourceContainer(Level level, Hopper hopper, BlockPos pos, BlockState state) {
+ Container container = getSourceContainer(level, hopper, pos, state);
+ if (hopper instanceof HopperBlockEntity hbe && HopperInventorySearchEvent.getHandlerList().getRegisteredListeners().length == 0) {
+ hbe.listenForContainerChanges(container, SOURCE_CONTAINER);
+ }
+ return container;
+ }
+
+ private static @Nullable Container sakura_getAttachedContainer(Level level, BlockPos pos, HopperBlockEntity hbe) {
+ Container container = getAttachedContainer(level, pos, hbe);
+ if (HopperInventorySearchEvent.getHandlerList().getRegisteredListeners().length == 0) {
+ hbe.listenForContainerChanges(container, ATTACHED_CONTAINER);
+ }
+ return container;
+ }
+
+ private void listenForContainerChanges(@Nullable Container container, int type) {
+ if (container != null && container.addListener(this)) {
+ this.connectedContainers |= type; // set
+ } else if ((this.connectedContainers & type) != 0) {
+ this.connectedContainers ^= type; // unset
+ }
+ }
+ // Sakura end - optimise hopper ticking
public HopperBlockEntity(BlockPos pos, BlockState blockState) {
@@ -196,6 +248,12 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
setChanged(level, pos, state);
return true;
}
+
+ // Sakura start - optimise hopper ticking
+ if (level.sakuraConfig().technical.optimiseIdleHopperTicking) {
+ blockEntity.waitForChange(fullState);
+ }
+ // Sakura end - optimise hopper ticking
}
return false;
@@ -413,7 +471,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
// Paper end - Perf: Optimize Hoppers
private static boolean ejectItems(Level level, BlockPos pos, HopperBlockEntity blockEntity) {
- Container attachedContainer = getAttachedContainer(level, pos, blockEntity);
+ Container attachedContainer = sakura_getAttachedContainer(level, pos, blockEntity); // Sakura - optimise hopper ticking
if (attachedContainer == null) {
return false;
} else {
@@ -526,7 +584,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
public static boolean suckInItems(Level level, Hopper hopper) {
BlockPos blockPos = BlockPos.containing(hopper.getLevelX(), hopper.getLevelY() + 1.0, hopper.getLevelZ());
BlockState blockState = level.getBlockState(blockPos);
- Container sourceContainer = getSourceContainer(level, hopper, blockPos, blockState);
+ Container sourceContainer = sakura_getSourceContainer(level, hopper, blockPos, blockState); // Sakura - optimise hopper ticking
if (sourceContainer != null) {
Direction direction = Direction.DOWN;
skipPullModeEventFire = skipHopperEvents; // Paper - Perf: Optimize Hoppers
diff --git a/net/minecraft/world/level/block/entity/TickingBlockEntity.java b/net/minecraft/world/level/block/entity/TickingBlockEntity.java
index 28e3b73507b988f7234cbf29c4024c88180d0aef..a0d247aa883553708c4b92158232425593d50534 100644
--- a/net/minecraft/world/level/block/entity/TickingBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/TickingBlockEntity.java
@@ -10,4 +10,10 @@ public interface TickingBlockEntity {
BlockPos getPos();
String getType();
+
+ // Sakura start - optimise hopper ticking
+ default boolean isBlockEntityActive() {
+ return true;
+ }
+ // Sakura end - optimise hopper ticking
}
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
index 761fdcd4a4e18f45547afd8edff44f61c6eeacb4..04477dd45088c06c97c2f8e24e9d1a7362a62a61 100644
--- a/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
@@ -955,6 +955,13 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
return BlockEntityType.getKey(this.blockEntity.getType()).toString();
}
+ // Sakura start - optimise hopper ticking
+ @Override
+ public boolean isBlockEntityActive() {
+ return this.blockEntity.isBlockEntityActive();
+ }
+ // Sakura end - optimise hopper ticking
+
@Override
public String toString() {
return "Level ticker for " + this.getType() + "@" + this.getPos();
@@ -1003,6 +1010,13 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
return this.ticker.getType();
}
+ // Sakura start - optimise hopper ticking
+ @Override
+ public boolean isBlockEntityActive() {
+ return this.ticker.isBlockEntityActive();
+ }
+ // Sakura end - optimise hopper ticking
+
@Override
public String toString() {
return this.ticker + " <wrapped>";

View File

@@ -0,0 +1,72 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Fri, 13 Sep 2024 17:22:51 +0100
Subject: [PATCH] Optimise entity scheduler ticking
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/server/ServerEntityLookup.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/server/ServerEntityLookup.java
index 26207443b1223119c03db478d7e816d9cdf8e618..1664830a49f37825c39fb6b436011d8149196e3a 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/server/ServerEntityLookup.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/server/ServerEntityLookup.java
@@ -18,6 +18,22 @@ public final class ServerEntityLookup extends EntityLookup {
private final ServerLevel serverWorld;
public final ReferenceList<Entity> trackerEntities = new ReferenceList<>(EMPTY_ENTITY_ARRAY); // Moonrise - entity tracker
+ // Sakura start - optimise entity scheduler ticking
+ public final ReferenceList<org.bukkit.craftbukkit.entity.CraftEntity> scheduledEntities = new ReferenceList<>();
+
+ public void entityStartScheduled(final Entity entity) {
+ org.bukkit.craftbukkit.entity.CraftEntity bukkitEntity = entity.getBukkitEntityRaw();
+ if (bukkitEntity != null && bukkitEntity.taskScheduler.hasTask()) {
+ this.scheduledEntities.add(bukkitEntity);
+ }
+ }
+
+ public void entityEndScheduled(final Entity entity) {
+ if (entity.getBukkitEntityRaw() != null) {
+ this.scheduledEntities.remove(entity.getBukkitEntityRaw());
+ }
+ }
+ // Sakura end - optimise entity scheduler ticking
public ServerEntityLookup(final ServerLevel world, final LevelCallback<Entity> worldCallback) {
super(world, worldCallback);
@@ -89,6 +105,7 @@ public final class ServerEntityLookup extends EntityLookup {
// Moonrise start - entity tracker
this.trackerEntities.add(entity);
// Moonrise end - entity tracker
+ this.entityStartScheduled(entity); // Sakura - optimise entity scheduler ticking
}
@Override
@@ -96,6 +113,7 @@ public final class ServerEntityLookup extends EntityLookup {
// Moonrise start - entity tracker
this.trackerEntities.remove(entity);
// Moonrise end - entity tracker
+ this.entityEndScheduled(entity); // Sakura - optimise entity scheduler ticking
}
@Override
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 6d8c513e78fa4efd8c7f6f534cf3958d46448efb..bad2fbd90d4db6b89b6346da53a41ef110307169 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1678,7 +1678,17 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Paper start - Folia scheduler API
((io.papermc.paper.threadedregions.scheduler.FoliaGlobalRegionScheduler) org.bukkit.Bukkit.getGlobalRegionScheduler()).tick();
getAllLevels().forEach(level -> {
- for (final net.minecraft.world.entity.Entity entity : level.getEntities().getAll()) {
+ // Sakura start - optimise entity scheduler ticking
+ final ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup entityLookup = (ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup) level.moonrise$getEntityLookup();
+ final java.util.Iterator<org.bukkit.craftbukkit.entity.CraftEntity> entityIterator = entityLookup.scheduledEntities.iterator();
+ while (entityIterator.hasNext()) {
+ final org.bukkit.craftbukkit.entity.CraftEntity scheduledEntity = entityIterator.next();
+ final net.minecraft.world.entity.Entity entity = scheduledEntity.getHandle();
+ if (!scheduledEntity.taskScheduler.hasTask()) {
+ entityIterator.remove();
+ continue;
+ }
+ // Sakura end - optimise entity scheduler ticking
if (entity.isRemoved()) {
continue;
}

View File

@@ -0,0 +1,68 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Fri, 8 Nov 2024 19:35:49 +0000
Subject: [PATCH] Optimise check inside blocks and traverse blocks
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index f9b9d81cc60785488a7cf57caabb4a5fdd84ecae..17e5148f7fb273e6de3ab5f159cbfc5d4819eb9f 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -1930,6 +1930,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
private void checkInsideBlocks(List<Entity.Movement> movements, Set<BlockState> blocksInside) {
if (this.isAffectedByBlocks()) {
LongSet set = this.visitedBlocks;
+ // Sakura start - optimise check inside blocks
+ int lastChunkX = Integer.MIN_VALUE;
+ int lastChunkZ = Integer.MIN_VALUE;
+ net.minecraft.world.level.chunk.ChunkAccess chunk = null;
+ // Sakura end - optimise check inside blocks
for (Entity.Movement movement : movements) {
Vec3 vec3 = movement.from();
@@ -1949,7 +1954,19 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return;
}
- BlockState blockState = this.level().getBlockState(blockPos);
+ // Sakura start - optimise check inside blocks
+ final int chunkX = blockPos.getX() >> 4;
+ final int chunkZ = blockPos.getZ() >> 4;
+ if (chunk == null || chunkX != lastChunkX || chunkZ != lastChunkZ) {
+ chunk = this.level.getChunkIfLoadedImmediately(chunkX, chunkZ);
+ if (chunk == null) {
+ continue;
+ }
+ lastChunkX = chunkX;
+ lastChunkZ = chunkZ;
+ }
+ final BlockState blockState = chunk.getBlockState(blockPos);
+ // Sakura end - optimise check inside blocks
if (!blockState.isAir() && set.add(blockPos.asLong())) {
try {
VoxelShape entityInsideCollisionShape = blockState.getEntityInsideCollisionShape(this.level(), blockPos);
diff --git a/net/minecraft/world/level/BlockGetter.java b/net/minecraft/world/level/BlockGetter.java
index 91865d7e78e15cc643a65de03045b90a52d6ec2a..8857887ac4fc9cb2bd08df4ccd9981d1d0e14806 100644
--- a/net/minecraft/world/level/BlockGetter.java
+++ b/net/minecraft/world/level/BlockGetter.java
@@ -214,10 +214,18 @@ public interface BlockGetter extends LevelHeightAccessor {
static Iterable<BlockPos> boxTraverseBlocks(Vec3 oldPosition, Vec3 position, AABB boundingBox) {
Vec3 vec3 = position.subtract(oldPosition);
- Iterable<BlockPos> iterable = BlockPos.betweenClosed(boundingBox);
+ // Sakura start - optimise check inside blocks
if (vec3.lengthSqr() < Mth.square(0.99999F)) {
- return iterable;
+ return me.samsuik.sakura.utils.BlockPosIterator.iterable(boundingBox);
} else {
+ final boolean xZero = vec3.x() == 0.0;
+ final boolean yZero = vec3.y() == 0.0;
+ final boolean zZero = vec3.z() == 0.0;
+ if (xZero && yZero || yZero && zZero || xZero && zZero) {
+ return me.samsuik.sakura.utils.BlockPosIterator.traverseArea(vec3, boundingBox);
+ }
+ Iterable<BlockPos> iterable = BlockPos.betweenClosed(boundingBox);
+ // Sakura end - optimise check inside blocks
Set<BlockPos> set = new ObjectLinkedOpenHashSet<>();
Vec3 minPosition = boundingBox.getMinPosition();
Vec3 vec31 = minPosition.subtract(vec3);

View File

@@ -0,0 +1,41 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Fri, 13 Sep 2024 17:22:51 +0100
Subject: [PATCH] Optimise entity scheduler ticking
diff --git a/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java b/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java
index c03608fec96b51e1867f43d8f42e5aefb1520e46..9a363b8a15d76911813e31fdb525815b74539b02 100644
--- a/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java
+++ b/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java
@@ -50,6 +50,22 @@ public final class EntityScheduler {
this.entity = Validate.notNull(entity);
}
+ // Sakura start - optimise entity scheduler ticking
+ public boolean hasTask() {
+ return !this.currentlyExecuting.isEmpty() || !this.oneTimeDelayed.isEmpty();
+ }
+
+ private void newScheduledTask() {
+ net.minecraft.server.MinecraftServer.getServer().scheduleOnMain(() -> {
+ Entity handle = this.entity.getHandleRaw();
+ net.minecraft.server.level.ServerLevel level = (net.minecraft.server.level.ServerLevel) handle.level();
+ ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup entityLookup = (ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup) level.moonrise$getEntityLookup();
+
+ entityLookup.entityStartScheduled(handle);
+ });
+ }
+ // Sakura end - optimise entity scheduler ticking
+
/**
* Retires the scheduler, preventing new tasks from being scheduled and invoking the retired callback
* on all currently scheduled tasks.
@@ -128,6 +144,7 @@ public final class EntityScheduler {
return new ArrayList<>();
}).add(task);
}
+ this.newScheduledTask(); // Sakura - tick entity schedulers only when necessary
return true;
}

View File

@@ -161,9 +161,15 @@ public abstract class SpecialisedExplosion<T extends Entity> extends ServerExplo
if (distanceFromBottom <= 1.0) {
double x = entity.getX() - pos.x;
double y = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - pos.y;
double y = entity.getEyeY() - pos.y; // Sakura - physics version api
double z = entity.getZ() - pos.z;
double distance = Math.sqrt(x * x + y * y + z * z);
// Sakura start - physics version api
if (this.physics.before(1_17_0)) {
distanceFromBottom = (float) distanceFromBottom;
distance = (float) distance;
}
// Sakura end - physics version api
if (distance != 0.0D) {
x /= distance;

View File

@@ -37,6 +37,13 @@ public final class TntExplosion extends SpecialisedExplosion<PrimedTnt> {
this.bounds = new AABB(center, center);
}
// Sakura start - physics version api
@Override
protected double getExplosionOffset() {
return this.physics.before(1_10_0) ? (double) 0.49f : super.getExplosionOffset();
}
// Sakura end - physics version api
@Override
protected int getExplosionCount() {
if (this.cause.getMergeEntityData().getMergeLevel() == MergeLevel.NONE) {

View File

@@ -5,6 +5,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
@@ -22,6 +23,14 @@ public final class BlockPosIterator extends AbstractIterator<BlockPos> {
return () -> new BlockPosIterator(bb);
}
public static Iterable<BlockPos> traverseArea(Vec3 vec, AABB boundingBox) {
double toTravel = Math.min(16.0 / vec.length(), 1.0);
Vec3 movement = vec.scale(toTravel);
AABB fromBB = boundingBox.move(-vec.x, -vec.y, -vec.z);
AABB searchArea = fromBB.expandTowards(movement);
return me.samsuik.sakura.utils.BlockPosIterator.iterable(searchArea);
}
public BlockPosIterator(AABB bb) {
this.startX = Mth.floor(bb.minX);
this.startY = Mth.floor(bb.minY);

Submodule sakura-server/src/minecraft/java updated: 6e26d2a9a1...368fba8e7c

Submodule sakura-server/src/minecraft/resources updated: 6f9aaa646d...9d71ffc850