Compare commits
19 Commits
build-225
...
feat/async
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7278888017 | ||
|
|
d1a9c55403 | ||
|
|
29fabdd8f3 | ||
|
|
ae1f11a394 | ||
|
|
b45f3843c2 | ||
|
|
8e31fc9945 | ||
|
|
ccd629843c | ||
|
|
ada5265608 | ||
|
|
f508c9cd84 | ||
|
|
e6c765ef71 | ||
|
|
cb1b2a78ac | ||
|
|
ad43ef6000 | ||
|
|
eb571af123 | ||
|
|
9925aa59c7 | ||
|
|
2dc38b4f88 | ||
|
|
4401555131 | ||
|
|
6da53043d4 | ||
|
|
ea1493dd8f | ||
|
|
e18e9091fb |
51
README.md
51
README.md
@@ -11,14 +11,13 @@
|
||||
|
||||
## Features
|
||||
|
||||
### Notable
|
||||
- **Xymb Linear Format**: A Region file format that reduces disk space usage by about 50%.
|
||||
- **Async Pathfinding**: Petal async pathfinding fixed & reworked.
|
||||
- **Technical Minecraft**: Enable Vanilla exploits such as sand duping, RNG manipulation...
|
||||
### Primary
|
||||
- **Xymb Linear Format**: Saves about 50% of disk space in OW/Nether and 95% in The End.
|
||||
- **Auto update**: Automatic upstream updates.
|
||||
|
||||
### Other
|
||||
- **Small optimizations**: Increase server efficiency by disabling unnecessary features.
|
||||
- **Commands**: Restore few commands that were previously removed by Folia.
|
||||
### Notable
|
||||
- **Entity throttling & removal**: Tweak entity tick frequency & max entity per region.
|
||||
- **Technical Minecraft**: Enable Vanilla exploits such as sand duping, RNG manipulation...
|
||||
|
||||
### Configuration
|
||||
|
||||
@@ -26,31 +25,16 @@
|
||||
network:
|
||||
send-null-entity-packets: true
|
||||
alternate-keepalive: false
|
||||
kick-player-on-bad-packet: true
|
||||
gameplay:
|
||||
server-mod-name: Kaiiju
|
||||
shared-random-for-players: true
|
||||
region-format:
|
||||
debug: false
|
||||
optimization:
|
||||
disable-vanish-api: false
|
||||
disable-player-stats: false
|
||||
disable-arm-swing-event: false
|
||||
disable-ensure-tick-thread-checks: false
|
||||
async-path-processing:
|
||||
enable: false
|
||||
max-threads: 0
|
||||
keepalive: 60
|
||||
queue-capacity: 4096
|
||||
gameplay:
|
||||
server-mod-name: Kaiiju
|
||||
shared-random-for-players: true
|
||||
world-settings:
|
||||
default:
|
||||
gameplay:
|
||||
fix-void-trading: true
|
||||
break-redstone-on-top-of-trap-doors-early: true
|
||||
fix-tripwire-state-inconsistency: true
|
||||
safe-teleportation: true
|
||||
sand-duplication: false
|
||||
teleport-async-on-high-velocity: false
|
||||
region-format:
|
||||
format: ANVIL
|
||||
linear:
|
||||
@@ -58,22 +42,25 @@ world-settings:
|
||||
crash-on-broken-symlink: true
|
||||
optimization:
|
||||
shulker-box-drop-contents-when-destroyed: true
|
||||
optimize-hoppers: true
|
||||
tick-when-empty: true
|
||||
enable-entity-throttling: false
|
||||
disable-achievements: false
|
||||
disable-creatures-spawn-events: false
|
||||
disable-dolphin-swim-to-treasure: false
|
||||
gameplay:
|
||||
fix-void-trading: true
|
||||
optimize-hoppers: true
|
||||
tick-when-empty: true
|
||||
break-redstone-on-top-of-trap-doors-early: true
|
||||
fix-tripwire-state-inconsistency: true
|
||||
safe-teleportation: true
|
||||
sand-duplication: false
|
||||
```
|
||||
Documentation: [Kaiiju Wiki](https://github.com/KaiijuMC/Kaiiju/wiki/Configuration)
|
||||
|
||||
### Roadmap
|
||||
- **Stash deduplication**: Make giant dupe stashes possible and lagless.
|
||||
- **Multithreaded Tracker**: Rework Petal multithreaded tracker.
|
||||
|
||||
## Open to contributions
|
||||
- **Static view distance**: Reduce RAM usage / Region size with a "static" view distance.
|
||||
- **Native world conversion**: Convert region file format at startup.
|
||||
- **Performance patch**: Any significative performance patch.
|
||||
- **Stash deduplication**: Make giant dupe stashes possible and lagless.
|
||||
|
||||
## Building
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ group = dev.kaiijumc.kaiiju
|
||||
version = 1.20.1-R0.1-SNAPSHOT
|
||||
mcVersion = 1.20.1
|
||||
|
||||
foliaRef = b2d7bdb0bb5c841b4ccd096c0181664664ce97b1
|
||||
foliaRef = daacd4255022f3a1bf74dd3e84f751be838678ac
|
||||
|
||||
org.gradle.caching=true
|
||||
org.gradle.parallel=true
|
||||
|
||||
@@ -42,7 +42,7 @@ index abf5e2a06af9853b58ac9107cd6e9787c4185c66..389c68c0becd2f69dc1004d0b383f1a8
|
||||
long expectedChunks = (long)regionFiles.length * (32L * 32L);
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
index c4d28d887b4cc71dc713b1e3f46bc80f4484a95d..f50507ab85282d261985ce9b186581f5a7a50f79 100644
|
||||
index 61c6bc2859235874aefac71e9e55162f0a89f29f..24bd63c596c9f61f1e89ec5b001b7cb7a29a09ff 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
@@ -269,7 +269,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||||
@@ -64,7 +64,7 @@ index c4d28d887b4cc71dc713b1e3f46bc80f4484a95d..f50507ab85282d261985ce9b186581f5
|
||||
// Paper start
|
||||
this.dataRegionManager = new io.papermc.paper.chunk.SingleThreadChunkRegionManager(this.level, 2, (1.0 / 3.0), 1, 6, "Data", DataRegionData::new, DataRegionSectionData::new);
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
index 7099a44a2322ab390c21e74668c8657dcc9e5e87..475554797ffc279243ac0d88f1e619c3dd07bc4b 100644
|
||||
index 4774d3f357d62b0818b4713f8085d05be09eaa5c..1bbd8b475cdc57fb15ca05ffe122220a5539da10 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -426,8 +426,8 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
||||
|
||||
@@ -22,7 +22,7 @@ index f3f824d0ab1a2a72825c40b67192386479a0b34c..95ed6cb7b94797187d1011cab344e187
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
index 475554797ffc279243ac0d88f1e619c3dd07bc4b..475d0f3dd38e0407fa120d57e7d89216836538dd 100644
|
||||
index 1bbd8b475cdc57fb15ca05ffe122220a5539da10..7f39e36037d55278d15399196459e51b885c5d1e 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -2838,7 +2838,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
||||
|
||||
@@ -22,7 +22,7 @@ index 6d7356cc07da58b1cef8d8963e790251d765de2c..601b9867d839f4928ba993ee8f00df9c
|
||||
|
||||
public boolean fixVoidTrading = true;
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
index 475d0f3dd38e0407fa120d57e7d89216836538dd..245c3e63588379f51780963ba91bc6bf0a3feda6 100644
|
||||
index 7f39e36037d55278d15399196459e51b885c5d1e..66509fa23bfcde70abd3917eb774cf48d5d6da93 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -798,7 +798,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
||||
|
||||
@@ -319,7 +319,7 @@ index 991e4c19763a34a6fead88363e007c2d11aad836..24a2d3f496727790f63cb66a2534d442
|
||||
dev.kaiijumc.kaiiju.KaiijuConfig.registerCommands();
|
||||
// Kaiiju end
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
index 245c3e63588379f51780963ba91bc6bf0a3feda6..6efc8b37d4ee929522f5646c972565b99aa45de3 100644
|
||||
index 245c3e63588379f51780963ba91bc6bf0a3feda6..761019f86983daaea4fface519e052f8fb6de1cd 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -822,6 +822,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
||||
@@ -337,7 +337,7 @@ index 245c3e63588379f51780963ba91bc6bf0a3feda6..6efc8b37d4ee929522f5646c972565b9
|
||||
+ // Kaiiju start
|
||||
+ if (kaiijuConfig.enableEntityThrottling) {
|
||||
+ dev.kaiijumc.kaiiju.KaiijuEntityThrottler.EntityThrottlerReturn throttle = regionizedWorldData.entityThrottler.tickLimiterShouldSkip(entity);
|
||||
+ if (throttle.remove && !entity.hasCustomName()) entity.remove(Entity.RemovalReason.DISCARDED);
|
||||
+ if (throttle.remove) entity.remove(Entity.RemovalReason.DISCARDED);
|
||||
+ if (throttle.skip) return;
|
||||
+ }
|
||||
+ // Kaiiju end
|
||||
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Async path processing
|
||||
|
||||
|
||||
diff --git a/src/main/java/dev/kaiijumc/kaiiju/KaiijuConfig.java b/src/main/java/dev/kaiijumc/kaiiju/KaiijuConfig.java
|
||||
index 6df1720159383c2f536b40ded1092a437c1a20af..fc88b9f1e7e8f5858a91deeca2a5d51266a79a93 100644
|
||||
index ebfa9e1dcca5ea8272e796f0409902d92b59ee76..6be4abdd16f2d57a80dbe175a91ff304fd17a7db 100644
|
||||
--- a/src/main/java/dev/kaiijumc/kaiiju/KaiijuConfig.java
|
||||
+++ b/src/main/java/dev/kaiijumc/kaiiju/KaiijuConfig.java
|
||||
@@ -12,6 +12,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -16,13 +16,14 @@ index 6df1720159383c2f536b40ded1092a437c1a20af..fc88b9f1e7e8f5858a91deeca2a5d512
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -218,12 +219,26 @@ public class KaiijuConfig {
|
||||
@@ -213,12 +214,28 @@ public class KaiijuConfig {
|
||||
public static boolean disablePlayerStats = false;
|
||||
public static boolean disableArmSwingEvent = false;
|
||||
public static boolean disableEnsureTickThreadChecks = false;
|
||||
+ public static boolean asyncPathProcessing = false;
|
||||
+ public static int asyncPathProcessingMaxThreads = 0;
|
||||
+ public static int asyncPathProcessingKeepalive = 60;
|
||||
+ public static int asyncPathProcessingQueueCapacity = 4096;
|
||||
|
||||
private static void optimizationSettings() {
|
||||
disableVanishApi = getBoolean("optimization.disable-vanish-api", disableVanishApi);
|
||||
@@ -32,6 +33,7 @@ index 6df1720159383c2f536b40ded1092a437c1a20af..fc88b9f1e7e8f5858a91deeca2a5d512
|
||||
+ asyncPathProcessing = getBoolean("optimization.async-path-processing.enable", asyncPathProcessing);
|
||||
+ asyncPathProcessingMaxThreads = getInt("optimization.async-path-processing.max-threads", asyncPathProcessingMaxThreads);
|
||||
+ asyncPathProcessingKeepalive = getInt("optimization.async-path-processing.keepalive", asyncPathProcessingKeepalive);
|
||||
+ asyncPathProcessingQueueCapacity = getInt("optimization.async-path-processing.queue-capacity", asyncPathProcessingQueueCapacity);
|
||||
+ if (asyncPathProcessingMaxThreads < 0)
|
||||
+ asyncPathProcessingMaxThreads = Math.max(Runtime.getRuntime().availableProcessors() + asyncPathProcessingMaxThreads, 1);
|
||||
+ else if (asyncPathProcessingMaxThreads == 0)
|
||||
@@ -338,15 +340,15 @@ index 0000000000000000000000000000000000000000..6b91852238f80d236fc44f766b115267
|
||||
+}
|
||||
diff --git a/src/main/java/dev/kaiijumc/kaiiju/path/AsyncPathProcessor.java b/src/main/java/dev/kaiijumc/kaiiju/path/AsyncPathProcessor.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..8ac99ae5f0c0fc8a471be293c9033c04ec644780
|
||||
index 0000000000000000000000000000000000000000..a6de8906d1629c60523c02681379ccdcaa22b588
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/dev/kaiijumc/kaiiju/path/AsyncPathProcessor.java
|
||||
@@ -0,0 +1,52 @@
|
||||
@@ -0,0 +1,53 @@
|
||||
+package dev.kaiijumc.kaiiju.path;
|
||||
+
|
||||
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
+
|
||||
+import dev.kaiijumc.kaiiju.KaiijuConfig;import net.minecraft.world.level.pathfinder.Path;
|
||||
+import net.minecraft.world.level.pathfinder.Path;
|
||||
+import net.minecraft.world.entity.Entity;
|
||||
+
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
@@ -362,13 +364,14 @@ index 0000000000000000000000000000000000000000..8ac99ae5f0c0fc8a471be293c9033c04
|
||||
+
|
||||
+ private static final Executor pathProcessingExecutor = new ThreadPoolExecutor(
|
||||
+ 1,
|
||||
+ KaiijuConfig.asyncPathProcessingMaxThreads,
|
||||
+ KaiijuConfig.asyncPathProcessingKeepalive, TimeUnit.SECONDS,
|
||||
+ new LinkedBlockingQueue<>(),
|
||||
+ new ThreadFactoryBuilder()
|
||||
+ .setNameFormat("petal-path-processor-%d")
|
||||
+ .setPriority(Thread.NORM_PRIORITY - 2)
|
||||
+ .build()
|
||||
+ dev.kaiijumc.kaiiju.KaiijuConfig.asyncPathProcessingMaxThreads,
|
||||
+ dev.kaiijumc.kaiiju.KaiijuConfig.asyncPathProcessingKeepalive,
|
||||
+ TimeUnit.SECONDS,
|
||||
+ new ArrayBlockingQueue<>(dev.kaiijumc.kaiiju.KaiijuConfig.asyncPathProcessingQueueCapacity),
|
||||
+ new ThreadFactoryBuilder()
|
||||
+ .setNameFormat("petal-path-processor-%d")
|
||||
+ .setPriority(Thread.NORM_PRIORITY - 2)
|
||||
+ .build()
|
||||
+ );
|
||||
+
|
||||
+ protected static CompletableFuture<Void> queue(@NotNull AsyncPath path) {
|
||||
@@ -396,10 +399,10 @@ index 0000000000000000000000000000000000000000..8ac99ae5f0c0fc8a471be293c9033c04
|
||||
+}
|
||||
diff --git a/src/main/java/dev/kaiijumc/kaiiju/path/NodeEvaluatorCache.java b/src/main/java/dev/kaiijumc/kaiiju/path/NodeEvaluatorCache.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..3213fed7cea3ebfc364f4d6603b95f4263222c76
|
||||
index 0000000000000000000000000000000000000000..121eda164714650f76bb6c8495ef375d8a00d812
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/dev/kaiijumc/kaiiju/path/NodeEvaluatorCache.java
|
||||
@@ -0,0 +1,45 @@
|
||||
@@ -0,0 +1,42 @@
|
||||
+package dev.kaiijumc.kaiiju.path;
|
||||
+
|
||||
+import net.minecraft.world.level.pathfinder.NodeEvaluator;
|
||||
@@ -416,13 +419,13 @@ index 0000000000000000000000000000000000000000..3213fed7cea3ebfc364f4d6603b95f42
|
||||
+ private static final Map<NodeEvaluatorFeatures, ConcurrentLinkedQueue<NodeEvaluator>> threadLocalNodeEvaluators = new ConcurrentHashMap<>();
|
||||
+ private static final Map<NodeEvaluator, NodeEvaluatorGenerator> nodeEvaluatorToGenerator = new ConcurrentHashMap<>();
|
||||
+
|
||||
+ private static @NotNull Queue<NodeEvaluator> getQueueForFeatures(@NotNull NodeEvaluatorFeatures nodeEvaluatorFeatures) {
|
||||
+ private static @NotNull Queue<NodeEvaluator> getDequeForGenerator(@NotNull NodeEvaluatorFeatures nodeEvaluatorFeatures) {
|
||||
+ return threadLocalNodeEvaluators.computeIfAbsent(nodeEvaluatorFeatures, (key) -> new ConcurrentLinkedQueue<>());
|
||||
+ }
|
||||
+
|
||||
+ public static @NotNull NodeEvaluator takeNodeEvaluator(@NotNull NodeEvaluatorGenerator generator, @NotNull NodeEvaluator localNodeEvaluator) {
|
||||
+ final NodeEvaluatorFeatures nodeEvaluatorFeatures = NodeEvaluatorFeatures.fromNodeEvaluator(localNodeEvaluator);
|
||||
+ NodeEvaluator nodeEvaluator = getQueueForFeatures(nodeEvaluatorFeatures).poll();
|
||||
+ NodeEvaluator nodeEvaluator = getDequeForGenerator(nodeEvaluatorFeatures).poll();
|
||||
+
|
||||
+ if (nodeEvaluator == null) {
|
||||
+ nodeEvaluator = generator.generate(nodeEvaluatorFeatures);
|
||||
@@ -434,16 +437,13 @@ index 0000000000000000000000000000000000000000..3213fed7cea3ebfc364f4d6603b95f42
|
||||
+ }
|
||||
+
|
||||
+ public static void returnNodeEvaluator(@NotNull NodeEvaluator nodeEvaluator) {
|
||||
+ final NodeEvaluatorGenerator generator = nodeEvaluatorToGenerator.remove(nodeEvaluator);
|
||||
+ final NodeEvaluatorFeatures nodeEvaluatorFeatures = NodeEvaluatorFeatures.fromNodeEvaluator(nodeEvaluator);
|
||||
+ final var generator = nodeEvaluatorToGenerator.remove(nodeEvaluator);
|
||||
+ Validate.notNull(generator, "NodeEvaluator already returned");
|
||||
+
|
||||
+ final NodeEvaluatorFeatures nodeEvaluatorFeatures = NodeEvaluatorFeatures.fromNodeEvaluator(nodeEvaluator);
|
||||
+ getQueueForFeatures(nodeEvaluatorFeatures).offer(nodeEvaluator);
|
||||
+ getDequeForGenerator(nodeEvaluatorFeatures).offer(nodeEvaluator);
|
||||
+ }
|
||||
+
|
||||
+ public static void removeNodeEvaluator(@NotNull NodeEvaluator nodeEvaluator) {
|
||||
+ nodeEvaluatorToGenerator.remove(nodeEvaluator);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/dev/kaiijumc/kaiiju/path/NodeEvaluatorFeatures.java b/src/main/java/dev/kaiijumc/kaiiju/path/NodeEvaluatorFeatures.java
|
||||
new file mode 100644
|
||||
@@ -1140,24 +1140,6 @@ index 97b763431bc5015448ee7a26a340635a932c950b..48109aebe34cbdfac3eceffb1c20aa84
|
||||
return new PathFinder(this.nodeEvaluator, range) {
|
||||
@Override
|
||||
protected float distance(Node a, Node b) {
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/ShulkerBoxBlock.java b/src/main/java/net/minecraft/world/level/block/ShulkerBoxBlock.java
|
||||
index b51155ad12515b2d0dd0f202580b9f455c114d9a..358233cb35860adad86c01872c65ec6f165ba594 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/ShulkerBoxBlock.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/ShulkerBoxBlock.java
|
||||
@@ -242,8 +242,13 @@ public class ShulkerBoxBlock extends BaseEntityBlock {
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
|
||||
+ try { // Kaiiju - async pathfinding - lol i hate that
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
return blockEntity instanceof ShulkerBoxBlockEntity ? Shapes.create(((ShulkerBoxBlockEntity)blockEntity).getBoundingBox(state)) : Shapes.block();
|
||||
+ } catch (NullPointerException e) {
|
||||
+ return Shapes.block();
|
||||
+ }
|
||||
+ // Kaiiju end
|
||||
}
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/net/minecraft/world/level/pathfinder/Path.java b/src/main/java/net/minecraft/world/level/pathfinder/Path.java
|
||||
index 2a335f277bd0e4b8ad0f60d8226eb8aaa80a871f..b2c3c459fae7d0cb5ef0fcbc2ff0e61c7b952087 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/pathfinder/Path.java
|
||||
@@ -1189,7 +1171,7 @@ index 2a335f277bd0e4b8ad0f60d8226eb8aaa80a871f..b2c3c459fae7d0cb5ef0fcbc2ff0e61c
|
||||
return false;
|
||||
} else if (o.nodes.size() != this.nodes.size()) {
|
||||
diff --git a/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java b/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
|
||||
index d23481453717f715124156b5d83f6448f720d049..64b4cc587e2380a3d83916ea6ca1e1458458ceb0 100644
|
||||
index d23481453717f715124156b5d83f6448f720d049..d4cc2a5f99f8445be9a63c279e28032f11a91304 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
|
||||
@@ -24,37 +24,77 @@ public class PathFinder {
|
||||
@@ -1225,7 +1207,11 @@ index d23481453717f715124156b5d83f6448f720d049..64b4cc587e2380a3d83916ea6ca1e145
|
||||
+ Node node = nodeEvaluator.getStart();
|
||||
+ // Kaiiju end
|
||||
if (node == null) {
|
||||
+ dev.kaiijumc.kaiiju.path.NodeEvaluatorCache.removeNodeEvaluator(nodeEvaluator); // Kaiiju - petal - handle nodeEvaluatorGenerator
|
||||
+ // Kaiiju start - petal - handle nodeEvaluatorGenerator
|
||||
+ if (this.nodeEvaluatorGenerator != null) {
|
||||
+ dev.kaiijumc.kaiiju.path.NodeEvaluatorCache.returnNodeEvaluator(nodeEvaluator);
|
||||
+ }
|
||||
+ // Kaiiju end
|
||||
return null;
|
||||
} else {
|
||||
// Paper start - remove streams - and optimize collection
|
||||
@@ -1241,16 +1227,12 @@ index d23481453717f715124156b5d83f6448f720d049..64b4cc587e2380a3d83916ea6ca1e145
|
||||
+ // Kaiiju start - petal - async path processing
|
||||
+ if (this.nodeEvaluatorGenerator == null) {
|
||||
+ // run sync :(
|
||||
+ dev.kaiijumc.kaiiju.path.NodeEvaluatorCache.removeNodeEvaluator(nodeEvaluator);
|
||||
+ return this.findPath(world.getProfiler(), node, map, followRange, distance, rangeMultiplier);
|
||||
+ return this.findPath(nodeEvaluator, world.getProfiler(), node, map, followRange, distance, rangeMultiplier);
|
||||
+ }
|
||||
+
|
||||
+ return new dev.kaiijumc.kaiiju.path.AsyncPath(Lists.newArrayList(), positions, () -> {
|
||||
+ try {
|
||||
+ return this.processPath(nodeEvaluator, node, map, followRange, distance, rangeMultiplier);
|
||||
+ } catch (Exception e) {
|
||||
+ e.printStackTrace();
|
||||
+ return null;
|
||||
+ } finally {
|
||||
+ nodeEvaluator.done();
|
||||
+ dev.kaiijumc.kaiiju.path.NodeEvaluatorCache.returnNodeEvaluator(nodeEvaluator);
|
||||
@@ -1263,17 +1245,18 @@ index d23481453717f715124156b5d83f6448f720d049..64b4cc587e2380a3d83916ea6ca1e145
|
||||
- @Nullable
|
||||
+ //@Nullable // Kaiiju - Always not null
|
||||
// Paper start - optimize collection
|
||||
private Path findPath(ProfilerFiller profiler, Node startNode, List<Map.Entry<Target, BlockPos>> positions, float followRange, int distance, float rangeMultiplier) {
|
||||
- private Path findPath(ProfilerFiller profiler, Node startNode, List<Map.Entry<Target, BlockPos>> positions, float followRange, int distance, float rangeMultiplier) {
|
||||
+ private Path findPath(NodeEvaluator nodeEvaluator, ProfilerFiller profiler, Node startNode, List<Map.Entry<Target, BlockPos>> positions, float followRange, int distance, float rangeMultiplier) {
|
||||
profiler.push("find_path");
|
||||
profiler.markForCharting(MetricCategory.PATH_FINDING);
|
||||
+ // Kaiiju start - petal - split pathfinding into the original sync method for compat and processing for delaying
|
||||
+ try {
|
||||
+ return this.processPath(this.nodeEvaluator, startNode, positions, followRange, distance, rangeMultiplier);
|
||||
+ } finally {
|
||||
+ this.nodeEvaluator.done();
|
||||
+ nodeEvaluator.done();
|
||||
+ }
|
||||
+ }
|
||||
+ private synchronized @org.jetbrains.annotations.NotNull Path processPath(NodeEvaluator nodeEvaluator, Node startNode, List<Map.Entry<Target, BlockPos>> positions, float followRange, int distance, float rangeMultiplier) { // sync to only use the caching functions in this class on a single thread
|
||||
+ private synchronized Path processPath(NodeEvaluator nodeEvaluator, Node startNode, List<Map.Entry<Target, BlockPos>> positions, float followRange, int distance, float rangeMultiplier) { // sync to only use the caching functions in this class on a single thread
|
||||
+ org.apache.commons.lang3.Validate.isTrue(!positions.isEmpty()); // ensure that we have at least one position, which means we'll always return a path
|
||||
+ // Kaiiju end
|
||||
// Set<Target> set = positions.keySet();
|
||||
@@ -1288,14 +1271,6 @@ index d23481453717f715124156b5d83f6448f720d049..64b4cc587e2380a3d83916ea6ca1e145
|
||||
|
||||
for(int l = 0; l < k; ++l) {
|
||||
Node node2 = this.neighbors[l];
|
||||
@@ -123,6 +163,7 @@ public class PathFinder {
|
||||
if (best == null || comparator.compare(path, best) < 0)
|
||||
best = path;
|
||||
}
|
||||
+ //noinspection ConstantConditions // Kaiiju - petal - ignore this warning, we know that the above loop always runs at least once since positions is not empty
|
||||
return best;
|
||||
// Paper end
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/world/level/pathfinder/SwimNodeEvaluator.java b/src/main/java/net/minecraft/world/level/pathfinder/SwimNodeEvaluator.java
|
||||
index 0e2b14e7dfedf209d63279c81723fd7955122d78..079b278e2e262af433bb5bd0c12b3d8db4fa12fc 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/pathfinder/SwimNodeEvaluator.java
|
||||
|
||||
@@ -1,458 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Paul Sauve <paul@technove.co>
|
||||
Date: Tue, 1 Aug 2023 03:38:09 +0200
|
||||
Subject: [PATCH] Improve container checking with a bitset
|
||||
|
||||
|
||||
diff --git a/src/main/java/dev/kaiijumc/kaiiju/structs/ItemListWithBitset.java b/src/main/java/dev/kaiijumc/kaiiju/structs/ItemListWithBitset.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..ee32b7c4a1ae1e23149694ecba5ab7bd347d6ca6
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/dev/kaiijumc/kaiiju/structs/ItemListWithBitset.java
|
||||
@@ -0,0 +1,114 @@
|
||||
+package dev.kaiijumc.kaiiju.structs;
|
||||
+
|
||||
+
|
||||
+import net.minecraft.core.NonNullList;
|
||||
+import net.minecraft.world.item.ItemStack;
|
||||
+import org.apache.commons.lang.Validate;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+import java.util.AbstractList;
|
||||
+import java.util.Arrays;
|
||||
+import java.util.List;
|
||||
+
|
||||
+public class ItemListWithBitset extends AbstractList<ItemStack> {
|
||||
+ public static ItemListWithBitset fromList(List<ItemStack> list) {
|
||||
+ if (list instanceof ItemListWithBitset ours) {
|
||||
+ return ours;
|
||||
+ }
|
||||
+ return new ItemListWithBitset(list);
|
||||
+ }
|
||||
+
|
||||
+ private static ItemStack[] createArray(int size) {
|
||||
+ ItemStack[] array = new ItemStack[size];
|
||||
+ Arrays.fill(array, ItemStack.EMPTY);
|
||||
+ return array;
|
||||
+ }
|
||||
+
|
||||
+ private final ItemStack[] items;
|
||||
+
|
||||
+ private long bitSet = 0;
|
||||
+ private final long allBits;
|
||||
+
|
||||
+ private static class OurNonNullList extends NonNullList<ItemStack> {
|
||||
+ protected OurNonNullList(List<ItemStack> delegate) {
|
||||
+ super(delegate, ItemStack.EMPTY);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public final NonNullList<ItemStack> nonNullList = new OurNonNullList(this);
|
||||
+
|
||||
+ private ItemListWithBitset(List<ItemStack> list) {
|
||||
+ this(list.size());
|
||||
+
|
||||
+ for (int i = 0; i < list.size(); i++) {
|
||||
+ this.set(i, list.get(i));
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public ItemListWithBitset(int size) {
|
||||
+ Validate.isTrue(size < Long.BYTES * 8, "size is too large");
|
||||
+
|
||||
+ this.items = createArray(size);
|
||||
+ this.allBits = ((1L << size) - 1);
|
||||
+ }
|
||||
+
|
||||
+ public boolean isCompletelyEmpty() {
|
||||
+ return this.bitSet == 0;
|
||||
+ }
|
||||
+
|
||||
+ public boolean hasFullStacks() {
|
||||
+ return (this.bitSet & this.allBits) == allBits;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public ItemStack set(int index, @NotNull ItemStack itemStack) {
|
||||
+ ItemStack existing = this.items[index];
|
||||
+
|
||||
+ this.items[index] = itemStack;
|
||||
+
|
||||
+ if (itemStack == ItemStack.EMPTY) {
|
||||
+ this.bitSet &= ~(1L << index);
|
||||
+ } else {
|
||||
+ this.bitSet |= 1L << index;
|
||||
+ }
|
||||
+
|
||||
+ return existing;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ @Override
|
||||
+ public ItemStack get(int var0) {
|
||||
+ return this.items[var0];
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int size() {
|
||||
+ return this.items.length;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void clear() {
|
||||
+ Arrays.fill(this.items, ItemStack.EMPTY);
|
||||
+ }
|
||||
+
|
||||
+ // these are unsupported for block inventories which have a static size
|
||||
+ @Override
|
||||
+ public void add(int var0, ItemStack var1) {
|
||||
+ throw new UnsupportedOperationException();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public ItemStack remove(int var0) {
|
||||
+ throw new UnsupportedOperationException();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public String toString() {
|
||||
+ return "ItemListWithBitset{" +
|
||||
+ "items=" + Arrays.toString(items) +
|
||||
+ ", bitSet=" + Long.toString(bitSet, 2) +
|
||||
+ ", allBits=" + Long.toString(allBits, 2) +
|
||||
+ ", size=" + this.items.length +
|
||||
+ '}';
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/net/minecraft/world/CompoundContainer.java b/src/main/java/net/minecraft/world/CompoundContainer.java
|
||||
index 241fec02e6869c638d3a160819b32173a081467b..62848ca68f532fa14241320df76d180c13072c34 100644
|
||||
--- a/src/main/java/net/minecraft/world/CompoundContainer.java
|
||||
+++ b/src/main/java/net/minecraft/world/CompoundContainer.java
|
||||
@@ -64,6 +64,23 @@ public class CompoundContainer implements Container {
|
||||
this.container2 = second;
|
||||
}
|
||||
|
||||
+ // Kaiiju start - airplane - improve container checking with a bitset
|
||||
+ @Override
|
||||
+ public boolean hasEmptySlot(net.minecraft.core.Direction enumdirection) {
|
||||
+ return this.container1.hasEmptySlot(null) || this.container2.hasEmptySlot(null);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCompletelyFull(net.minecraft.core.Direction enumdirection) {
|
||||
+ return this.container1.isCompletelyFull(null) && this.container2.isCompletelyFull(null);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCompletelyEmpty(net.minecraft.core.Direction enumdirection) {
|
||||
+ return this.container1.isCompletelyEmpty(null) && this.container2.isCompletelyEmpty(null);
|
||||
+ }
|
||||
+ // Kaiiju end
|
||||
+
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return this.container1.getContainerSize() + this.container2.getContainerSize();
|
||||
diff --git a/src/main/java/net/minecraft/world/Container.java b/src/main/java/net/minecraft/world/Container.java
|
||||
index 04b1531572e8fff1e46fe1c94e7fc863841e0f66..ac1e21a4fc210424ea57c247d03914c54129de9c 100644
|
||||
--- a/src/main/java/net/minecraft/world/Container.java
|
||||
+++ b/src/main/java/net/minecraft/world/Container.java
|
||||
@@ -13,6 +13,63 @@ import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
||||
// CraftBukkit end
|
||||
|
||||
public interface Container extends Clearable {
|
||||
+ // Kaiiju start - airplane - allow the inventory to override and optimize these frequent calls
|
||||
+ default boolean hasEmptySlot(@org.jetbrains.annotations.Nullable net.minecraft.core.Direction enumdirection) { // there is a slot with 0 items in it
|
||||
+ if (this instanceof WorldlyContainer worldlyContainer) {
|
||||
+ for (int i : worldlyContainer.getSlotsForFace(enumdirection)) {
|
||||
+ if (this.getItem(i).isEmpty()) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ }
|
||||
+ } else {
|
||||
+ int size = this.getContainerSize();
|
||||
+ for (int i = 0; i < size; i++) {
|
||||
+ if (this.getItem(i).isEmpty()) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ default boolean isCompletelyFull(@org.jetbrains.annotations.Nullable net.minecraft.core.Direction enumdirection) { // every stack is maxed
|
||||
+ if (this instanceof WorldlyContainer worldlyContainer) {
|
||||
+ for (int i : worldlyContainer.getSlotsForFace(enumdirection)) {
|
||||
+ ItemStack itemStack = this.getItem(i);
|
||||
+ if (itemStack.getCount() < itemStack.getMaxStackSize()) {
|
||||
+ return false;
|
||||
+ }
|
||||
+ }
|
||||
+ } else {
|
||||
+ int size = this.getContainerSize();
|
||||
+ for (int i = 0; i < size; i++) {
|
||||
+ ItemStack itemStack = this.getItem(i);
|
||||
+ if (itemStack.getCount() < itemStack.getMaxStackSize()) {
|
||||
+ return false;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ default boolean isCompletelyEmpty(@org.jetbrains.annotations.Nullable net.minecraft.core.Direction enumdirection) {
|
||||
+ if (this instanceof WorldlyContainer worldlyContainer) {
|
||||
+ for (int i : worldlyContainer.getSlotsForFace(enumdirection)) {
|
||||
+ if (!this.getItem(i).isEmpty()) {
|
||||
+ return false;
|
||||
+ }
|
||||
+ }
|
||||
+ } else {
|
||||
+ int size = this.getContainerSize();
|
||||
+ for (int i = 0; i < size; i++) {
|
||||
+ if (!this.getItem(i).isEmpty()) {
|
||||
+ return false;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ return true;
|
||||
+ }
|
||||
+ // Kaiiju end
|
||||
|
||||
int LARGE_MAX_STACK_SIZE = 64;
|
||||
int DEFAULT_DISTANCE_LIMIT = 8;
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java
|
||||
index 272095d7a09ab41227d741172735f66fd2798ce1..1f2e2d7726abd63bb46697697c91696387c819a2 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java
|
||||
@@ -28,6 +28,7 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
public abstract class AbstractMinecartContainer extends AbstractMinecart implements ContainerEntity {
|
||||
|
||||
private NonNullList<ItemStack> itemStacks;
|
||||
+ private dev.kaiijumc.kaiiju.structs.ItemListWithBitset itemStacksOptimized; // Kaiiju - airplane - implement ItemListWithBitset
|
||||
@Nullable
|
||||
public ResourceLocation lootTable;
|
||||
public long lootTableSeed;
|
||||
@@ -89,12 +90,18 @@ public abstract class AbstractMinecartContainer extends AbstractMinecart impleme
|
||||
|
||||
protected AbstractMinecartContainer(EntityType<?> type, Level world) {
|
||||
super(type, world);
|
||||
- this.itemStacks = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); // CraftBukkit - SPIGOT-3513
|
||||
+ // Kaiiju start - airplane - use ItemListWithBitset
|
||||
+ this.itemStacksOptimized = new dev.kaiijumc.kaiiju.structs.ItemListWithBitset(this.getContainerSize()); // CraftBukkit - SPIGOT-3513
|
||||
+ this.itemStacks = this.itemStacksOptimized.nonNullList;
|
||||
+ // Kaiiju end
|
||||
}
|
||||
|
||||
protected AbstractMinecartContainer(EntityType<?> type, double x, double y, double z, Level world) {
|
||||
super(type, world, x, y, z);
|
||||
- this.itemStacks = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); // CraftBukkit - SPIGOT-3513
|
||||
+ // Kaiiju start - airplane - use ItemListWithBitset
|
||||
+ this.itemStacksOptimized = new dev.kaiijumc.kaiiju.structs.ItemListWithBitset(this.getContainerSize()); // CraftBukkit - SPIGOT-3513
|
||||
+ this.itemStacks = this.itemStacksOptimized.nonNullList;
|
||||
+ // Kaiiju end
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,6 +163,10 @@ public abstract class AbstractMinecartContainer extends AbstractMinecart impleme
|
||||
protected void readAdditionalSaveData(CompoundTag nbt) {
|
||||
super.readAdditionalSaveData(nbt);
|
||||
this.lootableData.loadNbt(nbt); // Paper
|
||||
+ // Kaiiju start - airplane - use ItemListWithBitset
|
||||
+ this.itemStacksOptimized = new dev.kaiijumc.kaiiju.structs.ItemListWithBitset(this.getContainerSize()); // CraftBukkit - SPIGOT-3513
|
||||
+ this.itemStacks = this.itemStacksOptimized.nonNullList;
|
||||
+ // Kaiiju end
|
||||
this.readChestVehicleSaveData(nbt);
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java
|
||||
index a71414397bd45ee7bcacfeef0041d80dfa25f114..67f69540e6c217070f8d2af8908d4eb6f2b5c1c1 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java
|
||||
@@ -31,6 +31,7 @@ import org.bukkit.entity.HumanEntity;
|
||||
public class ChestBlockEntity extends RandomizableContainerBlockEntity implements LidBlockEntity {
|
||||
|
||||
private static final int EVENT_SET_OPEN_COUNT = 1;
|
||||
+ private dev.kaiijumc.kaiiju.structs.ItemListWithBitset optimizedItems; // Kaiiju - airplane - implement ItemListWithBitset
|
||||
private NonNullList<ItemStack> items;
|
||||
public final ContainerOpenersCounter openersCounter;
|
||||
private final ChestLidController chestLidController;
|
||||
@@ -65,9 +66,14 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
+ private final boolean isNative = getClass().equals(ChestBlockEntity.class); // Kaiiju - airplane
|
||||
+
|
||||
protected ChestBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
- this.items = NonNullList.withSize(27, ItemStack.EMPTY);
|
||||
+ // Kaiiju start - airplane - use ItemListWithBitset
|
||||
+ this.optimizedItems = new dev.kaiijumc.kaiiju.structs.ItemListWithBitset(27);
|
||||
+ this.items = this.optimizedItems.nonNullList;
|
||||
+ // Kaiiju end
|
||||
this.openersCounter = new ContainerOpenersCounter() {
|
||||
@Override
|
||||
protected void onOpen(Level world, BlockPos pos, BlockState state) {
|
||||
@@ -98,6 +104,23 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement
|
||||
this.chestLidController = new ChestLidController();
|
||||
}
|
||||
|
||||
+ // Kaiiju start - airplane - improve container checking with a bitset
|
||||
+ @Override
|
||||
+ public boolean hasEmptySlot(Direction enumdirection) {
|
||||
+ return isNative ? !this.optimizedItems.hasFullStacks() : super.hasEmptySlot(enumdirection);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCompletelyFull(Direction enumdirection) {
|
||||
+ return isNative ? this.optimizedItems.hasFullStacks() && super.isCompletelyFull(enumdirection) : super.isCompletelyFull(enumdirection);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCompletelyEmpty(Direction enumdirection) {
|
||||
+ return isNative && this.optimizedItems.isCompletelyEmpty() || super.isCompletelyEmpty(enumdirection);
|
||||
+ }
|
||||
+ // Kaiiju end
|
||||
+
|
||||
public ChestBlockEntity(BlockPos pos, BlockState state) {
|
||||
this(BlockEntityType.CHEST, pos, state);
|
||||
}
|
||||
@@ -115,7 +138,10 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement
|
||||
@Override
|
||||
public void load(CompoundTag nbt) {
|
||||
super.load(nbt);
|
||||
- this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
|
||||
+ // Kaiiju start - airplane - use ItemListWithBitset
|
||||
+ this.optimizedItems = new dev.kaiijumc.kaiiju.structs.ItemListWithBitset(this.getContainerSize());
|
||||
+ this.items = this.optimizedItems.nonNullList;
|
||||
+ // Kaiiju end
|
||||
if (!this.tryLoadLootTable(nbt)) {
|
||||
ContainerHelper.loadAllItems(nbt, this.items);
|
||||
}
|
||||
@@ -187,7 +213,10 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement
|
||||
|
||||
@Override
|
||||
protected void setItems(NonNullList<ItemStack> list) {
|
||||
- this.items = list;
|
||||
+ // Kaiiju start - airplane - use ItemListWithBitset
|
||||
+ this.optimizedItems = dev.kaiijumc.kaiiju.structs.ItemListWithBitset.fromList(list);
|
||||
+ this.items = this.optimizedItems.nonNullList;
|
||||
+ // Kaiiju end
|
||||
}
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
||||
index 762b763f271c3208b4f8a7e346897207ec5beb6c..a212a62bc2b43b55e9040e2de8360d6e55a7dd86 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
||||
@@ -48,6 +48,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
||||
public static final int MOVE_ITEM_SPEED = 8;
|
||||
public static final int HOPPER_CONTAINER_SIZE = 5;
|
||||
private NonNullList<ItemStack> items;
|
||||
+ private dev.kaiijumc.kaiiju.structs.ItemListWithBitset optimizedItems; // Kaiiju - airplane - implement ItemListWithBitset
|
||||
private int cooldownTime;
|
||||
private long tickedGameTime;
|
||||
|
||||
@@ -83,14 +84,37 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
||||
|
||||
public HopperBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(BlockEntityType.HOPPER, pos, state);
|
||||
- this.items = NonNullList.withSize(5, ItemStack.EMPTY);
|
||||
+ // Kaiiju start - airplane - use ItemListWithBitset
|
||||
+ this.optimizedItems = new dev.kaiijumc.kaiiju.structs.ItemListWithBitset(5);
|
||||
+ this.items = this.optimizedItems.nonNullList;
|
||||
+ // Kaiiju end
|
||||
this.cooldownTime = -1;
|
||||
}
|
||||
|
||||
+ // Kaiiju start - airplane - improve container checking with a bitset
|
||||
+ @Override
|
||||
+ public boolean hasEmptySlot(Direction enumdirection) {
|
||||
+ return !this.optimizedItems.hasFullStacks();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCompletelyFull(Direction enumdirection) {
|
||||
+ return this.optimizedItems.hasFullStacks() && super.isCompletelyFull(enumdirection);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCompletelyEmpty(Direction enumdirection) {
|
||||
+ return this.optimizedItems.isCompletelyEmpty() || super.isCompletelyEmpty(enumdirection);
|
||||
+ }
|
||||
+ // Kaiiju end
|
||||
+
|
||||
@Override
|
||||
public void load(CompoundTag nbt) {
|
||||
super.load(nbt);
|
||||
- this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
|
||||
+ // Kaiiju start - airplane - use ItemListWithBitset
|
||||
+ this.optimizedItems = new dev.kaiijumc.kaiiju.structs.ItemListWithBitset(this.getContainerSize());
|
||||
+ this.items = this.optimizedItems.nonNullList;
|
||||
+ // Kaiiju end
|
||||
if (!this.tryLoadLootTable(nbt)) {
|
||||
ContainerHelper.loadAllItems(nbt, this.items);
|
||||
}
|
||||
@@ -162,7 +186,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
||||
flag = HopperBlockEntity.ejectItems(world, pos, state, (Container) blockEntity, blockEntity); // CraftBukkit
|
||||
}
|
||||
|
||||
- if (!blockEntity.inventoryFull()) {
|
||||
+ if (!blockEntity.optimizedItems.hasFullStacks() || !blockEntity.inventoryFull()) { // Kaiiju - airplane
|
||||
flag |= booleansupplier.getAsBoolean();
|
||||
}
|
||||
|
||||
@@ -455,11 +479,11 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
||||
}
|
||||
|
||||
private static boolean isFullContainer(Container inventory, Direction direction) {
|
||||
- return allMatch(inventory, direction, STACK_SIZE_TEST); // Paper - no streams
|
||||
+ return inventory.isCompletelyFull(direction); // Kaiiju - airplane - use bitsets
|
||||
}
|
||||
|
||||
private static boolean isEmptyContainer(Container inv, Direction facing) {
|
||||
- return allMatch(inv, facing, IS_EMPTY_TEST);
|
||||
+ return inv.isCompletelyEmpty(facing); // Kaiiju - airplane - use bitsets
|
||||
}
|
||||
|
||||
public static boolean suckInItems(Level world, Hopper hopper) {
|
||||
@@ -649,7 +673,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
||||
|
||||
if (HopperBlockEntity.canPlaceItemInContainer(to, stack, slot, side)) {
|
||||
boolean flag = false;
|
||||
- boolean flag1 = to.isEmpty();
|
||||
+ boolean flag1 = to.isCompletelyEmpty(side); // Kaiiju - airplane - use bitsets
|
||||
|
||||
if (itemstack1.isEmpty()) {
|
||||
// Spigot start - SPIGOT-6693, InventorySubcontainer#setItem
|
||||
@@ -844,7 +868,10 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
||||
|
||||
@Override
|
||||
protected void setItems(NonNullList<ItemStack> list) {
|
||||
- this.items = list;
|
||||
+ // Kaiiju start - airplane - use ItemListWithBitset
|
||||
+ this.optimizedItems = dev.kaiijumc.kaiiju.structs.ItemListWithBitset.fromList(list);
|
||||
+ this.items = this.optimizedItems.nonNullList;
|
||||
+ // Kaiiju end
|
||||
}
|
||||
|
||||
public static void entityInside(Level world, BlockPos pos, BlockState state, Entity entity, HopperBlockEntity blockEntity) {
|
||||
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 081691f9710ff1115e4308f79ed49fbc38941193..648e28c5fba5c62e65f83fbb5ebc8836ffb166a9 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
|
||||
@@ -95,14 +95,7 @@ public abstract class RandomizableContainerBlockEntity extends BaseContainerBloc
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
this.unpackLootTable((Player)null);
|
||||
- // Paper start
|
||||
- for (final ItemStack itemStack : this.getItems()) {
|
||||
- if (!itemStack.isEmpty()) {
|
||||
- return false;
|
||||
- }
|
||||
- }
|
||||
- return true;
|
||||
- // Paper end
|
||||
+ return this.isCompletelyEmpty(null); // Kaiiju - airplane - use super
|
||||
}
|
||||
|
||||
@Override
|
||||
Reference in New Issue
Block a user