mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-21 07:49:29 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@c0a3d51 Start update, apply API patches PaperMC/Paper@172c7dc Work PaperMC/Paper@ab9a3db More work PaperMC/Paper@c60e47f More more work PaperMC/Paper@bd55e32 More more more work PaperMC/Paper@5265287 More more more more work PaperMC/Paper@4601dc9 Some fixes, start updating CustomModelData API PaperMC/Paper@2331dad Even more work PaperMC/Paper@dc74c6f moonrise PaperMC/Paper@d7d2f88 Apply remaining patches, fix API PaperMC/Paper@f863bb7 Update generated classes PaperMC/Paper@71a4ef8 Set java launcher for api generate task PaperMC/Paper@b8aeecb Compilation fixes PaperMC/Paper@6c35392 Tests succeed (by removing one) PaperMC/Paper@b0603da Fix jd gson version, move back mc util diff PaperMC/Paper@e2dd1d5 Add back post_teleport chunk ticket PaperMC/Paper@7045b2a Update DataConverter PaperMC/Paper@65633e3 Update Moonrise
82 lines
3.4 KiB
Diff
82 lines
3.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Thu, 14 Oct 2021 19:16:49 +0100
|
|
Subject: [PATCH] Copy EntityList methods to BasicEntityList
|
|
|
|
|
|
diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
|
index d21ce54ebb5724c04eadf56a2cde701d5eeb5db2..1fad004f07270e8a27a85557de6fcf5e693751db 100644
|
|
--- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
|
+++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
|
@@ -383,6 +383,13 @@ public final class ChunkEntitySlices {
|
|
|
|
private E[] storage;
|
|
private int size;
|
|
+ // Sakura start - use methods from EntityList
|
|
+ private it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap entityToIndex = null;
|
|
+ private void setupIndexMap() {
|
|
+ this.entityToIndex = new it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap(2, 0.8f);
|
|
+ this.entityToIndex.defaultReturnValue(Integer.MIN_VALUE);
|
|
+ }
|
|
+ // Sakura end - use methods from EntityList
|
|
|
|
public BasicEntityList() {
|
|
this(0);
|
|
@@ -403,6 +410,7 @@ public final class ChunkEntitySlices {
|
|
private void resize() {
|
|
if (this.storage == EMPTY) {
|
|
this.storage = (E[])new Entity[DEFAULT_CAPACITY];
|
|
+ this.setupIndexMap(); // Sakura - use methods from EntityList
|
|
} else {
|
|
this.storage = Arrays.copyOf(this.storage, this.storage.length * 2);
|
|
}
|
|
@@ -416,6 +424,7 @@ public final class ChunkEntitySlices {
|
|
} else {
|
|
this.storage[idx] = entity;
|
|
}
|
|
+ this.entityToIndex.put(entity.getId(), idx); // Sakura - use methods from EntityList
|
|
}
|
|
|
|
public int indexOf(final E entity) {
|
|
@@ -431,24 +440,32 @@ public final class ChunkEntitySlices {
|
|
}
|
|
|
|
public boolean remove(final E entity) {
|
|
- final int idx = this.indexOf(entity);
|
|
- if (idx == -1) {
|
|
+ // Sakura start - use methods from EntityList
|
|
+ if (this.entityToIndex == null) {
|
|
return false;
|
|
}
|
|
|
|
- final int size = --this.size;
|
|
- final E[] storage = this.storage;
|
|
- if (idx != size) {
|
|
- System.arraycopy(storage, idx + 1, storage, idx, size - idx);
|
|
+ final int index = this.entityToIndex.remove(entity.getId());
|
|
+ if (index == Integer.MIN_VALUE) {
|
|
+ return false;
|
|
}
|
|
|
|
- storage[size] = null;
|
|
+ // move the entity at the end to this index
|
|
+ final int endIndex = --this.size;
|
|
+ final E end = this.storage[endIndex];
|
|
+ if (index != endIndex) {
|
|
+ // not empty after this call
|
|
+ this.entityToIndex.put(end.getId(), index); // update index
|
|
+ }
|
|
+ this.storage[index] = end;
|
|
+ this.storage[endIndex] = null;
|
|
+ // Sakura end - use methods from EntityList
|
|
|
|
return true;
|
|
}
|
|
|
|
public boolean has(final E entity) {
|
|
- return this.indexOf(entity) != -1;
|
|
+ return this.entityToIndex != null && this.entityToIndex.containsKey(entity.getId()); // Sakura - use methods from EntityList
|
|
}
|
|
}
|
|
|