Move around patches again

This commit is contained in:
Nassim Jahnke 2024-12-05 11:18:29 +01:00
parent c54c062e6f
commit e4e24f3335
No known key found for this signature in database
GPG key ID: EF6771C01F6EF02F
764 changed files with 730 additions and 709 deletions

View file

@ -2597,285 +2597,6 @@ index 0000000000000000000000000000000000000000..c2d917c2eac55b8a4411a6e159f177f9
+ ((Runnable)TO_RUN_HANDLE.getVolatile(this)).run();
+ }
+}
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java b/src/main/java/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
new file mode 100644
index 0000000000000000000000000000000000000000..7e440b4a46b040365df7317035e577d93e7d855d
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
@@ -0,0 +1,273 @@
+package ca.spottedleaf.moonrise.common.misc;
+
+import ca.spottedleaf.moonrise.common.list.ReferenceList;
+import ca.spottedleaf.moonrise.common.util.CoordinateUtils;
+import ca.spottedleaf.moonrise.common.util.MoonriseConstants;
+import ca.spottedleaf.moonrise.common.util.ChunkSystem;
+import ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemLevel;
+import ca.spottedleaf.moonrise.patches.chunk_system.level.chunk.ChunkData;
+import ca.spottedleaf.moonrise.patches.chunk_tick_iteration.ChunkTickConstants;
+import ca.spottedleaf.moonrise.patches.chunk_tick_iteration.ChunkTickServerLevel;
+import it.unimi.dsi.fastutil.longs.Long2ReferenceOpenHashMap;
+import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
+import net.minecraft.core.BlockPos;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.level.ChunkPos;
+import java.util.ArrayList;
+
+public final class NearbyPlayers {
+
+ public static enum NearbyMapType {
+ GENERAL,
+ GENERAL_SMALL,
+ GENERAL_REALLY_SMALL,
+ TICK_VIEW_DISTANCE,
+ VIEW_DISTANCE,
+ // Moonrise start - chunk tick iteration
+ SPAWN_RANGE {
+ @Override
+ void addTo(final ServerPlayer player, final ServerLevel world, final int chunkX, final int chunkZ) {
+ ((ChunkTickServerLevel)world).moonrise$addPlayerTickingRequest(chunkX, chunkZ);
+ }
+
+ @Override
+ void removeFrom(final ServerPlayer player, final ServerLevel world, final int chunkX, final int chunkZ) {
+ ((ChunkTickServerLevel)world).moonrise$removePlayerTickingRequest(chunkX, chunkZ);
+ }
+ };
+ // Moonrise end - chunk tick iteration
+
+ void addTo(final ServerPlayer player, final ServerLevel world, final int chunkX, final int chunkZ) {
+
+ }
+
+ void removeFrom(final ServerPlayer player, final ServerLevel world, final int chunkX, final int chunkZ) {
+
+ }
+ }
+
+ private static final NearbyMapType[] MAP_TYPES = NearbyMapType.values();
+ public static final int TOTAL_MAP_TYPES = MAP_TYPES.length;
+
+ private static final int GENERAL_AREA_VIEW_DISTANCE = MoonriseConstants.MAX_VIEW_DISTANCE + 1;
+ private static final int GENERAL_SMALL_VIEW_DISTANCE = 10;
+ private static final int GENERAL_REALLY_SMALL_VIEW_DISTANCE = 3;
+
+ public static final int GENERAL_AREA_VIEW_DISTANCE_BLOCKS = (GENERAL_AREA_VIEW_DISTANCE << 4);
+ public static final int GENERAL_SMALL_AREA_VIEW_DISTANCE_BLOCKS = (GENERAL_SMALL_VIEW_DISTANCE << 4);
+ public static final int GENERAL_REALLY_SMALL_AREA_VIEW_DISTANCE_BLOCKS = (GENERAL_REALLY_SMALL_VIEW_DISTANCE << 4);
+
+ private final ServerLevel world;
+ private final Reference2ReferenceOpenHashMap<ServerPlayer, TrackedPlayer[]> players = new Reference2ReferenceOpenHashMap<>();
+ private final Long2ReferenceOpenHashMap<TrackedChunk> byChunk = new Long2ReferenceOpenHashMap<>();
+ private final Long2ReferenceOpenHashMap<ReferenceList<ServerPlayer>>[] directByChunk = new Long2ReferenceOpenHashMap[TOTAL_MAP_TYPES];
+ {
+ for (int i = 0; i < this.directByChunk.length; ++i) {
+ this.directByChunk[i] = new Long2ReferenceOpenHashMap<>();
+ }
+ }
+
+ public NearbyPlayers(final ServerLevel world) {
+ this.world = world;
+ }
+
+ public void addPlayer(final ServerPlayer player) {
+ final TrackedPlayer[] newTrackers = new TrackedPlayer[TOTAL_MAP_TYPES];
+ if (this.players.putIfAbsent(player, newTrackers) != null) {
+ throw new IllegalStateException("Already have player " + player);
+ }
+
+ final ChunkPos chunk = player.chunkPosition();
+
+ for (int i = 0; i < TOTAL_MAP_TYPES; ++i) {
+ // use 0 for default, will be updated by tickPlayer
+ (newTrackers[i] = new TrackedPlayer(player, MAP_TYPES[i])).add(chunk.x, chunk.z, 0);
+ }
+
+ // update view distances
+ this.tickPlayer(player);
+ }
+
+ public void removePlayer(final ServerPlayer player) {
+ final TrackedPlayer[] players = this.players.remove(player);
+ if (players == null) {
+ return; // May be called during teleportation before the player is actually placed
+ }
+
+ for (final TrackedPlayer tracker : players) {
+ tracker.remove();
+ }
+ }
+
+ public void clear() {
+ if (this.players.isEmpty()) {
+ return;
+ }
+
+ for (final ServerPlayer player : new ArrayList<>(this.players.keySet())) {
+ this.removePlayer(player);
+ }
+ }
+
+ public void tickPlayer(final ServerPlayer player) {
+ final TrackedPlayer[] players = this.players.get(player);
+ if (players == null) {
+ throw new IllegalStateException("Don't have player " + player);
+ }
+
+ final ChunkPos chunk = player.chunkPosition();
+
+ players[NearbyMapType.GENERAL.ordinal()].update(chunk.x, chunk.z, GENERAL_AREA_VIEW_DISTANCE);
+ players[NearbyMapType.GENERAL_SMALL.ordinal()].update(chunk.x, chunk.z, GENERAL_SMALL_VIEW_DISTANCE);
+ players[NearbyMapType.GENERAL_REALLY_SMALL.ordinal()].update(chunk.x, chunk.z, GENERAL_REALLY_SMALL_VIEW_DISTANCE);
+ players[NearbyMapType.TICK_VIEW_DISTANCE.ordinal()].update(chunk.x, chunk.z, ChunkSystem.getTickViewDistance(player));
+ players[NearbyMapType.VIEW_DISTANCE.ordinal()].update(chunk.x, chunk.z, ChunkSystem.getViewDistance(player));
+ players[NearbyMapType.SPAWN_RANGE.ordinal()].update(chunk.x, chunk.z, ChunkTickConstants.PLAYER_SPAWN_TRACK_RANGE); // Moonrise - chunk tick iteration
+ }
+
+ public TrackedChunk getChunk(final ChunkPos pos) {
+ return this.byChunk.get(CoordinateUtils.getChunkKey(pos));
+ }
+
+ public TrackedChunk getChunk(final BlockPos pos) {
+ return this.byChunk.get(CoordinateUtils.getChunkKey(pos));
+ }
+
+ public TrackedChunk getChunk(final int chunkX, final int chunkZ) {
+ return this.byChunk.get(CoordinateUtils.getChunkKey(chunkX, chunkZ));
+ }
+
+ public ReferenceList<ServerPlayer> getPlayers(final BlockPos pos, final NearbyMapType type) {
+ return this.directByChunk[type.ordinal()].get(CoordinateUtils.getChunkKey(pos));
+ }
+
+ public ReferenceList<ServerPlayer> getPlayers(final ChunkPos pos, final NearbyMapType type) {
+ return this.directByChunk[type.ordinal()].get(CoordinateUtils.getChunkKey(pos));
+ }
+
+ public ReferenceList<ServerPlayer> getPlayersByChunk(final int chunkX, final int chunkZ, final NearbyMapType type) {
+ return this.directByChunk[type.ordinal()].get(CoordinateUtils.getChunkKey(chunkX, chunkZ));
+ }
+
+ public ReferenceList<ServerPlayer> getPlayersByBlock(final int blockX, final int blockZ, final NearbyMapType type) {
+ return this.directByChunk[type.ordinal()].get(CoordinateUtils.getChunkKey(blockX >> 4, blockZ >> 4));
+ }
+
+ public static final class TrackedChunk {
+
+ private static final ServerPlayer[] EMPTY_PLAYERS_ARRAY = new ServerPlayer[0];
+
+ private final long chunkKey;
+ private final NearbyPlayers nearbyPlayers;
+ private final ReferenceList<ServerPlayer>[] players = new ReferenceList[TOTAL_MAP_TYPES];
+ private int nonEmptyLists;
+ private long updateCount;
+
+ public TrackedChunk(final long chunkKey, final NearbyPlayers nearbyPlayers) {
+ this.chunkKey = chunkKey;
+ this.nearbyPlayers = nearbyPlayers;
+ }
+
+ public boolean isEmpty() {
+ return this.nonEmptyLists == 0;
+ }
+
+ public long getUpdateCount() {
+ return this.updateCount;
+ }
+
+ public ReferenceList<ServerPlayer> getPlayers(final NearbyMapType type) {
+ return this.players[type.ordinal()];
+ }
+
+ public void addPlayer(final ServerPlayer player, final NearbyMapType type) {
+ ++this.updateCount;
+
+ final int idx = type.ordinal();
+ final ReferenceList<ServerPlayer> list = this.players[idx];
+ if (list == null) {
+ ++this.nonEmptyLists;
+ final ReferenceList<ServerPlayer> players = (this.players[idx] = new ReferenceList<>(EMPTY_PLAYERS_ARRAY));
+ this.nearbyPlayers.directByChunk[idx].put(this.chunkKey, players);
+ players.add(player);
+ return;
+ }
+
+ if (!list.add(player)) {
+ throw new IllegalStateException("Already contains player " + player);
+ }
+ }
+
+ public void removePlayer(final ServerPlayer player, final NearbyMapType type) {
+ ++this.updateCount;
+
+ final int idx = type.ordinal();
+ final ReferenceList<ServerPlayer> list = this.players[idx];
+ if (list == null) {
+ throw new IllegalStateException("Does not contain player " + player);
+ }
+
+ if (!list.remove(player)) {
+ throw new IllegalStateException("Does not contain player " + player);
+ }
+
+ if (list.size() == 0) {
+ this.players[idx] = null;
+ this.nearbyPlayers.directByChunk[idx].remove(this.chunkKey);
+ --this.nonEmptyLists;
+ }
+ }
+ }
+
+ private final class TrackedPlayer extends SingleUserAreaMap<ServerPlayer> {
+
+ private final NearbyMapType type;
+
+ public TrackedPlayer(final ServerPlayer player, final NearbyMapType type) {
+ super(player);
+ this.type = type;
+ }
+
+ @Override
+ protected void addCallback(final ServerPlayer parameter, final int chunkX, final int chunkZ) {
+ final long chunkKey = CoordinateUtils.getChunkKey(chunkX, chunkZ);
+
+ final TrackedChunk chunk = NearbyPlayers.this.byChunk.get(chunkKey);
+ final NearbyMapType type = this.type;
+ if (chunk != null) {
+ chunk.addPlayer(parameter, type);
+ type.addTo(parameter, NearbyPlayers.this.world, chunkX, chunkZ);
+ } else {
+ final TrackedChunk created = new TrackedChunk(chunkKey, NearbyPlayers.this);
+ NearbyPlayers.this.byChunk.put(chunkKey, created);
+ created.addPlayer(parameter, type);
+ type.addTo(parameter, NearbyPlayers.this.world, chunkX, chunkZ);
+
+ ((ChunkSystemLevel)NearbyPlayers.this.world).moonrise$requestChunkData(chunkKey).nearbyPlayers = created;
+ }
+ }
+
+ @Override
+ protected void removeCallback(final ServerPlayer parameter, final int chunkX, final int chunkZ) {
+ final long chunkKey = CoordinateUtils.getChunkKey(chunkX, chunkZ);
+
+ final TrackedChunk chunk = NearbyPlayers.this.byChunk.get(chunkKey);
+ if (chunk == null) {
+ throw new IllegalStateException("Chunk should exist at " + new ChunkPos(chunkKey));
+ }
+
+ final NearbyMapType type = this.type;
+ chunk.removePlayer(parameter, type);
+ type.removeFrom(parameter, NearbyPlayers.this.world, chunkX, chunkZ);
+
+ if (chunk.isEmpty()) {
+ NearbyPlayers.this.byChunk.remove(chunkKey);
+ final ChunkData chunkData = ((ChunkSystemLevel)NearbyPlayers.this.world).moonrise$releaseChunkData(chunkKey);
+ if (chunkData != null) {
+ chunkData.nearbyPlayers = null;
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/misc/PositionCountingAreaMap.java b/src/main/java/ca/spottedleaf/moonrise/common/misc/PositionCountingAreaMap.java
new file mode 100644
index 0000000000000000000000000000000000000000..90560769d09538f7a740753a41a3b8e017b0b92a
@ -5625,7 +5346,7 @@ index 9cdcab885a915990a679f3fc9ae6885f7d125bfd..3e35a64b4b92ec25789e85c7445375dd
boolean flag1 = this.chunkMap.promoteChunkMap();
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index ecbef5d54aef8e3f3bc2e4c34d2da6e96b1267b8..cba44ea8375692ce9d2511fba1ac1dd1d2d0cb1e 100644
index 7ccf5329d6c4db1a9cfb78f07d5bdf982185240f..ca112107e2c3b66f18b0a4517dc85bc4c95888dc 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -240,6 +240,103 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe

View file

@ -302,10 +302,10 @@ index 0000000000000000000000000000000000000000..95d6022c9cfb2e36ec5a71be6e343540
+ }
+}
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index 2bd7f0554bdf668930c990156f65e97e4b64d8bc..6a2af3cd3aebe525a5ff41a801929547d59b8fec 100644
index f4fa64ab18573cb9a22a9bfb79a351c388d1aaa5..df51c80b73e9922e4b0a1f2291ebabbb74d809ff 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -221,6 +221,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -215,6 +215,7 @@ public class ServerChunkCache extends ChunkSource {
Objects.requireNonNull(completablefuture);
chunkproviderserver_b.managedBlock(completablefuture::isDone);
@ -314,7 +314,7 @@ index 2bd7f0554bdf668930c990156f65e97e4b64d8bc..6a2af3cd3aebe525a5ff41a801929547
ChunkAccess ichunkaccess1 = (ChunkAccess) chunkresult.orElse(null); // CraftBukkit - decompile error
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 6430e759c3d89033418f79c7f7aacb8ca5a5135b..578d284a3e39368c5285eafe84056b081a240e3d 100644
index 6b97e29b0102b5521cba424f008478245c67d85f..5b47505353bf96bcb555910d1ebf645d14052f46 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -416,6 +416,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe

View file

@ -5,7 +5,7 @@ Subject: [PATCH] Add option to nerf pigmen from nether portals
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index e932bd4c922d7015bba0ef06e349d74f5c1a209c..a330a603349f7f9d694cef66f67ba465e3110a1c 100644
index 2179f631bf410297db2438e587f4b5ecb7ebc218..dcc6543f895c9bbf09301e64164873aa54c7b8b5 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -407,6 +407,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess

View file

@ -10,7 +10,7 @@ When not per player it will use the Vanilla mechanic of one delay per
world and the world age for the start day.
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index a624cab05e9a4308a7f887f9edcf0ec1555f94a8..df409f2dc2c49282f128a9fdd9c248a2f6d9a7c9 100644
index 9b194fcae767647b719ca687d0574ef74dc310da..6a282b80e062a0dd769c0d94357bce9a40240200 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -295,6 +295,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {

View file

@ -7,7 +7,7 @@ Causes sync chunk loads and who knows what all else.
This is safe because Spectators are skipped in unloaded chunks too in vanilla.
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index df409f2dc2c49282f128a9fdd9c248a2f6d9a7c9..957266d14ce2b9b99f7c97289458fc837e4d665a 100644
index 6a282b80e062a0dd769c0d94357bce9a40240200..4d73ccb30fde83497405b6a6a788f69e0349aec1 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -990,7 +990,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {

View file

@ -13,7 +13,7 @@ By skipping this, we avoid potential for a large spike on server start.
public net.minecraft.server.level.ServerPlayer fudgeSpawnLocation(Lnet/minecraft/server/level/ServerLevel;)V
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 957266d14ce2b9b99f7c97289458fc837e4d665a..21f7b26bbf2b3e231032b7a09fa6e82f8244f495 100644
index 4d73ccb30fde83497405b6a6a788f69e0349aec1..be5ca29b0c8e1a78fc84885bb4b1c112fefdb63b 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -417,7 +417,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {

View file

@ -5,7 +5,7 @@ Subject: [PATCH] Prevent opening inventories when frozen
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 21f7b26bbf2b3e231032b7a09fa6e82f8244f495..ba6dbbd56f5b0c2eb5566172e64fbf258f146ef0 100644
index be5ca29b0c8e1a78fc84885bb4b1c112fefdb63b..01afc19c566c07a1e57b57ab37d0df6095a64eac 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -935,7 +935,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {

View file

@ -88,7 +88,7 @@ index 0000000000000000000000000000000000000000..b6f4400df3d8ec7e06a996de54f8cabb
+ }
+}
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index ba6dbbd56f5b0c2eb5566172e64fbf258f146ef0..d00d43697d7fc5b7fa162fd4e773f21fb5594087 100644
index 01afc19c566c07a1e57b57ab37d0df6095a64eac..0efa13f8eff9458318f462e42fdbffe90e21d814 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -418,7 +418,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {

View file

@ -43,7 +43,7 @@ index 914e9e0af7533cbf487ea0413da447d5eb8d527b..69f54e812794b23e5f54606da86f7116
EntityType<?> entitytypes = entity.getType();
int i = entitytypes.clientTrackingRange() * 16;
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index d00d43697d7fc5b7fa162fd4e773f21fb5594087..07b1bc1a06ac1fec83ba76a73b3cc1bd8f560208 100644
index 0efa13f8eff9458318f462e42fdbffe90e21d814..b1340a5021991d09a0f4a6ad4ce5d7389feb1175 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -315,6 +315,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {

View file

@ -84,7 +84,7 @@ index 8239b9e2e1f5aa4f961aa40513f308f2fe44e7ef..f11bea4618757ac8060098ab7a7a2642
}
// Paper end - Entity#getEntitySpawnReason
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index a330a603349f7f9d694cef66f67ba465e3110a1c..e5c280df931fc712e41f4decfeb2871b870d2e4a 100644
index dcc6543f895c9bbf09301e64164873aa54c7b8b5..bccd5d2ef5cdc01d2785231d47ec17481f87f2cb 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2528,27 +2528,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess

View file

@ -16,7 +16,7 @@ So even if something NEW comes up, it would be impossible to drop the
same item twice because the source was destroyed.
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index e5c280df931fc712e41f4decfeb2871b870d2e4a..c48f634fe80919cb1c2c4d2c1fd647dc63c87749 100644
index bccd5d2ef5cdc01d2785231d47ec17481f87f2cb..2dc87373d687c04f89c7a3b033c8a188ba415904 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2656,11 +2656,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess

View file

@ -18,7 +18,7 @@ index d5ad109d2deb4fe756924ebaac4091017beb6b99..cc0a3c29aeb67e486fb75c1d6cc28019
testImplementation("org.hamcrest:hamcrest:2.2")
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java b/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java
new file mode 100644
index 0000000000000000000000000000000000000000..36621b42f0dbca9d82a2ca284f30fd9eceab166e
index 0000000000000000000000000000000000000000..99d0118061233eced90ca5aed2eb5ff0b188837b
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java
@@ -0,0 +1,379 @@
@ -317,7 +317,7 @@ index 0000000000000000000000000000000000000000..36621b42f0dbca9d82a2ca284f30fd9e
+ public static EnumSet<GoalType> vanillaToPaper(Goal goal) {
+ EnumSet<GoalType> goals = EnumSet.noneOf(GoalType.class);
+ for (GoalType type : GoalType.values()) {
+ if (goal.getFlags().hasElement(paperToVanilla(type))) {
+ if (goal.hasFlag(paperToVanilla(type))) {
+ goals.add(type);
+ }
+ }
@ -403,7 +403,7 @@ index 0000000000000000000000000000000000000000..36621b42f0dbca9d82a2ca284f30fd9e
+}
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/PaperCustomGoal.java b/src/main/java/com/destroystokyo/paper/entity/ai/PaperCustomGoal.java
new file mode 100644
index 0000000000000000000000000000000000000000..26c745dd9ccdfdd5c5039f2acc5201b9b91fb274
index 0000000000000000000000000000000000000000..2625ff0d8fa1fb2b5166326dc729bc41b054779b
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/PaperCustomGoal.java
@@ -0,0 +1,53 @@
@ -423,7 +423,7 @@ index 0000000000000000000000000000000000000000..26c745dd9ccdfdd5c5039f2acc5201b9
+
+ this.setFlags(MobGoalHelper.paperToVanilla(handle.getTypes()));
+ if (this.getFlags().size() == 0) {
+ this.getFlags().addUnchecked(Flag.UNKNOWN_BEHAVIOR);
+ this.addFlag(Flag.UNKNOWN_BEHAVIOR);
+ }
+ }
+
@ -462,7 +462,7 @@ index 0000000000000000000000000000000000000000..26c745dd9ccdfdd5c5039f2acc5201b9
+}
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/PaperMobGoals.java b/src/main/java/com/destroystokyo/paper/entity/ai/PaperMobGoals.java
new file mode 100644
index 0000000000000000000000000000000000000000..e8a427ea777af040d0e2b9cc0ba2a80b9176d026
index 0000000000000000000000000000000000000000..7e72fbb1659327452a2a1c665fd852b53670c85d
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/PaperMobGoals.java
@@ -0,0 +1,226 @@
@ -587,7 +587,7 @@ index 0000000000000000000000000000000000000000..e8a427ea777af040d0e2b9cc0ba2a80b
+ CraftMob craftMob = (CraftMob) mob;
+ Set<Goal<T>> goals = new HashSet<>();
+ for (WrappedGoal item : getHandle(craftMob, type).getAvailableGoals()) {
+ if (!item.getGoal().getFlags().hasElement(MobGoalHelper.paperToVanilla(type))) {
+ if (!item.getGoal().hasFlag(MobGoalHelper.paperToVanilla(type))) {
+ continue;
+ }
+
@ -610,7 +610,7 @@ index 0000000000000000000000000000000000000000..e8a427ea777af040d0e2b9cc0ba2a80b
+ continue;
+ }
+ for (WrappedGoal item : getHandle(craftMob, internalType).getAvailableGoals()) {
+ if (item.getGoal().getFlags().hasElement(MobGoalHelper.paperToVanilla(type))) {
+ if (item.getGoal().hasFlag(MobGoalHelper.paperToVanilla(type))) {
+ continue;
+ }
+
@ -640,7 +640,7 @@ index 0000000000000000000000000000000000000000..e8a427ea777af040d0e2b9cc0ba2a80b
+ Set<Goal<T>> goals = new HashSet<>();
+ getHandle(craftMob, type).getAvailableGoals()
+ .stream().filter(WrappedGoal::isRunning)
+ .filter(item -> item.getGoal().getFlags().hasElement(MobGoalHelper.paperToVanilla(type)))
+ .filter(item -> item.getGoal().hasFlag(MobGoalHelper.paperToVanilla(type)))
+ .forEach(item -> {
+ if (item.getGoal() instanceof PaperCustomGoal) {
+ //noinspection unchecked
@ -663,7 +663,7 @@ index 0000000000000000000000000000000000000000..e8a427ea777af040d0e2b9cc0ba2a80b
+ getHandle(craftMob, internalType).getAvailableGoals()
+ .stream()
+ .filter(WrappedGoal::isRunning)
+ .filter(item -> !item.getGoal().getFlags().hasElement(MobGoalHelper.paperToVanilla(type)))
+ .filter(item -> !item.getGoal().hasFlag(MobGoalHelper.paperToVanilla(type)))
+ .forEach(item -> {
+ if (item.getGoal() instanceof PaperCustomGoal) {
+ //noinspection unchecked
@ -760,10 +760,27 @@ index 0000000000000000000000000000000000000000..b5c594a5499556ad452d9939c75e150a
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/Goal.java b/src/main/java/net/minecraft/world/entity/ai/goal/Goal.java
index a8d6d7054110b5d95830296699f004418dae10db..acc25b08ed3b9f978229fa017d23f9fa0da519e3 100644
index a8d6d7054110b5d95830296699f004418dae10db..7a98d6e0d7e9b8d3967bf9498fd25a0c3148e039 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/Goal.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/Goal.java
@@ -62,7 +62,19 @@ public abstract class Goal {
@@ -46,6 +46,16 @@ public abstract class Goal {
return this.flags;
}
+ // Paper start - Mob Goal API
+ public boolean hasFlag(final Goal.Flag flag) {
+ return this.flags.contains(flag);
+ }
+
+ public void addFlag(final Goal.Flag flag) {
+ this.flags.add(flag);
+ }
+ // Paper end - Mob Goal API
+
protected int adjustedTickDelay(int ticks) {
return this.requiresUpdateEveryTick() ? ticks : reducedTickDelay(ticks);
}
@@ -62,7 +72,19 @@ public abstract class Goal {
return (ServerLevel)world;
}

View file

@ -6,7 +6,7 @@ Subject: [PATCH] Ensure Entity position and AABB are never invalid
Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index c48f634fe80919cb1c2c4d2c1fd647dc63c87749..3860265a50b62fbd36c9e1b32680c3b62d5342a6 100644
index 2dc87373d687c04f89c7a3b033c8a188ba415904..abcdb8d082dd0bbcd60c1d0d924b6774dd196ea7 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -678,8 +678,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess

View file

@ -9,7 +9,7 @@ instead of getting stuck in a never despawn state (bubble columns,
etc).
diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
index a05fc651a952b57a8a2fcb32d26d024875037d38..52765e1b9f5a026e7108ff5a7d97681cdb2870e9 100644
index 2b4df4e417b5655341a640a1c133457f78338970..6637da7a1c17152e8fc5f0f12d8da55bab6070de 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
@@ -244,6 +244,7 @@ public abstract class AbstractArrow extends Projectile {

View file

@ -5,7 +5,7 @@ Subject: [PATCH] Brand support
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 07b1bc1a06ac1fec83ba76a73b3cc1bd8f560208..475ad396d842617b53ccf59fd07bfe1682852e50 100644
index b1340a5021991d09a0f4a6ad4ce5d7389feb1175..ed2164d8c652b135f9cb777f1a6242bcfec36bbc 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -320,6 +320,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {

View file

@ -22,7 +22,7 @@ index eab19d5ac362c4779e91fad0ede3e4c26f29ab01..0d7dae5fa79cd302d73d1be51d8bf908
this.lastGoodY = this.awaitingPositionFromClient.y;
this.lastGoodZ = this.awaitingPositionFromClient.z;
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 3860265a50b62fbd36c9e1b32680c3b62d5342a6..e93f8a9eefc082d66d0e1804c98d0df7db914cd8 100644
index abcdb8d082dd0bbcd60c1d0d924b6774dd196ea7..d871b45ea22f1f2019ca1d1e0708d8861daec633 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -180,6 +180,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess

View file

@ -6,7 +6,7 @@ Subject: [PATCH] Extend block drop capture to capture all items added to the
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index f01fe053888f7f5124c6b157044dfd46ea98ae23..1ed0940d8bdc4210992a335b3691c1cd3a13580a 100644
index d32606cba7222aa538cca3882314f9f87f33684f..f6b91771445ab4f48525f24025a9f5249f176cd5 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -1199,6 +1199,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe

View file

@ -6,7 +6,7 @@ Subject: [PATCH] Expose the Entity Counter to allow plugins to use valid and
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index e93f8a9eefc082d66d0e1804c98d0df7db914cd8..56e4a5316e873c0a6fc3495bbfba6dc503cc9c9c 100644
index d871b45ea22f1f2019ca1d1e0708d8861daec633..b8e63ccc00668713e5759aaf04597359870397f3 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4760,4 +4760,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess

View file

@ -5,7 +5,7 @@ Subject: [PATCH] Entity#isTicking
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 56e4a5316e873c0a6fc3495bbfba6dc503cc9c9c..7609a58979388cb62be7ae94a51cc14774464214 100644
index b8e63ccc00668713e5759aaf04597359870397f3..1efaae5d9dab0bbcc2bbef772eb0f5cdf8ff384c 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4765,5 +4765,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess

Some files were not shown because too many files have changed in this diff Show more