From 02eec3bcd04072cb99957274dd40ea789b0bafe4 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke <nassim@njahnke.dev> Date: Thu, 25 Apr 2024 11:42:10 +0200 Subject: [PATCH] Patches --- a.sh | 9 +++++ .../Allow-Saving-of-Oversized-Chunks.patch | 12 +++--- .../{unapplied => }/server/Anti-Xray.patch | 17 ++++---- .../server/Entity-Activation-Range-2.0.patch | 18 ++++----- .../Entity-load-save-limit-per-chunk.patch | 0 .../Fix-World-isChunkGenerated-calls.patch | 9 ++--- .../Flat-bedrock-generator-settings.patch | 0 ...item-frames-performance-and-bug-fixe.patch | 8 ++-- ...ng-PreCreatureSpawnEvent-with-per-pl.patch | 2 +- ...ptimize-Collision-to-not-load-chunks.patch | 2 +- ...oalSelector-Goal.Flag-Set-operations.patch | 39 +++++-------------- ...-Manager-and-add-advanced-packet-sup.patch | 31 ++++++++------- ...ldBounds-and-getBlockState-for-inlin.patch | 0 .../Optional-per-player-mob-spawns.patch | 2 +- ...cing-for-EntityLiving-hasLineOfSight.patch | 0 .../incremental-chunk-and-player-saving.patch | 0 ...x-and-optimise-world-force-upgrading.patch | 21 +++++----- 17 files changed, 81 insertions(+), 89 deletions(-) create mode 100644 a.sh rename patches/{unapplied => }/server/Allow-Saving-of-Oversized-Chunks.patch (94%) rename patches/{unapplied => }/server/Anti-Xray.patch (98%) rename patches/{unapplied => }/server/Entity-Activation-Range-2.0.patch (98%) rename patches/{unapplied => }/server/Entity-load-save-limit-per-chunk.patch (100%) rename patches/{unapplied => }/server/Fix-World-isChunkGenerated-calls.patch (97%) rename patches/{unapplied => }/server/Flat-bedrock-generator-settings.patch (100%) rename patches/{unapplied => }/server/Improve-Maps-in-item-frames-performance-and-bug-fixe.patch (92%) rename patches/{unapplied => }/server/Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch (98%) rename patches/{unapplied => }/server/Optimize-Collision-to-not-load-chunks.patch (98%) rename patches/{unapplied => }/server/Optimize-GoalSelector-Goal.Flag-Set-operations.patch (85%) rename patches/{unapplied => }/server/Optimize-Network-Manager-and-add-advanced-packet-sup.patch (95%) rename patches/{unapplied => }/server/Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch (100%) rename patches/{unapplied => }/server/Optional-per-player-mob-spawns.patch (99%) rename patches/{unapplied => }/server/Strip-raytracing-for-EntityLiving-hasLineOfSight.patch (100%) rename patches/{unapplied => }/server/incremental-chunk-and-player-saving.patch (100%) diff --git a/a.sh b/a.sh new file mode 100644 index 0000000000..5e98c3969f --- /dev/null +++ b/a.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +cd patches/server + + +for file in [0-9][0-9][0-9][0-9]-*.patch; do + suffix=$(echo $file | cut -d'-' -f2-) + mv "$file" "$suffix" +done diff --git a/patches/unapplied/server/Allow-Saving-of-Oversized-Chunks.patch b/patches/server/Allow-Saving-of-Oversized-Chunks.patch similarity index 94% rename from patches/unapplied/server/Allow-Saving-of-Oversized-Chunks.patch rename to patches/server/Allow-Saving-of-Oversized-Chunks.patch index cbbbdb1967..8de7939ac8 100644 --- a/patches/unapplied/server/Allow-Saving-of-Oversized-Chunks.patch +++ b/patches/server/Allow-Saving-of-Oversized-Chunks.patch @@ -43,6 +43,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import java.util.zip.InflaterInputStream; // Paper import javax.annotation.Nullable; import net.minecraft.Util; + import net.minecraft.resources.ResourceLocation; + import net.minecraft.util.profiling.jfr.JvmProfiler; +import net.minecraft.nbt.CompoundTag; // Paper +import net.minecraft.nbt.NbtIo; // Paper import net.minecraft.world.level.ChunkPos; @@ -54,17 +56,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public final java.util.concurrent.locks.ReentrantLock fileLock = new java.util.concurrent.locks.ReentrantLock(); // Paper + public final Path regionFile; // Paper - public RegionFile(Path file, Path directory, boolean dsync) throws IOException { - this(file, directory, RegionFileVersion.getCompressionFormat(), dsync); // Paper - Configurable region compression format + public RegionFile(RegionStorageInfo storageKey, Path directory, Path path, boolean dsync) throws IOException { + this(storageKey, directory, path, RegionFileVersion.getCompressionFormat(), dsync); // Paper - Configurable region compression format @@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable { - public RegionFile(Path file, Path directory, RegionFileVersion outputChunkStreamVersion, boolean dsync) throws IOException { + public RegionFile(RegionStorageInfo storageKey, Path path, Path directory, RegionFileVersion compressionFormat, boolean dsync) throws IOException { this.header = ByteBuffer.allocateDirect(8192); + this.regionFile = file; // Paper + initOversizedState(); // Paper this.usedSectors = new RegionBitmap(); - this.version = outputChunkStreamVersion; - if (!Files.isDirectory(directory, new LinkOption[0])) { + this.info = storageKey; + this.path = path; @@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable { } diff --git a/patches/unapplied/server/Anti-Xray.patch b/patches/server/Anti-Xray.patch similarity index 98% rename from patches/unapplied/server/Anti-Xray.patch rename to patches/server/Anti-Xray.patch index c80d6dbd41..ec7db61198 100644 --- a/patches/unapplied/server/Anti-Xray.patch +++ b/patches/server/Anti-Xray.patch @@ -1102,7 +1102,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + chunk.getLevel().chunkPacketBlockController.modifyBlocks(this, chunkPacketInfo); // Paper - Anti-Xray - Modify blocks } - public ClientboundLevelChunkWithLightPacket(FriendlyByteBuf buf) { + private ClientboundLevelChunkWithLightPacket(RegistryFriendlyByteBuf buf) { diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java @@ -1522,21 +1522,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 private static final String TAG_UPGRADE_DATA = "UpgradeData"; private static final String BLOCK_TICKS_TAG = "block_ticks"; @@ -0,0 +0,0 @@ public class ChunkSerializer { + if (k >= 0 && k < achunksection.length) { - Logger logger; PalettedContainer datapaletteblock; + // Paper start - Anti-Xray - Add preset block states + BlockState[] presetBlockStates = world.chunkPacketBlockController.getPresetBlockStates(world, chunkPos, b0); if (nbttagcompound1.contains("block_states", 10)) { -- dataresult = ChunkSerializer.BLOCK_STATE_CODEC.parse(NbtOps.INSTANCE, nbttagcompound1.getCompound("block_states")).promotePartial((s) -> { +- datapaletteblock = (PalettedContainer) ChunkSerializer.BLOCK_STATE_CODEC.parse(NbtOps.INSTANCE, nbttagcompound1.getCompound("block_states")).promotePartial((s) -> { + Codec<PalettedContainer<BlockState>> blockStateCodec = presetBlockStates == null ? ChunkSerializer.BLOCK_STATE_CODEC : PalettedContainer.codecRW(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState(), presetBlockStates); -+ dataresult = blockStateCodec.parse(NbtOps.INSTANCE, nbttagcompound1.getCompound("block_states")).promotePartial((s) -> { ++ datapaletteblock = blockStateCodec.parse(NbtOps.INSTANCE, nbttagcompound1.getCompound("block_states")).promotePartial((s) -> { ChunkSerializer.logErrors(chunkPos, b0, s); - }); - logger = ChunkSerializer.LOGGER; - Objects.requireNonNull(logger); - datapaletteblock = (PalettedContainer) ((DataResult<PalettedContainer<BlockState>>) dataresult).getOrThrow(false, logger::error); // CraftBukkit - decompile error + }).getOrThrow(ChunkSerializer.ChunkReadException::new); } else { - datapaletteblock = new PalettedContainer<>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES); + datapaletteblock = new PalettedContainer<>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES, presetBlockStates); @@ -1545,8 +1542,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 PalettedContainer object; // CraftBukkit - read/write @@ -0,0 +0,0 @@ public class ChunkSerializer { - Objects.requireNonNull(logger); - object = ((DataResult<PalettedContainer<Holder<Biome>>>) dataresult).getOrThrow(false, logger::error); // CraftBukkit - decompile error + ChunkSerializer.logErrors(chunkPos, b0, s); + }).getOrThrow(ChunkSerializer.ChunkReadException::new); } else { - object = new PalettedContainer<>(iregistry.asHolderIdMap(), iregistry.getHolderOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES); + object = new PalettedContainer<>(iregistry.asHolderIdMap(), iregistry.getHolderOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES, null); // Paper - Anti-Xray - Add preset biomes diff --git a/patches/unapplied/server/Entity-Activation-Range-2.0.patch b/patches/server/Entity-Activation-Range-2.0.patch similarity index 98% rename from patches/unapplied/server/Entity-Activation-Range-2.0.patch rename to patches/server/Entity-Activation-Range-2.0.patch index fcb0b85dc4..eff138f01c 100644 --- a/patches/unapplied/server/Entity-Activation-Range-2.0.patch +++ b/patches/server/Entity-Activation-Range-2.0.patch @@ -114,7 +114,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/jav index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java -@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess // Spigot end protected int numCollisions = 0; // Paper - Cap entity collisions public boolean fromNetherPortal; // Paper - Add option to nerf pigmen from nether portals @@ -123,7 +123,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public boolean spawnedViaMobSpawner; // Paper - Yes this name is similar to above, upstream took the better one // Paper start - Entity origin API @javax.annotation.Nullable -@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess } else { this.wasOnFire = this.isOnFire(); if (movementType == MoverType.PISTON) { @@ -132,7 +132,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 movement = this.limitPistonMovement(movement); if (movement.equals(Vec3.ZERO)) { return; -@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess this.stuckSpeedMultiplier = Vec3.ZERO; this.setDeltaMovement(Vec3.ZERO); } @@ -150,7 +150,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/n index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/Mob.java +++ b/src/main/java/net/minecraft/world/entity/Mob.java -@@ -0,0 +0,0 @@ public abstract class Mob extends LivingEntity implements Targeting { +@@ -0,0 +0,0 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti return this.lookControl; } @@ -187,9 +187,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java +++ b/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java @@ -0,0 +0,0 @@ public class GoalSelector { + private final Set<WrappedGoal> availableGoals = new ObjectLinkedOpenHashSet<>(); + private final Supplier<ProfilerFiller> profiler; private final EnumSet<Goal.Flag> disabledFlags = EnumSet.noneOf(Goal.Flag.class); - private int tickCount; - private int newGoalRate = 3; + private int curRate; public GoalSelector(Supplier<ProfilerFiller> profiler) { @@ -201,7 +201,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start + public boolean inactiveTick() { + this.curRate++; -+ return this.curRate % this.newGoalRate == 0; ++ return this.curRate % 3 == 0; // TODO newGoalRate was already unused in 1.20.4, check if this is correct + } + public boolean hasTasks() { + for (WrappedGoal task : this.availableGoals) { @@ -213,8 +213,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + // Paper end public void removeGoal(Goal goal) { - this.availableGoals.stream().filter(wrappedGoal -> wrappedGoal.getGoal() == goal).filter(WrappedGoal::isRunning).forEach(WrappedGoal::stop); - this.availableGoals.removeIf(wrappedGoal -> wrappedGoal.getGoal() == goal); + for (WrappedGoal wrappedGoal : this.availableGoals) { + if (wrappedGoal.getGoal() == goal && wrappedGoal.isRunning()) { diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java b/src/main/java/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java diff --git a/patches/unapplied/server/Entity-load-save-limit-per-chunk.patch b/patches/server/Entity-load-save-limit-per-chunk.patch similarity index 100% rename from patches/unapplied/server/Entity-load-save-limit-per-chunk.patch rename to patches/server/Entity-load-save-limit-per-chunk.patch diff --git a/patches/unapplied/server/Fix-World-isChunkGenerated-calls.patch b/patches/server/Fix-World-isChunkGenerated-calls.patch similarity index 97% rename from patches/unapplied/server/Fix-World-isChunkGenerated-calls.patch rename to patches/server/Fix-World-isChunkGenerated-calls.patch index b6d154b052..3edf49eab4 100644 --- a/patches/unapplied/server/Fix-World-isChunkGenerated-calls.patch +++ b/patches/server/Fix-World-isChunkGenerated-calls.patch @@ -94,9 +94,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java +++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java @@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable { + protected final RegionBitmap usedSectors; public final java.util.concurrent.locks.ReentrantLock fileLock = new java.util.concurrent.locks.ReentrantLock(); // Paper public final Path regionFile; // Paper - + // Paper start - Cache chunk status + private final net.minecraft.world.level.chunk.ChunkStatus[] statuses = new net.minecraft.world.level.chunk.ChunkStatus[32 * 32]; + @@ -120,10 +120,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return this.statuses[location]; + } + // Paper end - Cache chunk status -+ - public RegionFile(Path file, Path directory, boolean dsync) throws IOException { - this(file, directory, RegionFileVersion.getCompressionFormat(), dsync); // Paper - Configurable region compression format - } + + public RegionFile(RegionStorageInfo storageKey, Path directory, Path path, boolean dsync) throws IOException { + this(storageKey, directory, path, RegionFileVersion.getCompressionFormat(), dsync); // Paper - Configurable region compression format @@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable { return this.getOffset(pos) != 0; } diff --git a/patches/unapplied/server/Flat-bedrock-generator-settings.patch b/patches/server/Flat-bedrock-generator-settings.patch similarity index 100% rename from patches/unapplied/server/Flat-bedrock-generator-settings.patch rename to patches/server/Flat-bedrock-generator-settings.patch diff --git a/patches/unapplied/server/Improve-Maps-in-item-frames-performance-and-bug-fixe.patch b/patches/server/Improve-Maps-in-item-frames-performance-and-bug-fixe.patch similarity index 92% rename from patches/unapplied/server/Improve-Maps-in-item-frames-performance-and-bug-fixe.patch rename to patches/server/Improve-Maps-in-item-frames-performance-and-bug-fixe.patch index a386f50ef5..c71f4125e3 100644 --- a/patches/unapplied/server/Improve-Maps-in-item-frames-performance-and-bug-fixe.patch +++ b/patches/server/Improve-Maps-in-item-frames-performance-and-bug-fixe.patch @@ -69,8 +69,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } + worldmap.vanillaRender.buffer = abyte; // Paper - ListTag nbttaglist = nbt.getList("banners", 10); - + RegistryOps<Tag> registryops = registryLookup.createSerializationContext(NbtOps.INSTANCE); + List<MapBanner> list = (List) MapBanner.LIST_CODEC.parse(registryops, nbt.get("banners")).resultOrPartial((s) -> { @@ -0,0 +0,0 @@ public class MapItemSavedData extends SavedData { public class HoldingPlayer { @@ -95,7 +95,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 private int minDirtyX; @@ -0,0 +0,0 @@ public class MapItemSavedData extends SavedData { @Nullable - Packet<?> nextUpdatePacket(int mapId) { + Packet<?> nextUpdatePacket(MapId mapId) { MapItemSavedData.MapPatch worldmap_b; - org.bukkit.craftbukkit.map.RenderData render = MapItemSavedData.this.mapView.render((org.bukkit.craftbukkit.entity.CraftPlayer) this.player.getBukkitEntity()); // CraftBukkit + if (!this.dirtyData && this.tick % 5 != 0) { this.tick++; return null; } // Paper - this won't end up sending, so don't render it! @@ -112,7 +112,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + for (org.bukkit.map.MapCursor cursor : render.cursors) { if (cursor.isVisible()) { - icons.add(new MapDecoration(MapDecoration.Type.byIcon(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), PaperAdventure.asVanilla(cursor.caption()))); // Paper - Adventure + icons.add(new MapDecoration(CraftMapCursor.CraftType.bukkitToMinecraftHolder(cursor.getType()), cursor.getX(), cursor.getY(), cursor.getDirection(), Optional.ofNullable(PaperAdventure.asVanilla(cursor.caption())))); diff --git a/src/main/java/org/bukkit/craftbukkit/map/RenderData.java b/src/main/java/org/bukkit/craftbukkit/map/RenderData.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/map/RenderData.java diff --git a/patches/unapplied/server/Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch b/patches/server/Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch similarity index 98% rename from patches/unapplied/server/Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch rename to patches/server/Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch index 46f04adf86..dc8263f9a1 100644 --- a/patches/unapplied/server/Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch +++ b/patches/server/Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch @@ -70,7 +70,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public final int[] mobBackoffCounts = new int[MOBCATEGORY_TOTAL_ENUMS]; // Paper - per player mob count backoff // CraftBukkit start - public String displayName; + public CraftPlayer.TransferCookieConnection transferCookieConnection; diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java diff --git a/patches/unapplied/server/Optimize-Collision-to-not-load-chunks.patch b/patches/server/Optimize-Collision-to-not-load-chunks.patch similarity index 98% rename from patches/unapplied/server/Optimize-Collision-to-not-load-chunks.patch rename to patches/server/Optimize-Collision-to-not-load-chunks.patch index 30fdb6dee4..77e847fc71 100644 --- a/patches/unapplied/server/Optimize-Collision-to-not-load-chunks.patch +++ b/patches/server/Optimize-Collision-to-not-load-chunks.patch @@ -29,7 +29,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/jav index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java -@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason; // Paper - Entity#getEntitySpawnReason public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper diff --git a/patches/unapplied/server/Optimize-GoalSelector-Goal.Flag-Set-operations.patch b/patches/server/Optimize-GoalSelector-Goal.Flag-Set-operations.patch similarity index 85% rename from patches/unapplied/server/Optimize-GoalSelector-Goal.Flag-Set-operations.patch rename to patches/server/Optimize-GoalSelector-Goal.Flag-Set-operations.patch index c14d5b29a7..40021f6b09 100644 --- a/patches/unapplied/server/Optimize-GoalSelector-Goal.Flag-Set-operations.patch +++ b/patches/server/Optimize-GoalSelector-Goal.Flag-Set-operations.patch @@ -63,52 +63,33 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +++ b/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java @@ -0,0 +0,0 @@ public class GoalSelector { private final Map<Goal.Flag, WrappedGoal> lockedFlags = new EnumMap<>(Goal.Flag.class); - private final Set<WrappedGoal> availableGoals = Sets.newLinkedHashSet(); + private final Set<WrappedGoal> availableGoals = new ObjectLinkedOpenHashSet<>(); private final Supplier<ProfilerFiller> profiler; - private final EnumSet<Goal.Flag> disabledFlags = EnumSet.noneOf(Goal.Flag.class); -+ private final EnumSet<Goal.Flag> disabledFlags = EnumSet.noneOf(Goal.Flag.class); // Paper unused, but dummy to prevent plugins from crashing as hard. Theyll need to support paper in a special case if this is super important, but really doesn't seem like it would be. -+ private final com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<net.minecraft.world.entity.ai.goal.Goal.Flag> goalTypes = new com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<>(Goal.Flag.class); // Paper - remove streams from pathfindergoalselector - private int tickCount; - private int newGoalRate = 3; - private int curRate; + private static final Goal.Flag[] GOAL_FLAG_VALUES = Goal.Flag.values(); // Paper - remove streams from pathfindergoalselector ++ private final com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<net.minecraft.world.entity.ai.goal.Goal.Flag> goalTypes = new com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<>(Goal.Flag.class); // Paper - remove streams from pathfindergoalselector + private int curRate; public GoalSelector(Supplier<ProfilerFiller> profiler) { - this.profiler = profiler; @@ -0,0 +0,0 @@ public class GoalSelector { + this.availableGoals.removeIf(wrappedGoalx -> wrappedGoalx.getGoal() == goal); } - // Paper end - public void removeGoal(Goal goal) { -- this.availableGoals.stream().filter(wrappedGoal -> wrappedGoal.getGoal() == goal).filter(WrappedGoal::isRunning).forEach(WrappedGoal::stop); -- this.availableGoals.removeIf(wrappedGoal -> wrappedGoal.getGoal() == goal); -- } -- + - private static boolean goalContainsAnyFlags(WrappedGoal goal, EnumSet<Goal.Flag> controls) { - for (Goal.Flag flag : goal.getFlags()) { - if (controls.contains(flag)) { - return true; -+ // Paper start - remove streams from pathfindergoalselector -+ for (java.util.Iterator<WrappedGoal> iterator = this.availableGoals.iterator(); iterator.hasNext();) { -+ WrappedGoal goalWrapped = iterator.next(); -+ if (goalWrapped.getGoal() != goal) { -+ continue; - } -+ if (goalWrapped.isRunning()) { -+ goalWrapped.stop(); -+ } -+ iterator.remove(); - } -+ // Paper end - remove streams from pathfindergoalselector -+ } - +- } +- } +- - return false; ++ // Paper start + private static boolean goalContainsAnyFlags(WrappedGoal goal, com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<Goal.Flag> controls) { -+ return goal.getFlags().hasCommonElements(controls); // Paper ++ return goal.getFlags().hasCommonElements(controls); } private static boolean goalCanBeReplacedForAllFlags(WrappedGoal goal, Map<Goal.Flag, WrappedGoal> goalsByControl) { - for (Goal.Flag flag : goal.getFlags()) { -+ // Paper start + long flagIterator = goal.getFlags().getBackingSet(); + int wrappedGoalSize = goal.getFlags().size(); + for (int i = 0; i < wrappedGoalSize; ++i) { diff --git a/patches/unapplied/server/Optimize-Network-Manager-and-add-advanced-packet-sup.patch b/patches/server/Optimize-Network-Manager-and-add-advanced-packet-sup.patch similarity index 95% rename from patches/unapplied/server/Optimize-Network-Manager-and-add-advanced-packet-sup.patch rename to patches/server/Optimize-Network-Manager-and-add-advanced-packet-sup.patch index 2f74ef2a24..871d7b9217 100644 --- a/patches/unapplied/server/Optimize-Network-Manager-and-add-advanced-packet-sup.patch +++ b/patches/server/Optimize-Network-Manager-and-add-advanced-packet-sup.patch @@ -32,11 +32,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/net/minecraft/network/Connection.java +++ b/src/main/java/net/minecraft/network/Connection.java @@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> { - return new DefaultEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Local Client IO #%d").setDaemon(true).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(LOGGER)).build()); // Paper - }); + private static final ProtocolInfo<ServerHandshakePacketListener> INITIAL_PROTOCOL = HandshakeProtocols.SERVERBOUND; private final PacketFlow receiving; + private volatile boolean sendLoginDisconnect = true; - private final Queue<Consumer<Connection>> pendingActions = Queues.newConcurrentLinkedQueue(); -+ private final Queue<WrappedConsumer> pendingActions = Queues.newConcurrentLinkedQueue(); ++ private final Queue<WrappedConsumer> pendingActions = Queues.newConcurrentLinkedQueue(); // Paper public Channel channel; public SocketAddress address; // Spigot Start @@ -81,7 +81,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } else { + final java.util.List<PacketSendAction> actions = new java.util.ArrayList<>(1 + extraPackets.size()); + actions.add(new PacketSendAction(packet, null, false)); // Delay the future listener until the end of the extra packets - ++ + for (int i = 0, len = extraPackets.size(); i < len;) { + final Packet<?> extraPacket = extraPackets.get(i); + final boolean end = ++i == len; @@ -90,7 +90,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + this.pendingActions.addAll(actions); + } -+ + + this.flushQueue(); + // Paper end - Optimize network + } @@ -148,7 +148,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } @@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> { - return attributekey; + } - private void flushQueue() { @@ -239,7 +239,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 final PacketListener packetListener = this.getPacketListener(); if (packetListener instanceof net.minecraft.server.network.ServerCommonPacketListenerImpl commonPacketListener) { @@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> { - public void setBandwidthLogger(SampleLogger log) { + public void setBandwidthLogger(LocalSampleLogger log) { this.bandwidthDebugMonitor = new BandwidthDebugMonitor(log); } + @@ -337,9 +337,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/net/minecraft/network/protocol/Packet.java +++ b/src/main/java/net/minecraft/network/protocol/Packet.java @@ -0,0 +0,0 @@ public interface Packet<T extends PacketListener> { - void handle(T listener); - - // Paper start + static <B extends ByteBuf, T extends Packet<?>> StreamCodec<B, T> codec(StreamMemberEncoder<B, T> encoder, StreamDecoder<B, T> decoder) { + return StreamCodec.ofMember(encoder, decoder); + } ++ ++ // Paper start + /** + * @param player Null if not at PLAY stage yet + */ @@ -364,9 +366,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + default java.util.List<Packet<?>> getExtraPackets() { + return null; + } - default boolean packetTooLarge(net.minecraft.network.Connection manager) { - return false; - } ++ // Paper end + } diff --git a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java @@ -389,6 +390,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } + if (!disableFlushConsolidation) channel.pipeline().addFirst(new io.netty.handler.flush.FlushConsolidationHandler()); // Paper - Optimize network - ChannelPipeline channelpipeline = channel.pipeline().addLast("timeout", new ReadTimeoutHandler(30)).addLast("legacy_query", new LegacyQueryHandler(ServerConnectionListener.this.getServer())); + ChannelPipeline channelpipeline = channel.pipeline().addLast("timeout", new ReadTimeoutHandler(30)); - Connection.configureSerialization(channelpipeline, PacketFlow.SERVERBOUND, (BandwidthDebugMonitor) null); + if (ServerConnectionListener.this.server.repliesToStatus()) { diff --git a/patches/unapplied/server/Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch b/patches/server/Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch similarity index 100% rename from patches/unapplied/server/Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch rename to patches/server/Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch diff --git a/patches/unapplied/server/Optional-per-player-mob-spawns.patch b/patches/server/Optional-per-player-mob-spawns.patch similarity index 99% rename from patches/unapplied/server/Optional-per-player-mob-spawns.patch rename to patches/server/Optional-per-player-mob-spawns.patch index 710b6cf8f5..f1a39c78d3 100644 --- a/patches/unapplied/server/Optional-per-player-mob-spawns.patch +++ b/patches/server/Optional-per-player-mob-spawns.patch @@ -77,7 +77,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper end - Optional per player mob spawns // CraftBukkit start - public String displayName; + public CraftPlayer.TransferCookieConnection transferCookieConnection; diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java diff --git a/patches/unapplied/server/Strip-raytracing-for-EntityLiving-hasLineOfSight.patch b/patches/server/Strip-raytracing-for-EntityLiving-hasLineOfSight.patch similarity index 100% rename from patches/unapplied/server/Strip-raytracing-for-EntityLiving-hasLineOfSight.patch rename to patches/server/Strip-raytracing-for-EntityLiving-hasLineOfSight.patch diff --git a/patches/unapplied/server/incremental-chunk-and-player-saving.patch b/patches/server/incremental-chunk-and-player-saving.patch similarity index 100% rename from patches/unapplied/server/incremental-chunk-and-player-saving.patch rename to patches/server/incremental-chunk-and-player-saving.patch diff --git a/patches/unapplied/server/Fix-and-optimise-world-force-upgrading.patch b/patches/unapplied/server/Fix-and-optimise-world-force-upgrading.patch index 6b3dce9336..c68d56ef5c 100644 --- a/patches/unapplied/server/Fix-and-optimise-world-force-upgrading.patch +++ b/patches/unapplied/server/Fix-and-optimise-world-force-upgrading.patch @@ -79,9 +79,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + private final DataFixer dataFixer; + private final Optional<ResourceKey<Codec<? extends ChunkGenerator>>> generatorKey; + private final boolean removeCaches; ++ private final boolean recreateRegionFiles; // TODO + + public ThreadedWorldUpgrader(final ResourceKey<LevelStem> dimensionType, final String worldName, final File worldDir, final int threads, -+ final DataFixer dataFixer, final Optional<ResourceKey<Codec<? extends ChunkGenerator>>> generatorKey, final boolean removeCaches) { ++ final DataFixer dataFixer, final Optional<ResourceKey<Codec<? extends ChunkGenerator>>> generatorKey, ++ final boolean removeCaches, final boolean recreateRegionFiles) { + this.dimensionType = dimensionType; + this.worldName = worldName; + this.worldDir = worldDir; @@ -103,6 +105,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + this.dataFixer = dataFixer; + this.generatorKey = generatorKey; + this.removeCaches = removeCaches; ++ this.recreateRegionFiles = recreateRegionFiles; + } + + public void convert() { @@ -256,16 +259,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - fix and optimise world upgrading + public static void convertWorldButItWorks(net.minecraft.resources.ResourceKey<net.minecraft.world.level.dimension.LevelStem> dimensionType, net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess worldSession, -+ DataFixer dataFixer, Optional<net.minecraft.resources.ResourceKey<com.mojang.serialization.Codec<? extends net.minecraft.world.level.chunk.ChunkGenerator>>> generatorKey, boolean removeCaches) { ++ DataFixer dataFixer, Optional<net.minecraft.resources.ResourceKey<com.mojang.serialization.Codec<? extends net.minecraft.world.level.chunk.ChunkGenerator>>> generatorKey, boolean removeCaches, boolean recreateRegionFiles) { + int threads = Runtime.getRuntime().availableProcessors() * 3 / 8; -+ final io.papermc.paper.world.ThreadedWorldUpgrader worldUpgrader = new io.papermc.paper.world.ThreadedWorldUpgrader(dimensionType, worldSession.getLevelId(), worldSession.levelDirectory.path().toFile(), threads, dataFixer, generatorKey, removeCaches); ++ final io.papermc.paper.world.ThreadedWorldUpgrader worldUpgrader = new io.papermc.paper.world.ThreadedWorldUpgrader(dimensionType, worldSession.getLevelId(), worldSession.levelDirectory.path().toFile(), threads, dataFixer, generatorKey, removeCaches, recreateRegionFiles); + worldUpgrader.convert(); + } + // Paper end - fix and optimise world upgrading + - public static void forceUpgrade(LevelStorageSource.LevelStorageAccess session, DataFixer dataFixer, boolean eraseCache, BooleanSupplier continueCheck, Registry<LevelStem> dimensionOptionsRegistry) { + public static void forceUpgrade(LevelStorageSource.LevelStorageAccess session, DataFixer dataFixer, boolean eraseCache, BooleanSupplier continueCheck, RegistryAccess dynamicRegistryManager, boolean recreateRegionFiles) { Main.LOGGER.info("Forcing world upgrade! {}", session.getLevelId()); // CraftBukkit - WorldUpgrader worldupgrader = new WorldUpgrader(session, dataFixer, dimensionOptionsRegistry, eraseCache); + WorldUpgrader worldupgrader = new WorldUpgrader(session, dataFixer, dynamicRegistryManager, eraseCache, recreateRegionFiles); diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java @@ -277,7 +280,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 - if (this.options.has("forceUpgrade")) { - net.minecraft.server.Main.forceUpgrade(worldSession, DataFixers.getDataFixer(), this.options.has("eraseCache"), () -> { - return true; -- }, dimensions); +- }, iregistrycustom_dimension, this.options.has("recreateRegionFiles")); - } + // Paper - fix and optimise world upgrading; move down @@ -290,7 +293,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - fix and optimise world upgrading + if (options.has("forceUpgrade")) { + net.minecraft.server.Main.convertWorldButItWorks( -+ dimensionKey, worldSession, DataFixers.getDataFixer(), worlddimension.generator().getTypeNameForDataFixer(), options.has("eraseCache") ++ dimensionKey, worldSession, DataFixers.getDataFixer(), worlddimension.generator().getTypeNameForDataFixer(), options.has("eraseCache"), console.has("recreateRegionFiles") + ); + } + // Paper end - fix and optimise world upgrading @@ -360,7 +363,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 worlddata.setModdedInfo(this.console.getServerModName(), this.console.getModdedStatus().shouldReportAsModified()); - if (this.console.options.has("forceUpgrade")) { -- net.minecraft.server.Main.forceUpgrade(worldSession, DataFixers.getDataFixer(), this.console.options.has("eraseCache"), () -> true, iregistry); +- net.minecraft.server.Main.forceUpgrade(worldSession, DataFixers.getDataFixer(), this.console.options.has("eraseCache"), () -> true, iregistrycustom_dimension, this.console.options.has("recreateRegionFiles")); - } + // Paper - fix and optimise world upgrading; move down @@ -373,7 +376,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - fix and optimise world upgrading + if (this.console.options.has("forceUpgrade")) { + net.minecraft.server.Main.convertWorldButItWorks( -+ actualDimension, worldSession, DataFixers.getDataFixer(), worlddimension.generator().getTypeNameForDataFixer(), this.console.options.has("eraseCache") ++ actualDimension, worldSession, DataFixers.getDataFixer(), worlddimension.generator().getTypeNameForDataFixer(), this.console.options.has("eraseCache"), this.console.options.has("recreateRegionFiles") + ); + } + // Paper end - fix and optimise world upgrading