Compare commits

...

30 Commits

Author SHA1 Message Date
Sofiane H. Djerbi
1271516e58 Async path processor bugfixes
Fix villager AI (and other mobs)
Fix piston stacktrace & piston breaking pathfinding
2023-08-06 06:07:10 +02:00
Sofiane H. Djerbi
0648cb49c8 Patch cleanup 2023-08-05 03:07:45 +02:00
Sofiane H. Djerbi
35a7588d6d Fix entity <=> obsidian platform spawn sync 2023-08-05 03:05:19 +02:00
Sofiane H. Djerbi
dc4931389b Pathfinding fixes
Fix shulker boxes breaking pathfinding
Fix petal memory leak
Remove the thread queue
2023-08-05 03:01:51 +02:00
Sofiane H. Djerbi
eb6be9f290 Fix container bitset implementation 2023-08-01 15:57:58 +02:00
Sofiane H. Djerbi
6d12ac828a Update config defaults 2023-08-01 13:49:43 +02:00
Sofiane H. Djerbi
baf0a46d91 Add airplane hopper optimization 2023-08-01 13:21:05 +02:00
Sofiane H. Djerbi
32a11498b4 Don't remove named entities 2023-08-01 02:59:59 +02:00
Sofiane H. Djerbi
8eb4a79492 Avoid manipulating null paths 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
f8abc46b5e Final changes 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
1594847f93 Set default queue to 1000 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
fd71bdebd5 Log async threads for pathfinding 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
a3c8b4a2b7 Add NodeEvaluatorType and use it in cache 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
d514f5744a 0 threads if not enabled 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
dbd96e6e84 Add thread options & improve thread control 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
6669139413 Fix TargetGoal autism 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
4327944b97 Remove redundant isDone call (Raise exception) 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
b869fc44e0 Add async pathfinding to warden 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
423b2078e8 Add processing check back 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
a6cd4d115e Add async pathfinding to WaterBound mobs & Strider 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
7e70bc76d9 Rework nodeEvaluatorGenerator cache 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
fd509ffe21 Rebase nodeEvaluatorGenerator 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
28de4d3178 [skip ci] credit peaches94 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
67b061cda6 Fix mob in the water issue 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
243f57f124 Use the correct thread context to postprocess path 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
c66ed11b44 Use local pool 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
4edf6f9cd3 Base asyncpathprocessing patch from petal 2023-08-01 02:56:46 +02:00
Sofiane H. Djerbi
09e0f58125 Update config 2023-07-31 01:11:56 +02:00
Sofiane H. Djerbi
a95080aaff Update README.md 2023-07-31 00:13:59 +02:00
kugge
794ce3b533 Update Upstream (Folia) 2023-07-26 13:30:47 +02:00
9 changed files with 1837 additions and 28 deletions

View File

