Begin remigrate to Shiroha

uhm
This commit is contained in:
2026-07-14 11:32:51 +08:00
parent 5661499e95
commit 576a9a44c8
60 changed files with 379 additions and 379 deletions
@@ -16,10 +16,10 @@ index fe17157c4c6fc9ec745c5c11f6837e715d7949ab..be3bdce1b42a32f57d9ec71d8f115ea1
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;
import java.util.function.Predicate;
+// Camellia start - imports for lithium sleeping block entity
+// Shiroha start - imports for lithium sleeping block entity
+import org.leavesmc.leaves.lithium.common.tracking.entity.ChunkSectionInventoryEntityTracker;
+import org.leavesmc.leaves.lithium.common.tracking.entity.ChunkSectionItemEntityMovementTracker;
+// Camellia end
+// Shiroha end
public final class RegionizedWorldData {
@@ -27,7 +27,7 @@ index fe17157c4c6fc9ec745c5c11f6837e715d7949ab..be3bdce1b42a32f57d9ec71d8f115ea1
public static final RegionizedData.RegioniserCallback<RegionizedWorldData> REGION_CALLBACK = new RegionizedData.RegioniserCallback<>() {
@Override
public void merge(final RegionizedWorldData from, final RegionizedWorldData into, final long fromTickOffset) {
+ // Camellia start - Region threading for lithium sleeping block entity
+ // Shiroha start - Region threading for lithium sleeping block entity
+ // lithium listeners
+ final long fromRedstoneTimeOffsetForLithiumTracker = into.redstoneTime - from.redstoneTime;
+ for (var entry : from.containerEntityMovementTrackerMap.entrySet()) {
@@ -52,7 +52,7 @@ index fe17157c4c6fc9ec745c5c11f6837e715d7949ab..be3bdce1b42a32f57d9ec71d8f115ea1
+ tracker.updateTicks(fromTickOffset, fromRedstoneTimeOffsetForLithiumTracker);
+ into.itemEntityMovementTrackerMap.put(key, tracker);
+ }
+ // Camellia end
+ // Shiroha end
// connections
for (final Connection conn : from.connections) {
into.connections.add(conn);
@@ -61,25 +61,25 @@ index fe17157c4c6fc9ec745c5c11f6837e715d7949ab..be3bdce1b42a32f57d9ec71d8f115ea1
// tile entity ticking
- for (final TickingBlockEntity tileEntityWrapped : from.pendingBlockEntityTickers) {
+ for (TickingBlockEntity tileEntityWrapped : from.pendingBlockEntityTickers) { // Camellia - Region threading for lithium sleeping block entity
+ for (TickingBlockEntity tileEntityWrapped : from.pendingBlockEntityTickers) { // Shiroha - Region threading for lithium sleeping block entity
into.pendingBlockEntityTickers.add(tileEntityWrapped);
- final BlockEntity tileEntity = tileEntityWrapped.getTileEntity();
+ BlockEntity tileEntity = tileEntityWrapped.getTileEntity(); // Camellia - Region threading for lithium sleeping block entity
+ // Camellia start - Region threading for lithium sleeping block entity
+ BlockEntity tileEntity = tileEntityWrapped.getTileEntity(); // Shiroha - Region threading for lithium sleeping block entity
+ // Shiroha start - Region threading for lithium sleeping block entity
+ tileEntityWrapped.updateTicksForLithium(fromRedstoneTimeOffset);
+ // Camellia end - Region threading for lithium sleeping block entity
+ // Shiroha end - Region threading for lithium sleeping block entity
if (tileEntity != null) {
tileEntity.updateTicks(fromTickOffset, fromRedstoneTimeOffset);
}
}
- for (final TickingBlockEntity tileEntityWrapped : from.blockEntityTickers) {
+ for (TickingBlockEntity tileEntityWrapped : from.blockEntityTickers) { // Camellia - Region threading for lithium sleeping block entity
+ for (TickingBlockEntity tileEntityWrapped : from.blockEntityTickers) { // Shiroha - Region threading for lithium sleeping block entity
into.blockEntityTickers.add(tileEntityWrapped);
- final BlockEntity tileEntity = tileEntityWrapped.getTileEntity();
+ BlockEntity tileEntity = tileEntityWrapped.getTileEntity(); // Camellia - Region threading for lithium sleeping block entity
+ // Camellia start - Region threading for lithium sleeping block entity
+ BlockEntity tileEntity = tileEntityWrapped.getTileEntity(); // Shiroha - Region threading for lithium sleeping block entity
+ // Shiroha start - Region threading for lithium sleeping block entity
+ tileEntityWrapped.updateTicksForLithium(fromRedstoneTimeOffset);
+ // Camellia end - Region threading for lithium sleeping block entity
+ // Shiroha end - Region threading for lithium sleeping block entity
if (tileEntity != null) {
tileEntity.updateTicks(fromTickOffset, fromRedstoneTimeOffset);
}
@@ -87,7 +87,7 @@ index fe17157c4c6fc9ec745c5c11f6837e715d7949ab..be3bdce1b42a32f57d9ec71d8f115ea1
public void split(final RegionizedWorldData from, final int chunkToRegionShift,
final Long2ReferenceOpenHashMap<RegionizedWorldData> regionToData,
final ReferenceOpenHashSet<RegionizedWorldData> dataSet) {
+ // Camellia start - Region threading for lithium sleeping block entity
+ // Shiroha start - Region threading for lithium sleeping block entity
+ // lithium entity movement listeners
+ for (var entry : from.containerEntityMovementTrackerMap.entrySet()) {
+ final long key = entry.getKey();
@@ -117,7 +117,7 @@ index fe17157c4c6fc9ec745c5c11f6837e715d7949ab..be3bdce1b42a32f57d9ec71d8f115ea1
+
+ regionToData.get(CoordinateUtils.getChunkKey(pos.x() >> chunkToRegionShift, pos.z() >> chunkToRegionShift)).itemEntityMovementTrackerMap.put(key, tracker);
+ }
+ // Camellia end
+ // Shiroha end
// connections
for (final Connection conn : from.connections) {
final ServerPlayer player = conn.getPlayer();
@@ -127,9 +127,9 @@ index fe17157c4c6fc9ec745c5c11f6837e715d7949ab..be3bdce1b42a32f57d9ec71d8f115ea1
// tile entity ticking
- for (final TickingBlockEntity tileEntity : from.pendingBlockEntityTickers) {
- final BlockPos pos = tileEntity.getPos();
+ for (final TickingBlockEntity tileEntity : from.pendingBlockEntityTickers) { // Camellia - Region threading for lithium sleeping block entity
+ BlockPos pos = tileEntity.getPos(); // Camellia - Region threading for lithium sleeping block entity
+ if (pos == null) pos = tileEntity.getTileEntity().getBlockPos(); // Camellia - Region threading for lithium sleeping block entity
+ for (final TickingBlockEntity tileEntity : from.pendingBlockEntityTickers) { // Shiroha - Region threading for lithium sleeping block entity
+ BlockPos pos = tileEntity.getPos(); // Shiroha - Region threading for lithium sleeping block entity
+ if (pos == null) pos = tileEntity.getTileEntity().getBlockPos(); // Shiroha - Region threading for lithium sleeping block entity
final int chunkX = pos.getX() >> 4;
final int chunkZ = pos.getZ() >> 4;
@@ -139,9 +139,9 @@ index fe17157c4c6fc9ec745c5c11f6837e715d7949ab..be3bdce1b42a32f57d9ec71d8f115ea1
}
- for (final TickingBlockEntity tileEntity : from.blockEntityTickers) {
- final BlockPos pos = tileEntity.getPos();
+ for (final TickingBlockEntity tileEntity : from.blockEntityTickers) { // Camellia - Region threading for lithium sleeping block entity
+ BlockPos pos = tileEntity.getPos(); // Camellia - Region threading for lithium sleeping block entity
+ if (pos == null) pos = tileEntity.getTileEntity().getBlockPos(); // Camellia - Region threading for lithium sleeping block entity
+ for (final TickingBlockEntity tileEntity : from.blockEntityTickers) { // Shiroha - Region threading for lithium sleeping block entity
+ BlockPos pos = tileEntity.getPos(); // Shiroha - Region threading for lithium sleeping block entity
+ if (pos == null) pos = tileEntity.getTileEntity().getBlockPos(); // Shiroha - Region threading for lithium sleeping block entity
final int chunkX = pos.getX() >> 4;
final int chunkZ = pos.getZ() >> 4;
@@ -149,11 +149,11 @@ index fe17157c4c6fc9ec745c5c11f6837e715d7949ab..be3bdce1b42a32f57d9ec71d8f115ea1
public final io.papermc.paper.redstone.RedstoneWireTurbo turbo;
// Environment attribute system
public Reference2ObjectOpenHashMap<EnvironmentAttribute<?>, EnvironmentAttributeSystem.ValueSampler<?>> attributeSamplers;
+ // Camellia start - Region threading for lithium sleeping block entity
+ // Shiroha start - Region threading for lithium sleeping block entity
+ // Lithium
+ public final Map<Long, ChunkSectionInventoryEntityTracker> containerEntityMovementTrackerMap = new it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<>();
+ public final Map<Long, ChunkSectionItemEntityMovementTracker> itemEntityMovementTrackerMap = new it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<>();
+ // Camellia end
+ // Shiroha end
public final TickRegions.TickRegionData regionData;
@@ -256,24 +256,24 @@ index 18e0572fe28461e57edb13e6ed6f5a0b6b3604c9..83914a091cc8fd6ef726f2732238b164
}
protected Entity transformForAsyncTeleport(ServerLevel destination, Vec3 pos, Float yaw, Float pitch, Vec3 velocity) {
+ final boolean toSameWorld = this.level != destination; // Camellia - Region threading for lithium sleeping block entity
+ final boolean toSameWorld = this.level != destination; // Shiroha - Region threading for lithium sleeping block entity
this.removeAfterChangingDimensions(); // remove before so that any CBEntity#getHandle call affects this entity before copying
Entity copy = this.getType().create(destination, EntitySpawnReason.DIMENSION_TRAVEL);
copy.restoreFrom(this);
copy.transform(pos, yaw, pitch, velocity);
+ if (toSameWorld) copy.notifyLithiumTrackerIfNeeded(); // Camellia - Region threading for lithium sleeping block entity
if (copy instanceof net.minecraft.world.entity.boss.enderdragon.EnderDragon dragon) dragon.syncDragonPartsAfterTeleportTransform(); // Camellia - Fix dragon part desync
+ if (toSameWorld) copy.notifyLithiumTrackerIfNeeded(); // Shiroha - Region threading for lithium sleeping block entity
if (copy instanceof net.minecraft.world.entity.boss.enderdragon.EnderDragon dragon) dragon.syncDragonPartsAfterTeleportTransform(); // Shiroha - Fix dragon part desync
// vanilla code used to call remove _after_ copying, and some stuff is required to be after copy - so add hook here
// for example, clearing of inventory after switching dimensions
@@ -5953,8 +5955,29 @@ public abstract class Entity
this.setBoundingBox(this.makeBoundingBox());
}
// Paper end - Block invalid positions and bounding box
+ this.notifyLithiumTrackerIfNeeded(); // Camellia - Leaves lithium sleeping block entity
+ this.notifyLithiumTrackerIfNeeded(); // Shiroha - Leaves lithium sleeping block entity
}
+ // Camellia start - Region threading for lithium sleeping block entity
+ // Shiroha start - Region threading for lithium sleeping block entity
+ private void notifyLithiumTrackerIfNeeded() {
+ // Leaves start - Lithium Sleeping Block Entity
+ if (!moe.monnairealms.camellia.config.modules.optimizations.LeavesSleepingBlockEntityConfig.enabled) return;
@@ -282,16 +282,16 @@ index 18e0572fe28461e57edb13e6ed6f5a0b6b3604c9..83914a091cc8fd6ef726f2732238b164
+ if (this instanceof ItemEntity) {
+ long sectionKey = ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkSectionKey(this);
+ org.leavesmc.leaves.lithium.common.tracking.entity.ChunkSectionItemEntityMovementTracker tracker = currentWorldData.itemEntityMovementTrackerMap.get(sectionKey);
+ if (tracker != null) tracker.notifyAllListeners(currentWorldData.getRedstoneGameTime()); // Camellia - Region threading for lithium sleeping block entity
+ if (tracker != null) tracker.notifyAllListeners(currentWorldData.getRedstoneGameTime()); // Shiroha - Region threading for lithium sleeping block entity
+ }
+ else if (this instanceof net.minecraft.world.entity.vehicle.ContainerEntity) {
+ long sectionKey = ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkSectionKey(this);
+ org.leavesmc.leaves.lithium.common.tracking.entity.ChunkSectionInventoryEntityTracker tracker = currentWorldData.containerEntityMovementTrackerMap.get(sectionKey);
+ if (tracker != null) tracker.notifyAllListeners(currentWorldData.getRedstoneGameTime()); // Camellia - Region threading for lithium sleeping block entity
+ if (tracker != null) tracker.notifyAllListeners(currentWorldData.getRedstoneGameTime()); // Shiroha - Region threading for lithium sleeping block entity
+ }
+ // Leaves end - Lithium Sleeping Block Entity
+ }
+ // Camellia end
+ // Shiroha end
+
public void checkDespawn() {
}
@@ -1613,10 +1613,10 @@ index 4c9d0bcd8820b250b51c06fff4531021ab57d408..fa34778b1ce7a34385c192182e521b00
public void updateTicks(final long fromTickOffset, final long fromRedstoneTimeOffset) {
super.updateTicks(fromTickOffset, fromRedstoneTimeOffset);
- if (this.tickedGameTime != Long.MIN_VALUE) {
+ if (this.tickedGameTime != Long.MIN_VALUE && this.tickedGameTime != Long.MAX_VALUE) { // Camellia - Region threading for lithium sleeping block entity
+ if (this.tickedGameTime != Long.MIN_VALUE && this.tickedGameTime != Long.MAX_VALUE) { // Shiroha - Region threading for lithium sleeping block entity
this.tickedGameTime += fromRedstoneTimeOffset;
}
+ // Camellia start - Region threading for lithium sleeping block entity
+ // Shiroha start - Region threading for lithium sleeping block entity
+ if (this.insertInventoryEntityFailedSearchTime != Long.MIN_VALUE)
+ this.insertInventoryEntityFailedSearchTime += fromRedstoneTimeOffset;
+
@@ -1625,7 +1625,7 @@ index 4c9d0bcd8820b250b51c06fff4531021ab57d408..fa34778b1ce7a34385c192182e521b00
+
+ if (this.collectItemEntityAttemptTime != Long.MIN_VALUE)
+ this.collectItemEntityAttemptTime += fromRedstoneTimeOffset;
+ // Camellia end
+ // Shiroha end
}
// Folia end - region threading
@@ -2607,9 +2607,9 @@ index c8facee29ee08e0975528083f89b64f0b593957f..2499535f0aa699decad88917ab46fccc
BlockEntity getTileEntity(); // Folia - region threading
+
+ // Camellia start - Region threading for lithium sleeping block entity
+ // Shiroha start - Region threading for lithium sleeping block entity
+ default void updateTicksForLithium(long redstoneGameTimeOffset) {}
+ // Camellia end
+ // Shiroha end
}
diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java
index c78d77089e34c4bb559f173b449bfb7d91b05d5c..f4cce42ddd319cfd11cc43d68044f51b4514af38 100644
@@ -2653,7 +2653,7 @@ index 0e84b695a677e71f443a29c78fc5025eec7ae7f4..3cb6c24a21538569d73b95803dde7e4a
LevelChunk.RebindableTickingBlockEntityWrapper ticker = this.tickersInLevel.remove(pos);
if (ticker != null) {
ticker.rebind(NULL_TICKER);
+ ticker.createdBy = null; // Camellia - Region threading for sleeping block entity
+ ticker.createdBy = null; // Shiroha - Region threading for sleeping block entity
}
}
@@ -2661,7 +2661,7 @@ index 0e84b695a677e71f443a29c78fc5025eec7ae7f4..3cb6c24a21538569d73b95803dde7e4a
this.blockEntities.values().forEach(BlockEntity::setRemoved);
this.blockEntities.clear();
this.tickersInLevel.values().forEach(ticker -> ticker.rebind(NULL_TICKER));
+ this.tickersInLevel.values().forEach(ticker -> ticker.createdBy = null); // Camellia - Region threading for sleeping block entity
+ this.tickersInLevel.values().forEach(ticker -> ticker.createdBy = null); // Shiroha - Region threading for sleeping block entity
this.tickersInLevel.clear();
}
@@ -2670,13 +2670,13 @@ index 0e84b695a677e71f443a29c78fc5025eec7ae7f4..3cb6c24a21538569d73b95803dde7e4a
TickingBlockEntity actualTicker = this.createTicker(blockEntity, ticker);
if (existingTicker != null) {
+ if (moe.monnairealms.camellia.config.modules.optimizations.LeavesSleepingBlockEntityConfig.enabled && blockEntity instanceof org.leavesmc.leaves.lithium.common.block.entity.SleepingBlockEntity sleepingBlockEntity) sleepingBlockEntity.lithium$setTickWrapper(existingTicker); // Leaves - Lithium Sleeping Block Entity
+ if (moe.monnairealms.camellia.config.modules.optimizations.LeavesSleepingBlockEntityConfig.enabled) existingTicker.createdBy = blockEntity; // Camellia - Region threading for lithium sleeping block entity
+ if (moe.monnairealms.camellia.config.modules.optimizations.LeavesSleepingBlockEntityConfig.enabled) existingTicker.createdBy = blockEntity; // Shiroha - Region threading for lithium sleeping block entity
existingTicker.rebind(actualTicker);
return (LevelChunk.RebindableTickingBlockEntityWrapper)existingTicker;
} else if (this.isInLevel()) {
LevelChunk.RebindableTickingBlockEntityWrapper result = new LevelChunk.RebindableTickingBlockEntityWrapper(actualTicker);
+ if (moe.monnairealms.camellia.config.modules.optimizations.LeavesSleepingBlockEntityConfig.enabled && blockEntity instanceof org.leavesmc.leaves.lithium.common.block.entity.SleepingBlockEntity sleepingBlockEntity) sleepingBlockEntity.lithium$setTickWrapper(result); // Leaves - Lithium Sleeping Block Entity
+ if (moe.monnairealms.camellia.config.modules.optimizations.LeavesSleepingBlockEntityConfig.enabled) result.createdBy = blockEntity; // Camellia - Region threading for lithium sleeping block entity
+ if (moe.monnairealms.camellia.config.modules.optimizations.LeavesSleepingBlockEntityConfig.enabled) result.createdBy = blockEntity; // Shiroha - Region threading for lithium sleeping block entity
this.level.addBlockEntityTicker(result);
return result;
} else {
@@ -2688,7 +2688,7 @@ index 0e84b695a677e71f443a29c78fc5025eec7ae7f4..3cb6c24a21538569d73b95803dde7e4a
- private TickingBlockEntity ticker;
+ public static class RebindableTickingBlockEntityWrapper implements TickingBlockEntity { // Leaves - default -> public
+ public TickingBlockEntity ticker; // Leaves - private -> public
+ @org.jetbrains.annotations.Nullable private BlockEntity createdBy; // Camellia - Region threading for lithium sleeping block entity
+ @org.jetbrains.annotations.Nullable private BlockEntity createdBy; // Shiroha - Region threading for lithium sleeping block entity
private RebindableTickingBlockEntityWrapper(final TickingBlockEntity ticker) {
this.ticker = ticker;
@@ -2702,7 +2702,7 @@ index 0e84b695a677e71f443a29c78fc5025eec7ae7f4..3cb6c24a21538569d73b95803dde7e4a
// Folia start - region threading
@Override
public BlockEntity getTileEntity() {
+ // Camellia start - Region threading for lithium sleeping block entity
+ // Shiroha start - Region threading for lithium sleeping block entity
+ if (true) {
+ if (this.ticker != null) {
+ var ret = this.ticker.getTileEntity();
@@ -2716,7 +2716,7 @@ index 0e84b695a677e71f443a29c78fc5025eec7ae7f4..3cb6c24a21538569d73b95803dde7e4a
+
+ return null;
+ }
+ // Camellia end
+ // Shiroha end
return this.ticker == null ? null : this.ticker.getTileEntity();
}
// Folia end - region threading
@@ -2725,7 +2725,7 @@ index 0e84b695a677e71f443a29c78fc5025eec7ae7f4..3cb6c24a21538569d73b95803dde7e4a
return this.ticker + " <wrapped>";
}
+
+ // Camellia start - Region threading for lithium sleeping block entity
+ // Shiroha start - Region threading for lithium sleeping block entity
+ @Override
+ public void updateTicksForLithium(long redstoneGameTimeOffset) {
+ if (this.ticker != null) {
@@ -2733,7 +2733,7 @@ index 0e84b695a677e71f443a29c78fc5025eec7ae7f4..3cb6c24a21538569d73b95803dde7e4a
+ }
+ }
+
+ // Camellia end
+ // Shiroha end
}
@FunctionalInterface