Skip to content

Commit 745881b

Browse files
committed
Update Moonrise common for 1.21.5
1 parent a1c4fc9 commit 745881b

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

paper-server/src/main/java/ca/spottedleaf/moonrise/common/list/IteratorSafeOrderedReferenceSet.java

+24-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import it.unimi.dsi.fastutil.objects.Reference2IntLinkedOpenHashMap;
44
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
5+
import java.lang.reflect.Array;
56
import java.util.Arrays;
67
import java.util.NoSuchElementException;
78

@@ -21,15 +22,34 @@ public final class IteratorSafeOrderedReferenceSet<E> {
2122
private int iteratorCount;
2223

2324
public IteratorSafeOrderedReferenceSet() {
24-
this(16, 0.75f, 16, 0.2);
25+
this(Object.class);
26+
}
27+
28+
public IteratorSafeOrderedReferenceSet(final Class<? super E> arrComponent) {
29+
this(16, 0.75f, 16, 0.2, arrComponent);
2530
}
2631

2732
public IteratorSafeOrderedReferenceSet(final int setCapacity, final float setLoadFactor, final int arrayCapacity,
2833
final double maxFragFactor) {
34+
this(setCapacity, setLoadFactor, arrayCapacity, maxFragFactor, Object.class);
35+
}
36+
37+
public IteratorSafeOrderedReferenceSet(final int setCapacity, final float setLoadFactor, final int arrayCapacity,
38+
final double maxFragFactor, final Class<? super E> arrComponent) {
2939
this.indexMap = new Reference2IntLinkedOpenHashMap<>(setCapacity, setLoadFactor);
3040
this.indexMap.defaultReturnValue(-1);
3141
this.maxFragFactor = maxFragFactor;
32-
this.listElements = (E[])new Object[arrayCapacity];
42+
this.listElements = (E[])Array.newInstance(arrComponent, arrayCapacity);
43+
}
44+
45+
// includes null (gravestone) elements
46+
public E[] getListRaw() {
47+
return this.listElements;
48+
}
49+
50+
// includes null (gravestone) elements
51+
public int getListSize() {
52+
return this.listSize;
3353
}
3454

3555
/*
@@ -81,7 +101,7 @@ private double getFragFactor() {
81101
public int createRawIterator() {
82102
++this.iteratorCount;
83103
if (this.indexMap.isEmpty()) {
84-
return -1;
104+
return Integer.MAX_VALUE;
85105
} else {
86106
return this.firstInvalidIndex == 0 ? this.indexMap.getInt(this.indexMap.firstKey()) : 0;
87107
}
@@ -96,7 +116,7 @@ public int advanceRawIterator(final int index) {
96116
}
97117
}
98118

99-
return -1;
119+
return Integer.MAX_VALUE;
100120
}
101121

102122
public void finishRawIterator() {
@@ -205,10 +225,6 @@ public E getKey() {
205225
//this.check();
206226
}
207227

208-
public E rawGet(final int index) {
209-
return this.listElements[index];
210-
}
211-
212228
public int size() {
213229
// always returns the correct amount - listSize can be different
214230
return this.indexMap.size();

paper-server/src/main/java/ca/spottedleaf/moonrise/common/misc/PositionCountingAreaMap.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ca.spottedleaf.moonrise.common.misc;
22

3-
import ca.spottedleaf.concurrentutil.util.IntPairUtil;
3+
import ca.spottedleaf.moonrise.common.util.CoordinateUtils;
44
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
55
import it.unimi.dsi.fastutil.longs.LongSet;
66
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
@@ -23,12 +23,16 @@ public int getTotalPositions() {
2323
return this.positions.size();
2424
}
2525

26+
public boolean hasObjectsNear(final long pos) {
27+
return this.positions.containsKey(pos);
28+
}
29+
2630
public boolean hasObjectsNear(final int toX, final int toZ) {
27-
return this.positions.containsKey(IntPairUtil.key(toX, toZ));
31+
return this.positions.containsKey(CoordinateUtils.getChunkKey(toX, toZ));
2832
}
2933

3034
public int getObjectsNear(final int toX, final int toZ) {
31-
return this.positions.get(IntPairUtil.key(toX, toZ));
35+
return this.positions.get(CoordinateUtils.getChunkKey(toX, toZ));
3236
}
3337

3438
public boolean add(final T parameter, final int toX, final int toZ, final int distance) {
@@ -85,12 +89,12 @@ public PositionCounter(final T parameter) {
8589

8690
@Override
8791
protected void addCallback(final T parameter, final int toX, final int toZ) {
88-
PositionCountingAreaMap.this.positions.addTo(IntPairUtil.key(toX, toZ), 1);
92+
PositionCountingAreaMap.this.positions.addTo(CoordinateUtils.getChunkKey(toX, toZ), 1);
8993
}
9094

9195
@Override
9296
protected void removeCallback(final T parameter, final int toX, final int toZ) {
93-
final long key = IntPairUtil.key(toX, toZ);
97+
final long key = CoordinateUtils.getChunkKey(toX, toZ);
9498
if (PositionCountingAreaMap.this.positions.addTo(key, -1) == 1) {
9599
PositionCountingAreaMap.this.positions.remove(key);
96100
}

paper-server/src/main/java/ca/spottedleaf/moonrise/common/misc/SingleUserAreaMap.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package ca.spottedleaf.moonrise.common.misc;
22

3-
import ca.spottedleaf.concurrentutil.util.IntegerUtil;
4-
53
public abstract class SingleUserAreaMap<T> {
64

75
public static final int NOT_SET = Integer.MIN_VALUE;
@@ -99,8 +97,8 @@ public final boolean update(final int toX, final int toZ, final int newViewDista
9997
final int dx = toX - fromX;
10098
final int dz = toZ - fromZ;
10199

102-
final int totalX = IntegerUtil.branchlessAbs(fromX - toX);
103-
final int totalZ = IntegerUtil.branchlessAbs(fromZ - toZ);
100+
final int totalX = Math.abs(fromX - toX);
101+
final int totalZ = Math.abs(fromZ - toZ);
104102

105103
if (Math.max(totalX, totalZ) > (2 * Math.max(newViewDistance, oldViewDistance))) {
106104
// teleported
@@ -120,7 +118,7 @@ public final boolean update(final int toX, final int toZ, final int newViewDista
120118
for (int currZ = oldMinZ; currZ <= oldMaxZ; ++currZ) {
121119

122120
// only remove if we're outside the new view distance...
123-
if (Math.max(IntegerUtil.branchlessAbs(currX - toX), IntegerUtil.branchlessAbs(currZ - toZ)) > newViewDistance) {
121+
if (Math.max(Math.abs(currX - toX), Math.abs(currZ - toZ)) > newViewDistance) {
124122
this.removeCallback(parameter, currX, currZ);
125123
}
126124
}
@@ -136,7 +134,7 @@ public final boolean update(final int toX, final int toZ, final int newViewDista
136134
for (int currZ = newMinZ; currZ <= newMaxZ; ++currZ) {
137135

138136
// only add if we're outside the old view distance...
139-
if (Math.max(IntegerUtil.branchlessAbs(currX - fromX), IntegerUtil.branchlessAbs(currZ - fromZ)) > oldViewDistance) {
137+
if (Math.max(Math.abs(currX - fromX), Math.abs(currZ - fromZ)) > oldViewDistance) {
140138
this.addCallback(parameter, currX, currZ);
141139
}
142140
}

paper-server/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystemHooks.java

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.minecraft.server.level.FullChunkStatus;
66
import net.minecraft.server.level.ServerLevel;
77
import net.minecraft.server.level.ServerPlayer;
8+
import net.minecraft.server.level.TicketType;
89
import net.minecraft.world.entity.Entity;
910
import net.minecraft.world.level.chunk.ChunkAccess;
1011
import net.minecraft.world.level.chunk.LevelChunk;
@@ -74,4 +75,6 @@ public void scheduleTickingState(final ServerLevel level, final int chunkX, fina
7475
public void removePlayerFromDistanceMaps(final ServerLevel world, final ServerPlayer player);
7576

7677
public void updateMaps(final ServerLevel world, final ServerPlayer player);
78+
79+
public long[] getCounterTypesUncached(final TicketType type);
7780
}

0 commit comments

Comments
 (0)