@@ -11,30 +11,46 @@
## Features
### Primary
- **Xymb Linear Format**: Saves about 50% of disk space in OW/Nether and 95% in The End.
- **Auto update**: Automatic upstream updates.
### Notable
- **Entity throttling & removal**: Tweak entity tick frequency & max entity per region.
- **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...
### Other
- **Small optimizations**: Increase server efficiency by disabling unnecessary features.
- **Commands**: Restore few commands that were previously removed by Folia.
### Configuration
```yaml
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
gameplay:
server-mod-name: Kaiiju
shared-random-for-players: true
async-path-processing:
enable: false
max-threads: 0
keepalive: 60
queue-capacity: 4096
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:
@@ -42,25 +58,22 @@ 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
- **Static view distance**: Reduce RAM usage / Region size with a "static" view distance.
- **Native world conversion**: Convert region file format at startup.
- **Stash deduplication**: Make giant dupe stashes possible and lagless.
- **Multithreaded Tracker**: Rework Petal multithreaded tracker.
## Open to contributions
- **Native world conversion**: Convert region file format at startup.
- **Performance patch**: Any significative performance patch.
## Building

View File

@@ -2,7 +2,7 @@ group = dev.kaiijumc.kaiiju
version = 1.20.1-R0.1-SNAPSHOT
mcVersion = 1.20.1
foliaRef = daacd4255022f3a1bf74dd3e84f751be838678ac
foliaRef = b2d7bdb0bb5c841b4ccd096c0181664664ce97b1
org.gradle.caching=true
org.gradle.parallel=true

View File

@@ -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 61c6bc2859235874aefac71e9e55162f0a89f29f..24bd63c596c9f61f1e89ec5b001b7cb7a29a09ff 100644
index c4d28d887b4cc71dc713b1e3f46bc80f4484a95d..f50507ab85282d261985ce9b186581f5a7a50f79 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 61c6bc2859235874aefac71e9e55162f0a89f29f..24bd63c596c9f61f1e89ec5b001b7cb7
// 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 4774d3f357d62b0818b4713f8085d05be09eaa5c..1bbd8b475cdc57fb15ca05ffe122220a5539da10 100644
index 7099a44a2322ab390c21e74668c8657dcc9e5e87..475554797ffc279243ac0d88f1e619c3dd07bc4b 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 {

View File

@@ -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 1bbd8b475cdc57fb15ca05ffe122220a5539da10..7f39e36037d55278d15399196459e51b885c5d1e 100644
index 475554797ffc279243ac0d88f1e619c3dd07bc4b..475d0f3dd38e0407fa120d57e7d89216836538dd 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 {

View File

@@ -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 7f39e36037d55278d15399196459e51b885c5d1e..66509fa23bfcde70abd3917eb774cf48d5d6da93 100644
index 475d0f3dd38e0407fa120d57e7d89216836538dd..245c3e63588379f51780963ba91bc6bf0a3feda6 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 {

View File

@@ -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..761019f86983daaea4fface519e052f8fb6de1cd 100644
index 245c3e63588379f51780963ba91bc6bf0a3feda6..6efc8b37d4ee929522f5646c972565b99aa45de3 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..761019f86983daaea4fface519e052f8
+ // Kaiiju start
+ if (kaiijuConfig.enableEntityThrottling) {
+ dev.kaiijumc.kaiiju.KaiijuEntityThrottler.EntityThrottlerReturn throttle = regionizedWorldData.entityThrottler.tickLimiterShouldSkip(entity);
+ if (throttle.remove) entity.remove(Entity.RemovalReason.DISCARDED);
+ if (throttle.remove && !entity.hasCustomName()) entity.remove(Entity.RemovalReason.DISCARDED);
+ if (throttle.skip) return;
+ }
+ // Kaiiju end

View File

@@ -5,12 +5,15 @@ Subject: [PATCH] Vanilla end portal teleportation
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index b971f35b69a930dddcf603207f524dc95e09f0fd..135573308662845ecc73fde1c620345e1f372538 100644
index b971f35b69a930dddcf603207f524dc95e09f0fd..03895d35c02ff9422aaa0177eb0aa40e03fdc925 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4031,10 +4031,15 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -4029,12 +4029,17 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
targetPos, 16, // load 16 blocks to be safe from block physics
ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.HIGH,
(chunks) -> {
ServerLevel.makeObsidianPlatform(destination, null, targetPos);
- ServerLevel.makeObsidianPlatform(destination, null, targetPos);
+ //ServerLevel.makeObsidianPlatform(destination, null, targetPos); // Kaiiju - Vanilla end teleportation - moved down
+ // Kaiiju start - Vanilla end teleportation
+ Vec3 finalPos;
@@ -25,3 +28,23 @@ index b971f35b69a930dddcf603207f524dc95e09f0fd..135573308662845ecc73fde1c620345e
);
}
);
@@ -4221,6 +4226,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
if (!this.canPortalAsync(takePassengers)) {
return false;
}
+ // Kaiiju start - sync end platform spawning & entity teleportation
+ final java.util.function.Consumer<Entity> tpComplete = type == PortalType.END && destination.getTypeKey() == LevelStem.END ?
+ e -> ServerLevel.makeObsidianPlatform(destination, null, ServerLevel.END_SPAWN_POINT) : teleportComplete;
+ // Kaiiju end
Vec3 initialPosition = this.position();
ChunkPos initialPositionChunk = new ChunkPos(
@@ -4279,7 +4288,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
// place
passengerTree.root.placeInAsync(
originWorld, destination, Entity.TELEPORT_FLAG_LOAD_CHUNK | (takePassengers ? Entity.TELEPORT_FLAG_TELEPORT_PASSENGERS : 0L),
- passengerTree, teleportComplete
+ passengerTree, tpComplete // Kaiiju - vanilla end teleportation
);
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,458 @@
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