mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-01 04:32:11 -07:00
More more work
This commit is contained in:
479
patches/server/Chunk-debug-command.patch
Normal file
479
patches/server/Chunk-debug-command.patch
Normal file
@@ -0,0 +1,479 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
||||
Date: Sat, 1 Jun 2019 13:00:55 -0700
|
||||
Subject: [PATCH] Chunk debug command
|
||||
|
||||
Prints all chunk information to a text file into the debug
|
||||
folder in the root server folder. The format is in JSON, and
|
||||
the data format is described in MCUtil#dumpChunks(File)
|
||||
|
||||
The command will output server version and all online players to the
|
||||
file as well. We do not log anything but the location, world and
|
||||
username of the player.
|
||||
|
||||
Also logs the value of these config values (note not all are paper's):
|
||||
- keep spawn loaded value
|
||||
- spawn radius
|
||||
- view distance
|
||||
|
||||
Each chunk has the following logged:
|
||||
- Coordinate
|
||||
- Ticket level & its corresponding state
|
||||
- Whether it is queued for unload
|
||||
- Chunk status (may be unloaded)
|
||||
- All tickets on the chunk
|
||||
|
||||
Example log:
|
||||
https://gist.githubusercontent.com/Spottedleaf/0131e7710ffd5d531e5fd246c3367380/raw/169ae1b2e240485f99bc7a6bd8e78d90e3af7397/chunks-2019-06-01_19.57.05.txt
|
||||
|
||||
For references on certain keywords (ticket, status, etc), please see:
|
||||
|
||||
https://bugs.mojang.com/browse/MC-141484?focusedCommentId=528273&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-528273
|
||||
https://bugs.mojang.com/browse/MC-141484?focusedCommentId=528577&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-528577
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||||
@@ -0,0 +0,0 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
-import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
+import net.minecraft.server.level.ChunkHolder;
|
||||
import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
+import net.minecraft.resources.ResourceLocation;
|
||||
+import net.minecraft.server.MCUtil;
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -0,0 +0,0 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class PaperCommand extends Command {
|
||||
private static final String BASE_PERM = "bukkit.command.paper.";
|
||||
- private static final ImmutableSet<String> SUBCOMMANDS = ImmutableSet.<String>builder().add("heap", "entity", "reload", "version").build();
|
||||
+ private static final ImmutableSet<String> SUBCOMMANDS = ImmutableSet.<String>builder().add("heap", "entity", "reload", "version", "debug", "chunkinfo").build();
|
||||
|
||||
public PaperCommand(String name) {
|
||||
super(name);
|
||||
@@ -0,0 +0,0 @@ public class PaperCommand extends Command {
|
||||
if (args.length == 3)
|
||||
return getListMatchingLast(sender, args, EntityType.getEntityNameList().stream().map(ResourceLocation::toString).sorted().toArray(String[]::new));
|
||||
break;
|
||||
+ case "debug":
|
||||
+ if (args.length == 2) {
|
||||
+ return getListMatchingLast(sender, args, "help", "chunks");
|
||||
+ }
|
||||
+ break;
|
||||
+ case "chunkinfo":
|
||||
+ List<String> worldNames = new ArrayList<>();
|
||||
+ worldNames.add("*");
|
||||
+ for (org.bukkit.World world : Bukkit.getWorlds()) {
|
||||
+ worldNames.add(world.getName());
|
||||
+ }
|
||||
+ if (args.length == 2) {
|
||||
+ return getListMatchingLast(sender, args, worldNames);
|
||||
+ }
|
||||
+ break;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public class PaperCommand extends Command {
|
||||
case "reload":
|
||||
doReload(sender);
|
||||
break;
|
||||
+ case "debug":
|
||||
+ doDebug(sender, args);
|
||||
+ break;
|
||||
+ case "chunkinfo":
|
||||
+ doChunkInfo(sender, args);
|
||||
+ break;
|
||||
case "ver":
|
||||
if (!testPermission(sender, "version")) break; // "ver" needs a special check because it's an alias. All other commands are checked up before the switch statement (because they are present in the SUBCOMMANDS set)
|
||||
case "version":
|
||||
@@ -0,0 +0,0 @@ public class PaperCommand extends Command {
|
||||
return true;
|
||||
}
|
||||
|
||||
+ private void doChunkInfo(CommandSender sender, String[] args) {
|
||||
+ List<org.bukkit.World> worlds;
|
||||
+ if (args.length < 2 || args[1].equals("*")) {
|
||||
+ worlds = Bukkit.getWorlds();
|
||||
+ } else {
|
||||
+ worlds = new ArrayList<>(args.length - 1);
|
||||
+ for (int i = 1; i < args.length; ++i) {
|
||||
+ org.bukkit.World world = Bukkit.getWorld(args[i]);
|
||||
+ if (world == null) {
|
||||
+ sender.sendMessage(ChatColor.RED + "World '" + args[i] + "' is invalid");
|
||||
+ return;
|
||||
+ }
|
||||
+ worlds.add(world);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ int accumulatedTotal = 0;
|
||||
+ int accumulatedInactive = 0;
|
||||
+ int accumulatedBorder = 0;
|
||||
+ int accumulatedTicking = 0;
|
||||
+ int accumulatedEntityTicking = 0;
|
||||
+
|
||||
+ for (org.bukkit.World bukkitWorld : worlds) {
|
||||
+ ServerLevel world = ((CraftWorld)bukkitWorld).getHandle();
|
||||
+
|
||||
+ int total = 0;
|
||||
+ int inactive = 0;
|
||||
+ int border = 0;
|
||||
+ int ticking = 0;
|
||||
+ int entityTicking = 0;
|
||||
+
|
||||
+ for (ChunkHolder chunk : world.getChunkSource().chunkMap.updatingChunkMap.values()) {
|
||||
+ if (chunk.getFullChunkIfCached() == null) {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ ++total;
|
||||
+
|
||||
+ ChunkHolder.FullChunkStatus state = ChunkHolder.getFullChunkStatus(chunk.getTicketLevel());
|
||||
+
|
||||
+ switch (state) {
|
||||
+ case INACCESSIBLE:
|
||||
+ ++inactive;
|
||||
+ continue;
|
||||
+ case BORDER:
|
||||
+ ++border;
|
||||
+ continue;
|
||||
+ case TICKING:
|
||||
+ ++ticking;
|
||||
+ continue;
|
||||
+ case ENTITY_TICKING:
|
||||
+ ++entityTicking;
|
||||
+ continue;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ accumulatedTotal += total;
|
||||
+ accumulatedInactive += inactive;
|
||||
+ accumulatedBorder += border;
|
||||
+ accumulatedTicking += ticking;
|
||||
+ accumulatedEntityTicking += entityTicking;
|
||||
+
|
||||
+ sender.sendMessage(ChatColor.BLUE + "Chunks in " + ChatColor.GREEN + bukkitWorld.getName() + ChatColor.DARK_AQUA + ":");
|
||||
+ sender.sendMessage(ChatColor.BLUE + "Total: " + ChatColor.DARK_AQUA + total + ChatColor.BLUE + " Inactive: " + ChatColor.DARK_AQUA
|
||||
+ + inactive + ChatColor.BLUE + " Border: " + ChatColor.DARK_AQUA + border + ChatColor.BLUE + " Ticking: "
|
||||
+ + ChatColor.DARK_AQUA + ticking + ChatColor.BLUE + " Entity: " + ChatColor.DARK_AQUA + entityTicking);
|
||||
+ }
|
||||
+ if (worlds.size() > 1) {
|
||||
+ sender.sendMessage(ChatColor.BLUE + "Chunks in " + ChatColor.GREEN + "all listed worlds" + ChatColor.DARK_AQUA + ":");
|
||||
+ sender.sendMessage(ChatColor.BLUE + "Total: " + ChatColor.DARK_AQUA + accumulatedTotal + ChatColor.BLUE + " Inactive: " + ChatColor.DARK_AQUA
|
||||
+ + accumulatedInactive + ChatColor.BLUE + " Border: " + ChatColor.DARK_AQUA + accumulatedBorder + ChatColor.BLUE + " Ticking: "
|
||||
+ + ChatColor.DARK_AQUA + accumulatedTicking + ChatColor.BLUE + " Entity: " + ChatColor.DARK_AQUA + accumulatedEntityTicking);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private void doDebug(CommandSender sender, String[] args) {
|
||||
+ if (args.length < 2) {
|
||||
+ sender.sendMessage(ChatColor.RED + "Use /paper debug [chunks] help for more information on a specific command");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ String debugType = args[1].toLowerCase(Locale.ENGLISH);
|
||||
+ switch (debugType) {
|
||||
+ case "chunks":
|
||||
+ if (args.length >= 3 && args[2].toLowerCase(Locale.ENGLISH).equals("help")) {
|
||||
+ sender.sendMessage(ChatColor.RED + "Use /paper debug chunks to dump loaded chunk information to a file");
|
||||
+ break;
|
||||
+ }
|
||||
+ File file = new File(new File(new File("."), "debug"),
|
||||
+ "chunks-" + DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss").format(LocalDateTime.now()) + ".txt");
|
||||
+ sender.sendMessage(ChatColor.GREEN + "Writing chunk information dump to " + file.toString());
|
||||
+ try {
|
||||
+ MCUtil.dumpChunks(file);
|
||||
+ sender.sendMessage(ChatColor.GREEN + "Successfully written chunk information!");
|
||||
+ } catch (Throwable thr) {
|
||||
+ MinecraftServer.LOGGER.warn("Failed to dump chunk information to file " + file.toString(), thr);
|
||||
+ sender.sendMessage(ChatColor.RED + "Failed to dump chunk information, see console");
|
||||
+ }
|
||||
+
|
||||
+ break;
|
||||
+ case "help":
|
||||
+ // fall through to default
|
||||
+ default:
|
||||
+ sender.sendMessage(ChatColor.RED + "Use /paper debug [chunks] help for more information on a specific command");
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
/*
|
||||
* Ported from MinecraftForge - author: LexManos <LexManos@gmail.com> - License: LGPLv2.1
|
||||
*/
|
||||
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/MCUtil.java
|
||||
+++ b/src/main/java/net/minecraft/server/MCUtil.java
|
||||
@@ -0,0 +0,0 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
+import net.minecraft.server.level.ChunkHolder;
|
||||
+import net.minecraft.server.level.ChunkMap;
|
||||
+import net.minecraft.server.level.DistanceManager;
|
||||
+import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
+import net.minecraft.server.level.ServerPlayer;
|
||||
+import net.minecraft.server.level.Ticket;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
+import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
+import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
+import com.google.gson.JsonArray;
|
||||
+import com.google.gson.JsonObject;
|
||||
+import com.google.gson.internal.Streams;
|
||||
+import com.google.gson.stream.JsonWriter;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
+import com.mojang.datafixers.util.Either;
|
||||
+import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
@@ -0,0 +0,0 @@ import org.spigotmc.AsyncCatcher;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
+import java.io.*;
|
||||
+import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
+import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
@@ -0,0 +0,0 @@ public final class MCUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
+ public static ChunkStatus getChunkStatus(ChunkHolder chunk) {
|
||||
+ List<ChunkStatus> statuses = ServerChunkCache.getPossibleChunkStatuses();
|
||||
+ for (int i = statuses.size() - 1; i >= 0; --i) {
|
||||
+ ChunkStatus curr = statuses.get(i);
|
||||
+ CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> future = chunk.getFutureIfPresentUnchecked(curr);
|
||||
+ if (future != ChunkHolder.UNLOADED_CHUNK_FUTURE) {
|
||||
+ return curr;
|
||||
+ }
|
||||
+ }
|
||||
+ return null; // unloaded
|
||||
+ }
|
||||
+
|
||||
+ public static void dumpChunks(File file) throws IOException {
|
||||
+ file.getParentFile().mkdirs();
|
||||
+ file.createNewFile();
|
||||
+ /*
|
||||
+ * Json format:
|
||||
+ *
|
||||
+ * Main data format:
|
||||
+ * -server-version:<string>
|
||||
+ * -data-version:<int>
|
||||
+ * -worlds:
|
||||
+ * -name:<world name>
|
||||
+ * -view-distance:<int>
|
||||
+ * -keep-spawn-loaded:<boolean>
|
||||
+ * -keep-spawn-loaded-range:<int>
|
||||
+ * -visible-chunk-count:<int>
|
||||
+ * -loaded-chunk-count:<int>
|
||||
+ * -verified-fully-loaded-chunks:<int>
|
||||
+ * -players:<array of player>
|
||||
+ * -chunk-data:<array of chunks>
|
||||
+ *
|
||||
+ * Player format:
|
||||
+ * -name:<string>
|
||||
+ * -x:<double>
|
||||
+ * -y:<double>
|
||||
+ * -z:<double>
|
||||
+ *
|
||||
+ * Chunk Format:
|
||||
+ * -x:<integer>
|
||||
+ * -z:<integer>
|
||||
+ * -ticket-level:<integer>
|
||||
+ * -state:<string>
|
||||
+ * -queued-for-unload:<boolean>
|
||||
+ * -status:<string>
|
||||
+ * -tickets:<array of tickets>
|
||||
+ *
|
||||
+ *
|
||||
+ * Ticket format:
|
||||
+ * -ticket-type:<string>
|
||||
+ * -ticket-level:<int>
|
||||
+ * -add-tick:<long>
|
||||
+ * -object-reason:<string> // This depends on the type of ticket. ie POST_TELEPORT -> entity id
|
||||
+ */
|
||||
+ List<org.bukkit.World> worlds = org.bukkit.Bukkit.getWorlds();
|
||||
+ JsonObject data = new JsonObject();
|
||||
+
|
||||
+ data.addProperty("server-version", org.bukkit.Bukkit.getVersion());
|
||||
+ data.addProperty("data-version", 0);
|
||||
+
|
||||
+ JsonArray worldsData = new JsonArray();
|
||||
+
|
||||
+ for (org.bukkit.World bukkitWorld : worlds) {
|
||||
+ JsonObject worldData = new JsonObject();
|
||||
+
|
||||
+ ServerLevel world = ((org.bukkit.craftbukkit.CraftWorld)bukkitWorld).getHandle();
|
||||
+ ChunkMap chunkMap = world.getChunkSource().chunkMap;
|
||||
+ Long2ObjectLinkedOpenHashMap<ChunkHolder> visibleChunks = chunkMap.visibleChunkMap;
|
||||
+ DistanceManager chunkMapDistance = chunkMap.distanceManager;
|
||||
+ List<ChunkHolder> allChunks = new ArrayList<>(visibleChunks.values());
|
||||
+ List<ServerPlayer> players = world.players;
|
||||
+
|
||||
+ int fullLoadedChunks = 0;
|
||||
+
|
||||
+ for (ChunkHolder chunk : allChunks) {
|
||||
+ if (chunk.getFullChunkIfCached() != null) {
|
||||
+ ++fullLoadedChunks;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // sorting by coordinate makes the log easier to read
|
||||
+ allChunks.sort((ChunkHolder v1, ChunkHolder v2) -> {
|
||||
+ if (v1.location.x != v2.location.x) {
|
||||
+ return Integer.compare(v1.location.x, v2.location.x);
|
||||
+ }
|
||||
+ return Integer.compare(v1.location.z, v2.location.z);
|
||||
+ });
|
||||
+
|
||||
+ worldData.addProperty("name", world.getWorld().getName());
|
||||
+ worldData.addProperty("view-distance", world.spigotConfig.viewDistance);
|
||||
+ worldData.addProperty("keep-spawn-loaded", world.keepSpawnInMemory);
|
||||
+ worldData.addProperty("keep-spawn-loaded-range", world.paperConfig.keepLoadedRange);
|
||||
+ worldData.addProperty("visible-chunk-count", visibleChunks.size());
|
||||
+ worldData.addProperty("loaded-chunk-count", chunkMap.entitiesInLevel.size());
|
||||
+ worldData.addProperty("verified-fully-loaded-chunks", fullLoadedChunks);
|
||||
+
|
||||
+ JsonArray playersData = new JsonArray();
|
||||
+
|
||||
+ for (ServerPlayer player : players) {
|
||||
+ JsonObject playerData = new JsonObject();
|
||||
+
|
||||
+ playerData.addProperty("name", player.getScoreboardName());
|
||||
+ playerData.addProperty("x", player.getX());
|
||||
+ playerData.addProperty("y", player.getY());
|
||||
+ playerData.addProperty("z", player.getZ());
|
||||
+
|
||||
+ playersData.add(playerData);
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+ worldData.add("players", playersData);
|
||||
+
|
||||
+ JsonArray chunksData = new JsonArray();
|
||||
+
|
||||
+ for (ChunkHolder playerChunk : allChunks) {
|
||||
+ JsonObject chunkData = new JsonObject();
|
||||
+
|
||||
+ Set<Ticket<?>> tickets = chunkMapDistance.tickets.get(playerChunk.pos.pair());
|
||||
+ ChunkStatus status = getChunkStatus(playerChunk);
|
||||
+
|
||||
+ chunkData.addProperty("x", playerChunk.location.x);
|
||||
+ chunkData.addProperty("z", playerChunk.location.z);
|
||||
+ chunkData.addProperty("ticket-level", playerChunk.getTicketLevel());
|
||||
+ chunkData.addProperty("state", ChunkHolder.getFullChunkStatus(playerChunk.getTicketLevel()).toString());
|
||||
+ chunkData.addProperty("queued-for-unload", chunkMap.toDrop.contains(playerChunk.pos.pair()));
|
||||
+ chunkData.addProperty("status", status == null ? "unloaded" : status.toString());
|
||||
+
|
||||
+ JsonArray ticketsData = new JsonArray();
|
||||
+
|
||||
+ if (tickets != null) {
|
||||
+ for (Ticket<?> ticket : tickets) {
|
||||
+ JsonObject ticketData = new JsonObject();
|
||||
+
|
||||
+ ticketData.addProperty("ticket-type", ticket.getType().toString());
|
||||
+ ticketData.addProperty("ticket-level", ticket.getTicketLevel());
|
||||
+ ticketData.addProperty("object-reason", String.valueOf(ticket.getObjectReason()));
|
||||
+ ticketData.addProperty("add-tick", ticket.getCreationTick());
|
||||
+
|
||||
+ ticketsData.add(ticketData);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ chunkData.add("tickets", ticketsData);
|
||||
+ chunksData.add(chunkData);
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ worldData.add("chunk-data", chunksData);
|
||||
+ worldsData.add(worldData);
|
||||
+ }
|
||||
+
|
||||
+ data.add("worlds", worldsData);
|
||||
+
|
||||
+ StringWriter stringWriter = new StringWriter();
|
||||
+ JsonWriter jsonWriter = new JsonWriter(stringWriter);
|
||||
+ jsonWriter.setIndent(" ");
|
||||
+ jsonWriter.setLenient(false);
|
||||
+ Streams.write(data, jsonWriter);
|
||||
+
|
||||
+ String fileData = stringWriter.toString();
|
||||
+
|
||||
+ try (PrintStream out = new PrintStream(new FileOutputStream(file), false, "UTF-8")) {
|
||||
+ out.print(fileData);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
public static int getTicketLevelFor(net.minecraft.world.level.chunk.ChunkStatus status) {
|
||||
return net.minecraft.server.level.ChunkMap.MAX_VIEW_DISTANCE + net.minecraft.world.level.chunk.ChunkStatus.getDistance(status);
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
@@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||||
public final Long2ObjectLinkedOpenHashMap<ChunkHolder> updatingChunkMap = new Long2ObjectLinkedOpenHashMap();
|
||||
public volatile Long2ObjectLinkedOpenHashMap<ChunkHolder> visibleChunkMap;
|
||||
private final Long2ObjectLinkedOpenHashMap<ChunkHolder> pendingUnloads;
|
||||
- private final LongSet entitiesInLevel;
|
||||
+ public final LongSet entitiesInLevel; // Paper - private -> public
|
||||
public final ServerLevel level;
|
||||
private final ThreadedLevelLightEngine lightEngine;
|
||||
private final BlockableEventLoop<Runnable> mainThreadExecutor;
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
@@ -0,0 +0,0 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; // Paper
|
||||
|
||||
public class ServerChunkCache extends ChunkSource {
|
||||
|
||||
- private static final List<ChunkStatus> CHUNK_STATUSES = ChunkStatus.getStatusList();
|
||||
+ private static final List<ChunkStatus> CHUNK_STATUSES = ChunkStatus.getStatusList(); public static final List<ChunkStatus> getPossibleChunkStatuses() { return ServerChunkCache.CHUNK_STATUSES; } // Paper - OBFHELPER
|
||||
private final DistanceManager distanceManager;
|
||||
public final ChunkGenerator generator;
|
||||
final ServerLevel level;
|
||||
diff --git a/src/main/java/net/minecraft/server/level/Ticket.java b/src/main/java/net/minecraft/server/level/Ticket.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/Ticket.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/Ticket.java
|
||||
@@ -0,0 +0,0 @@ import java.util.Objects;
|
||||
public final class Ticket<T> implements Comparable<Ticket<?>> {
|
||||
private final TicketType<T> type;
|
||||
private final int ticketLevel;
|
||||
- public final T key;
|
||||
- private long createdTick;
|
||||
+ public final T key; public final T getObjectReason() { return this.key; } // Paper - OBFHELPER
|
||||
+ private long createdTick; public final long getCreationTick() { return this.createdTick; } // Paper - OBFHELPER
|
||||
|
||||
protected Ticket(TicketType<T> type, int level, T argument) {
|
||||
this.type = type;
|
||||
@@ -0,0 +0,0 @@ public final class Ticket<T> implements Comparable<Ticket<?>> {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
+ public final int getTicketLevel() { return this.getTicketLevel(); } // Paper - OBFHELPER
|
||||
public int getTicketLevel() {
|
||||
return this.ticketLevel;
|
||||
}
|
84
patches/server/ChunkMapDistance-CME.patch
Normal file
84
patches/server/ChunkMapDistance-CME.patch
Normal file
@@ -0,0 +1,84 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Shane Freeder <theboyetronic@gmail.com>
|
||||
Date: Wed, 29 May 2019 04:01:22 +0100
|
||||
Subject: [PATCH] ChunkMapDistance CME
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ChunkHolder.java b/src/main/java/net/minecraft/server/level/ChunkHolder.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ChunkHolder.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ChunkHolder.java
|
||||
@@ -0,0 +0,0 @@ public class ChunkHolder {
|
||||
private boolean resendLight;
|
||||
private CompletableFuture<Void> pendingFullStateConfirmation;
|
||||
|
||||
+ boolean isUpdateQueued = false; // Paper
|
||||
private final ChunkMap chunkMap; // Paper
|
||||
|
||||
public ChunkHolder(ChunkPos pos, int level, LevelHeightAccessor world, LevelLightEngine lightingProvider, ChunkHolder.LevelChangeListener levelUpdateListener, ChunkHolder.PlayerProvider playersWatchingChunkProvider) {
|
||||
diff --git a/src/main/java/net/minecraft/server/level/DistanceManager.java b/src/main/java/net/minecraft/server/level/DistanceManager.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/DistanceManager.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/DistanceManager.java
|
||||
@@ -0,0 +0,0 @@ public abstract class DistanceManager {
|
||||
private final DistanceManager.ChunkTicketTracker ticketTracker = new DistanceManager.ChunkTicketTracker();
|
||||
private final DistanceManager.FixedPlayerDistanceChunkTracker naturalSpawnChunkCounter = new DistanceManager.FixedPlayerDistanceChunkTracker(8);
|
||||
private final DistanceManager.PlayerTicketTracker playerTicketManager = new DistanceManager.PlayerTicketTracker(33);
|
||||
- final Set<ChunkHolder> chunksToUpdateFutures = Sets.newHashSet();
|
||||
+ // Paper start use a queue, but still keep unique requirement
|
||||
+ public final java.util.Queue<ChunkHolder> pendingChunkUpdates = new java.util.ArrayDeque<ChunkHolder>() {
|
||||
+ @Override
|
||||
+ public boolean add(ChunkHolder o) {
|
||||
+ if (o.isUpdateQueued) return true;
|
||||
+ o.isUpdateQueued = true;
|
||||
+ return super.add(o);
|
||||
+ }
|
||||
+ };
|
||||
+ // Paper end
|
||||
final ChunkTaskPriorityQueueSorter ticketThrottler;
|
||||
final ProcessorHandle<ChunkTaskPriorityQueueSorter.Message<Runnable>> ticketThrottlerInput;
|
||||
final ProcessorHandle<ChunkTaskPriorityQueueSorter.Release> ticketThrottlerReleaser;
|
||||
@@ -0,0 +0,0 @@ public abstract class DistanceManager {
|
||||
;
|
||||
}
|
||||
|
||||
- if (!this.chunksToUpdateFutures.isEmpty()) {
|
||||
- // CraftBukkit start
|
||||
- // Iterate pending chunk updates with protection against concurrent modification exceptions
|
||||
- java.util.Iterator<ChunkHolder> iter = this.chunksToUpdateFutures.iterator();
|
||||
- int expectedSize = this.chunksToUpdateFutures.size();
|
||||
- do {
|
||||
- ChunkHolder playerchunk = iter.next();
|
||||
- iter.remove();
|
||||
- expectedSize--;
|
||||
-
|
||||
- playerchunk.updateFutures(playerchunkmap, this.mainThreadExecutor);
|
||||
-
|
||||
- // Reset iterator if set was modified using add()
|
||||
- if (this.chunksToUpdateFutures.size() != expectedSize) {
|
||||
- expectedSize = this.chunksToUpdateFutures.size();
|
||||
- iter = this.chunksToUpdateFutures.iterator();
|
||||
- }
|
||||
- } while (iter.hasNext());
|
||||
- // CraftBukkit end
|
||||
-
|
||||
+ // Paper start
|
||||
+ if (!this.pendingChunkUpdates.isEmpty()) {
|
||||
+ while(!this.pendingChunkUpdates.isEmpty()) {
|
||||
+ ChunkHolder remove = this.pendingChunkUpdates.remove();
|
||||
+ remove.isUpdateQueued = false;
|
||||
+ remove.updateFutures(playerchunkmap, this.mainThreadExecutor);
|
||||
+ }
|
||||
+ // Paper end
|
||||
return true;
|
||||
} else {
|
||||
if (!this.ticketsToRelease.isEmpty()) {
|
||||
@@ -0,0 +0,0 @@ public abstract class DistanceManager {
|
||||
if (k != level) {
|
||||
playerchunk = DistanceManager.this.updateChunkScheduling(id, level, playerchunk, k);
|
||||
if (playerchunk != null) {
|
||||
- DistanceManager.this.chunksToUpdateFutures.add(playerchunk);
|
||||
+ DistanceManager.this.pendingChunkUpdates.add(playerchunk);
|
||||
}
|
||||
|
||||
}
|
@@ -174,7 +174,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
public void setDefaultSpawnPos(BlockPos pos, float angle) {
|
||||
- ChunkPos chunkcoordintpair = new ChunkPos(new BlockPos(this.levelData.getXSpawn(), 0, this.levelData.getZSpawn()));
|
||||
+ // Paper - configurable spawn radius
|
||||
+ BlockPos prevSpawn = this.getSpawn();
|
||||
+ BlockPos prevSpawn = this.getSharedSpawnPos();
|
||||
+ //ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(new BlockPosition(this.worldData.a(), 0, this.worldData.c()));
|
||||
|
||||
this.levelData.setSpawn(pos, angle);
|
||||
|
390
patches/server/Fix-World-isChunkGenerated-calls.patch
Normal file
390
patches/server/Fix-World-isChunkGenerated-calls.patch
Normal file
@@ -0,0 +1,390 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
||||
Date: Sat, 15 Jun 2019 08:54:33 -0700
|
||||
Subject: [PATCH] Fix World#isChunkGenerated calls
|
||||
|
||||
Optimize World#loadChunk() too
|
||||
This patch also adds a chunk status cache on region files (note that
|
||||
its only purpose is to cache the status on DISK)
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ChunkHolder.java b/src/main/java/net/minecraft/server/level/ChunkHolder.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ChunkHolder.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ChunkHolder.java
|
||||
@@ -0,0 +0,0 @@ public class ChunkHolder {
|
||||
Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> either = (Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>) statusFuture.getNow(null);
|
||||
return either == null ? null : (LevelChunk) either.left().orElse(null);
|
||||
}
|
||||
+
|
||||
+ public ChunkAccess getAvailableChunkNow() {
|
||||
+ // TODO can we just getStatusFuture(EMPTY)?
|
||||
+ for (ChunkStatus curr = ChunkStatus.FULL, next = curr.getPreviousStatus(); curr != next; curr = next, next = next.getPreviousStatus()) {
|
||||
+ CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> future = this.getFutureIfPresentUnchecked(curr);
|
||||
+ Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> either = future.getNow(null);
|
||||
+ if (either == null || !either.left().isPresent()) {
|
||||
+ continue;
|
||||
+ }
|
||||
+ return either.left().get();
|
||||
+ }
|
||||
+ return null;
|
||||
+ }
|
||||
// Paper end
|
||||
|
||||
public CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> getFutureIfPresentUnchecked(ChunkStatus leastStatus) {
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
@@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||||
}
|
||||
|
||||
@Nullable
|
||||
- private CompoundTag readChunk(ChunkPos pos) throws IOException {
|
||||
+ public CompoundTag readChunk(ChunkPos pos) throws IOException { // Paper - private -> public
|
||||
CompoundTag nbttagcompound = this.read(pos);
|
||||
+ // Paper start - Cache chunk status on disk
|
||||
+ if (nbttagcompound == null) {
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ nbttagcompound = this.getChunkData(this.level.getTypeKey(), this.overworldDataStorage, nbttagcompound, pos, level); // CraftBukkit
|
||||
+ if (nbttagcompound == null) {
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ this.updateChunkStatusOnDisk(pos, nbttagcompound);
|
||||
+
|
||||
+ return nbttagcompound;
|
||||
+ // Paper end
|
||||
+ }
|
||||
+
|
||||
+ // Paper start - chunk status cache "api"
|
||||
+ public ChunkStatus getChunkStatusOnDiskIfCached(ChunkPos chunkPos) {
|
||||
+ RegionFile regionFile = this.getIOWorker().getRegionFileCache().getRegionFileIfLoaded(chunkPos);
|
||||
+
|
||||
+ return regionFile == null ? null : regionFile.getStatusIfCached(chunkPos.x, chunkPos.z);
|
||||
+ }
|
||||
+
|
||||
+ public ChunkStatus getChunkStatusOnDisk(ChunkPos chunkPos) throws IOException {
|
||||
+ RegionFile regionFile = this.getIOWorker().getRegionFileCache().getFile(chunkPos, true);
|
||||
+
|
||||
+ if (regionFile == null || !regionFile.chunkExists(chunkPos)) {
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ ChunkStatus status = regionFile.getStatusIfCached(chunkPos.x, chunkPos.z);
|
||||
+
|
||||
+ if (status != null) {
|
||||
+ return status;
|
||||
+ }
|
||||
+
|
||||
+ this.readChunk(chunkPos);
|
||||
|
||||
- return nbttagcompound == null ? null : this.getChunkData(this.level.getTypeKey(), this.overworldDataStorage, nbttagcompound, pos, level); // CraftBukkit
|
||||
+ return regionFile.getStatusIfCached(chunkPos.x, chunkPos.z);
|
||||
}
|
||||
|
||||
+ public void updateChunkStatusOnDisk(ChunkPos chunkPos, @Nullable CompoundTag compound) throws IOException {
|
||||
+ RegionFile regionFile = this.getIOWorker().getRegionFileCache().getFile(chunkPos, false);
|
||||
+
|
||||
+ regionFile.setStatus(chunkPos.x, chunkPos.z, ChunkSerializer.getStatus(compound));
|
||||
+ }
|
||||
+
|
||||
+ public ChunkAccess getUnloadingChunk(int chunkX, int chunkZ) {
|
||||
+ ChunkHolder chunkHolder = this.pendingUnloads.get(ChunkPos.asLong(chunkX, chunkZ));
|
||||
+ return chunkHolder == null ? null : chunkHolder.getAvailableChunkNow();
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
boolean noPlayersCloseForSpawning(ChunkPos chunkcoordintpair) {
|
||||
// Spigot start
|
||||
return isOutsideOfRange(chunkcoordintpair, false);
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
@@ -0,0 +0,0 @@ public class ServerChunkCache extends ChunkSource {
|
||||
private final ServerLevel level;
|
||||
public final Thread mainThread; // Paper - private -> public
|
||||
private final ThreadedLevelLightEngine lightEngine;
|
||||
- private final ServerChunkCache.MainThreadExecutor mainThreadProcessor;
|
||||
+ public final ServerChunkCache.MainThreadExecutor mainThreadProcessor; // Paper private -> public
|
||||
public final ChunkMap chunkMap;
|
||||
private final DimensionDataStorage dataStorage;
|
||||
private long lastInhabitedUpdate;
|
||||
@@ -0,0 +0,0 @@ public class ServerChunkCache extends ChunkSource {
|
||||
|
||||
return ret;
|
||||
}
|
||||
+
|
||||
+ @Nullable
|
||||
+ public ChunkAccess getChunkAtImmediately(int x, int z) {
|
||||
+ long k = ChunkPos.asLong(x, z);
|
||||
+
|
||||
+ // Note: Bypass cache to make this MT-Safe
|
||||
+
|
||||
+ ChunkHolder playerChunk = this.getVisibleChunkIfPresent(k);
|
||||
+ if (playerChunk == null) {
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ return playerChunk.getAvailableChunkNow();
|
||||
+
|
||||
+ }
|
||||
// Paper end
|
||||
|
||||
@Nullable
|
||||
@@ -0,0 +0,0 @@ public class ServerChunkCache extends ChunkSource {
|
||||
return this.lastSpawnState;
|
||||
}
|
||||
|
||||
- final class MainThreadExecutor extends BlockableEventLoop<Runnable> {
|
||||
+ public final class MainThreadExecutor extends BlockableEventLoop<Runnable> { // Paper - package -> public
|
||||
|
||||
private MainThreadExecutor(Level world) {
|
||||
super("Chunk source main thread executor for " + world.dimension().location());
|
||||
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkStatus.java b/src/main/java/net/minecraft/world/level/chunk/ChunkStatus.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkStatus.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkStatus.java
|
||||
@@ -0,0 +0,0 @@ public class ChunkStatus {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
+ public ChunkStatus getPreviousStatus() { return this.getParent(); } // Paper - OBFHELPER
|
||||
public ChunkStatus getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public class ChunkStatus {
|
||||
return this.chunkType;
|
||||
}
|
||||
|
||||
+ // Paper start
|
||||
+ public static ChunkStatus getStatus(String name) {
|
||||
+ try {
|
||||
+ // We need this otherwise we return EMPTY for invalid names
|
||||
+ ResourceLocation key = new ResourceLocation(name);
|
||||
+ return Registry.CHUNK_STATUS.getOptional(key).orElse(null);
|
||||
+ } catch (Exception ex) {
|
||||
+ return null; // invalid name
|
||||
+ }
|
||||
+ }
|
||||
+ // Paper end
|
||||
public static ChunkStatus byName(String id) {
|
||||
return (ChunkStatus) Registry.CHUNK_STATUS.get(ResourceLocation.tryParse(id));
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
|
||||
@@ -0,0 +0,0 @@ public class ChunkSerializer {
|
||||
}
|
||||
// Paper end
|
||||
|
||||
+ // Paper start
|
||||
+ public static ChunkStatus getStatus(CompoundTag compound) {
|
||||
+ if (compound == null) {
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ // Note: Copied from below
|
||||
+ return ChunkStatus.getStatus(compound.getCompound("Level").getString("Status"));
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
public static ChunkStatus.ChunkType getChunkTypeFromTag(@Nullable CompoundTag tag) {
|
||||
if (tag != null) {
|
||||
ChunkStatus chunkstatus = ChunkStatus.byName(tag.getCompound("Level").getString("Status"));
|
||||
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java
|
||||
@@ -0,0 +0,0 @@ import net.minecraft.world.level.storage.DimensionDataStorage;
|
||||
|
||||
public class ChunkStorage implements AutoCloseable {
|
||||
|
||||
- private final IOWorker worker;
|
||||
+ private final IOWorker worker; public IOWorker getIOWorker() { return worker; } // Paper - OBFHELPER
|
||||
protected final DataFixer fixerUpper;
|
||||
@Nullable
|
||||
private LegacyStructureDataHandler legacyStructureHandler;
|
||||
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- 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 @@ import net.minecraft.Util;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
+import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
|
||||
protected final RegionBitmap usedSectors;
|
||||
public final File file; // Paper
|
||||
|
||||
+ // Paper start - Cache chunk status
|
||||
+ private final ChunkStatus[] statuses = new ChunkStatus[32 * 32];
|
||||
+
|
||||
+ private boolean closed;
|
||||
+
|
||||
+ // invoked on write/read
|
||||
+ public void setStatus(int x, int z, ChunkStatus status) {
|
||||
+ if (this.closed) {
|
||||
+ // We've used an invalid region file.
|
||||
+ throw new IllegalStateException("RegionFile is closed");
|
||||
+ }
|
||||
+ this.statuses[getChunkLocation(x, z)] = status;
|
||||
+ }
|
||||
+
|
||||
+ public ChunkStatus getStatusIfCached(int x, int z) {
|
||||
+ if (this.closed) {
|
||||
+ // We've used an invalid region file.
|
||||
+ throw new IllegalStateException("RegionFile is closed");
|
||||
+ }
|
||||
+ final int location = getChunkLocation(x, z);
|
||||
+ return this.statuses[location];
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
public RegionFile(File file, File directory, boolean dsync) throws IOException {
|
||||
this(file.toPath(), directory.toPath(), RegionFileVersion.VERSION_DEFLATE, dsync);
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
|
||||
return this.getOffset(pos) != 0;
|
||||
}
|
||||
|
||||
+ private static int getChunkLocation(int x, int z) { return (x & 31) + (z & 31) * 32; } // Paper - OBFHELPER - sort of, mirror of logic below
|
||||
private static int getOffsetIndex(ChunkPos pos) {
|
||||
return pos.getRegionLocalX() + pos.getRegionLocalZ() * 32;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
+ this.closed = true; // Paper
|
||||
try {
|
||||
this.padToFullSector();
|
||||
} finally {
|
||||
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
|
||||
@@ -0,0 +0,0 @@ public final class RegionFileStorage implements AutoCloseable {
|
||||
this.sync = dsync;
|
||||
}
|
||||
|
||||
- private RegionFile getFile(ChunkPos chunkcoordintpair, boolean existingOnly) throws IOException { // CraftBukkit
|
||||
+
|
||||
+ // Paper start
|
||||
+ public RegionFile getRegionFileIfLoaded(ChunkPos chunkcoordintpair) {
|
||||
+ return this.regionCache.getAndMoveToFirst(ChunkPos.asLong(chunkcoordintpair.getRegionX(), chunkcoordintpair.getRegionZ()));
|
||||
+ }
|
||||
+
|
||||
+ // Paper end
|
||||
+ public RegionFile getFile(ChunkPos chunkcoordintpair, boolean existingOnly) throws IOException { // CraftBukkit // Paper - private > public
|
||||
long i = ChunkPos.asLong(chunkcoordintpair.getRegionX(), chunkcoordintpair.getRegionZ());
|
||||
RegionFile regionfile = (RegionFile) this.regionCache.getAndMoveToFirst(i);
|
||||
|
||||
@@ -0,0 +0,0 @@ public final class RegionFileStorage implements AutoCloseable {
|
||||
|
||||
try {
|
||||
NbtIo.write(tag, (DataOutput) dataoutputstream);
|
||||
+ regionfile.setStatus(pos.x, pos.z, ChunkSerializer.getStatus(tag)); // Paper - cache status on disk
|
||||
regionfile.setOversized(pos.x, pos.z, false); // Paper - We don't do this anymore, mojang stores differently, but clear old meta flag if it exists to get rid of our own meta file once last oversized is gone
|
||||
} catch (Throwable throwable1) {
|
||||
throwable = throwable1;
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
@@ -0,0 +0,0 @@ import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
+import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -0,0 +0,0 @@ public class CraftWorld implements World {
|
||||
|
||||
@Override
|
||||
public boolean isChunkGenerated(int x, int z) {
|
||||
+ // Paper start - Fix this method
|
||||
+ if (!Bukkit.isPrimaryThread()) {
|
||||
+ return CompletableFuture.supplyAsync(() -> {
|
||||
+ return CraftWorld.this.isChunkGenerated(x, z);
|
||||
+ }, world.getChunkSource().mainThreadProcessor).join();
|
||||
+ }
|
||||
+ ChunkAccess chunk = world.getChunkSource().getChunkAtImmediately(x, z);
|
||||
+ if (chunk == null) {
|
||||
+ chunk = world.getChunkSource().chunkMap.getUnloadingChunk(x, z);
|
||||
+ }
|
||||
+ if (chunk != null) {
|
||||
+ return chunk instanceof ImposterProtoChunk || chunk instanceof net.minecraft.world.level.chunk.LevelChunk;
|
||||
+ }
|
||||
try {
|
||||
- return world.getChunkSource().getChunkAtIfCachedImmediately(x, z) != null || world.getChunkSource().chunkMap.read(new ChunkPos(x, z)) != null; // Paper (TODO check if the first part can be removed)
|
||||
+ return world.getChunkSource().chunkMap.getChunkStatusOnDisk(new ChunkPos(x, z)) == ChunkStatus.FULL;
|
||||
+ // Paper end
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public class CraftWorld implements World {
|
||||
@Override
|
||||
public boolean loadChunk(int x, int z, boolean generate) {
|
||||
org.spigotmc.AsyncCatcher.catchOp("chunk load"); // Spigot
|
||||
- ChunkAccess chunk = world.getChunkSource().getChunk(x, z, generate || isChunkGenerated(x, z) ? ChunkStatus.FULL : ChunkStatus.EMPTY, true); // Paper
|
||||
+ // Paper start - Optimize this method
|
||||
+ ChunkPos chunkPos = new ChunkPos(x, z);
|
||||
|
||||
- // If generate = false, but the chunk already exists, we will get this back.
|
||||
- if (chunk instanceof ImposterProtoChunk) {
|
||||
- // We then cycle through again to get the full chunk immediately, rather than after the ticket addition
|
||||
- chunk = world.getChunkSource().getChunk(x, z, ChunkStatus.FULL, true);
|
||||
- }
|
||||
+ if (!generate) {
|
||||
+ ChunkAccess immediate = world.getChunkSource().getChunkAtImmediately(x, z);
|
||||
+ if (immediate == null) {
|
||||
+ immediate = world.getChunkSource().chunkMap.getUnloadingChunk(x, z);
|
||||
+ }
|
||||
+ if (immediate != null) {
|
||||
+ if (!(immediate instanceof ImposterProtoChunk) && !(immediate instanceof net.minecraft.world.level.chunk.LevelChunk)) {
|
||||
+ return false; // not full status
|
||||
+ }
|
||||
+ world.getChunkSource().addRegionTicket(TicketType.PLUGIN, chunkPos, 1, Unit.INSTANCE);
|
||||
+ world.getChunk(x, z); // make sure we're at ticket level 32 or lower
|
||||
+ return true;
|
||||
+ }
|
||||
|
||||
- if (chunk instanceof net.minecraft.world.level.chunk.LevelChunk) {
|
||||
- world.getChunkSource().addRegionTicket(TicketType.PLUGIN, new ChunkPos(x, z), 1, Unit.INSTANCE);
|
||||
- return true;
|
||||
+ net.minecraft.world.level.chunk.storage.RegionFile file;
|
||||
+ try {
|
||||
+ file = world.getChunkSource().chunkMap.getIOWorker().getRegionFileCache().getFile(chunkPos, false);
|
||||
+ } catch (IOException ex) {
|
||||
+ throw new RuntimeException(ex);
|
||||
+ }
|
||||
+
|
||||
+ ChunkStatus status = file.getStatusIfCached(x, z);
|
||||
+ if (!file.hasChunk(chunkPos) || (status != null && status != ChunkStatus.FULL)) {
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ ChunkAccess chunk = world.getChunkSource().getChunk(x, z, ChunkStatus.EMPTY, true);
|
||||
+ if (!(chunk instanceof ImposterProtoChunk) && !(chunk instanceof net.minecraft.world.level.chunk.LevelChunk)) {
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ // fall through to load
|
||||
+ // we do this so we do not re-read the chunk data on disk
|
||||
}
|
||||
|
||||
- return false;
|
||||
+ world.getChunkSource().addRegionTicket(TicketType.PLUGIN, chunkPos, 1, Unit.INSTANCE);
|
||||
+ world.getChunkSource().getChunk(x, z, ChunkStatus.FULL, true);
|
||||
+ return true;
|
||||
+ // Paper end
|
||||
}
|
||||
|
||||
@Override
|
83
patches/server/Implement-CraftBlockSoundGroup.patch
Normal file
83
patches/server/Implement-CraftBlockSoundGroup.patch
Normal file
@@ -0,0 +1,83 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: simpleauthority <jacob@algorithmjunkie.com>
|
||||
Date: Tue, 28 May 2019 03:48:51 -0700
|
||||
Subject: [PATCH] Implement CraftBlockSoundGroup
|
||||
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/block/CraftBlockSoundGroup.java b/src/main/java/com/destroystokyo/paper/block/CraftBlockSoundGroup.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/block/CraftBlockSoundGroup.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package com.destroystokyo.paper.block;
|
||||
+
|
||||
+import net.minecraft.world.level.block.SoundType;
|
||||
+import org.bukkit.Sound;
|
||||
+import org.bukkit.craftbukkit.CraftSound;
|
||||
+
|
||||
+public class CraftBlockSoundGroup implements BlockSoundGroup {
|
||||
+ private final SoundType soundEffectType;
|
||||
+
|
||||
+ public CraftBlockSoundGroup(SoundType soundEffectType) {
|
||||
+ this.soundEffectType = soundEffectType;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Sound getBreakSound() {
|
||||
+ return CraftSound.getBukkit(soundEffectType.getBreakSound());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Sound getStepSound() {
|
||||
+ return CraftSound.getBukkit(soundEffectType.getStepSound());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Sound getPlaceSound() {
|
||||
+ return CraftSound.getBukkit(soundEffectType.getPlaceSound());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Sound getHitSound() {
|
||||
+ return CraftSound.getBukkit(soundEffectType.getHitSound());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Sound getFallSound() {
|
||||
+ return CraftSound.getBukkit(soundEffectType.getFallSound());
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/SoundType.java b/src/main/java/net/minecraft/world/level/block/SoundType.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/SoundType.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/SoundType.java
|
||||
@@ -0,0 +0,0 @@ public class SoundType {
|
||||
public static final SoundType POLISHED_DEEPSLATE = new SoundType(1.0F, 1.0F, SoundEvents.POLISHED_DEEPSLATE_BREAK, SoundEvents.POLISHED_DEEPSLATE_STEP, SoundEvents.POLISHED_DEEPSLATE_PLACE, SoundEvents.POLISHED_DEEPSLATE_HIT, SoundEvents.POLISHED_DEEPSLATE_FALL);
|
||||
public final float volume;
|
||||
public final float pitch;
|
||||
- public final SoundEvent breakSound;
|
||||
+ public final SoundEvent breakSound; public final SoundEvent getBreakSound() { return this.breakSound; } // Paper - OBFHELPER // PAIL private -> public, rename breakSound
|
||||
private final SoundEvent stepSound;
|
||||
private final SoundEvent placeSound;
|
||||
- public final SoundEvent hitSound;
|
||||
+ public final SoundEvent hitSound; public final SoundEvent getHitSound() { return this.hitSound; } // Paper - OBFHELPER // PAIL private -> public, rename hitSound
|
||||
private final SoundEvent fallSound;
|
||||
|
||||
public SoundType(float volume, float pitch, SoundEvent breakSound, SoundEvent stepSound, SoundEvent placeSound, SoundEvent hitSound, SoundEvent fallSound) {
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||
@@ -0,0 +0,0 @@ public class CraftBlock implements Block {
|
||||
AABB aabb = shape.bounds();
|
||||
return new BoundingBox(this.getX() + aabb.minX, this.getY() + aabb.minY, this.getZ() + aabb.minZ, this.getX() + aabb.maxX, this.getY() + aabb.maxY, this.getZ() + aabb.maxZ);
|
||||
}
|
||||
+
|
||||
+ // Paper start
|
||||
+ @Override
|
||||
+ public com.destroystokyo.paper.block.BlockSoundGroup getSoundGroup() {
|
||||
+ return new com.destroystokyo.paper.block.CraftBlockSoundGroup(getNMSBlock().defaultBlockState().getSoundType());
|
||||
+ }
|
||||
+ // Paper end
|
||||
}
|
Reference in New Issue
Block a user