MC Utils
== AT == public net.minecraft.server.level.ServerChunkCache mainThread public net.minecraft.server.level.ServerLevel chunkSource public org.bukkit.craftbukkit.inventory.CraftItemStack handle public net.minecraft.server.level.ChunkMap getVisibleChunkIfPresent(J)Lnet/minecraft/server/level/ChunkHolder; public net.minecraft.server.level.ServerChunkCache mainThreadProcessor public net.minecraft.server.level.ServerChunkCache$MainThreadExecutor public net.minecraft.world.level.chunk.LevelChunkSection states
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
--- a/net/minecraft/world/level/chunk/ChunkAccess.java
|
||||
+++ b/net/minecraft/world/level/chunk/ChunkAccess.java
|
||||
@@ -85,6 +85,11 @@
|
||||
@@ -65,7 +65,7 @@
|
||||
protected final ShortList[] postProcessing;
|
||||
private volatile boolean unsaved;
|
||||
private volatile boolean isLightCorrect;
|
||||
- protected final ChunkPos chunkPos;
|
||||
+ protected final ChunkPos chunkPos; public final long coordinateKey; public final int locX; public final int locZ; // Paper - cache coordinate key
|
||||
private long inhabitedTime;
|
||||
/** @deprecated */
|
||||
@Nullable
|
||||
@@ -85,8 +85,14 @@
|
||||
protected final LevelHeightAccessor levelHeightAccessor;
|
||||
protected final LevelChunkSection[] sections;
|
||||
|
||||
@@ -10,9 +19,13 @@
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public ChunkAccess(ChunkPos pos, UpgradeData upgradeData, LevelHeightAccessor heightLimitView, Registry<Biome> biomeRegistry, long inhabitedTime, @Nullable LevelChunkSection[] sectionArray, @Nullable BlendingData blendingData) {
|
||||
this.chunkPos = pos;
|
||||
- this.chunkPos = pos;
|
||||
+ this.locX = pos.x; this.locZ = pos.z; // Paper - reduce need for field lookups
|
||||
+ this.chunkPos = pos; this.coordinateKey = ChunkPos.asLong(locX, locZ); // Paper - cache long key
|
||||
this.upgradeData = upgradeData;
|
||||
@@ -103,7 +108,11 @@
|
||||
this.levelHeightAccessor = heightLimitView;
|
||||
this.sections = new LevelChunkSection[heightLimitView.getSectionsCount()];
|
||||
@@ -103,7 +109,11 @@
|
||||
}
|
||||
|
||||
ChunkAccess.replaceMissingSections(biomeRegistry, this.sections);
|
||||
@@ -24,7 +37,7 @@
|
||||
|
||||
private static void replaceMissingSections(Registry<Biome> biomeRegistry, LevelChunkSection[] sectionArray) {
|
||||
for (int i = 0; i < sectionArray.length; ++i) {
|
||||
@@ -275,6 +284,7 @@
|
||||
@@ -275,6 +285,7 @@
|
||||
public boolean tryMarkSaved() {
|
||||
if (this.unsaved) {
|
||||
this.unsaved = false;
|
||||
@@ -32,7 +45,7 @@
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -282,7 +292,7 @@
|
||||
@@ -282,7 +293,7 @@
|
||||
}
|
||||
|
||||
public boolean isUnsaved() {
|
||||
@@ -41,10 +54,15 @@
|
||||
}
|
||||
|
||||
public abstract ChunkStatus getPersistedStatus();
|
||||
@@ -463,6 +473,27 @@
|
||||
}
|
||||
}
|
||||
@@ -458,10 +469,31 @@
|
||||
|
||||
crashreportsystemdetails.setDetail("Location", () -> {
|
||||
return CrashReportCategory.formatLocation(this, biomeX, biomeY, biomeZ);
|
||||
+ });
|
||||
+ throw new ReportedException(crashreport);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ public void setBiome(int i, int j, int k, Holder<Biome> biome) {
|
||||
+ try {
|
||||
@@ -60,12 +78,11 @@
|
||||
+
|
||||
+ crashreportsystemdetails.setDetail("Location", () -> {
|
||||
+ return CrashReportCategory.formatLocation(this, i, j, k);
|
||||
+ });
|
||||
+ throw new ReportedException(crashreport);
|
||||
+ }
|
||||
+ }
|
||||
});
|
||||
throw new ReportedException(crashreport);
|
||||
}
|
||||
}
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
|
||||
public void fillBiomesFromNoise(BiomeResolver biomeSupplier, Climate.Sampler sampler) {
|
||||
ChunkPos chunkcoordintpair = this.getPos();
|
||||
int i = QuartPos.fromBlock(chunkcoordintpair.getMinBlockX());
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
--- a/net/minecraft/world/level/chunk/EmptyLevelChunk.java
|
||||
+++ b/net/minecraft/world/level/chunk/EmptyLevelChunk.java
|
||||
@@ -25,6 +25,12 @@
|
||||
public BlockState getBlockState(BlockPos pos) {
|
||||
return Blocks.VOID_AIR.defaultBlockState();
|
||||
}
|
||||
+ // Paper start
|
||||
+ @Override
|
||||
+ public BlockState getBlockState(final int x, final int y, final int z) {
|
||||
+ return Blocks.VOID_AIR.defaultBlockState();
|
||||
+ }
|
||||
+ // Paper end
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@@ -18,7 +18,7 @@
|
||||
this.gameEventListenerRegistrySections = new Int2ObjectOpenHashMap();
|
||||
Heightmap.Types[] aheightmap_type = Heightmap.Types.values();
|
||||
int j = aheightmap_type.length;
|
||||
@@ -116,6 +116,11 @@
|
||||
@@ -116,6 +116,15 @@
|
||||
this.fluidTicks = fluidTickScheduler;
|
||||
}
|
||||
|
||||
@@ -26,11 +26,15 @@
|
||||
+ public boolean mustNotSave;
|
||||
+ public boolean needsDecoration;
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
+ // Paper start
|
||||
+ boolean loadedTicketLevel;
|
||||
+ // Paper end
|
||||
+
|
||||
public LevelChunk(ServerLevel world, ProtoChunk protoChunk, @Nullable LevelChunk.PostLoadProcessor entityLoader) {
|
||||
this(world, protoChunk.getPos(), protoChunk.getUpgradeData(), protoChunk.unpackBlockTicks(), protoChunk.unpackFluidTicks(), protoChunk.getInhabitedTime(), protoChunk.getSections(), entityLoader, protoChunk.getBlendingData());
|
||||
if (!Collections.disjoint(protoChunk.pendingBlockEntities.keySet(), protoChunk.blockEntities.keySet())) {
|
||||
@@ -151,6 +156,10 @@
|
||||
@@ -151,6 +160,10 @@
|
||||
this.skyLightSources = protoChunk.skyLightSources;
|
||||
this.setLightCorrect(protoChunk.isLightCorrect());
|
||||
this.markUnsaved();
|
||||
@@ -41,7 +45,53 @@
|
||||
}
|
||||
|
||||
public void setUnsavedListener(LevelChunk.UnsavedListener unsavedListener) {
|
||||
@@ -272,78 +281,86 @@
|
||||
@@ -200,8 +213,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ // Paper start - Perf: Reduce instructions and provide final method
|
||||
+ public BlockState getBlockState(final int x, final int y, final int z) {
|
||||
+ return this.getBlockStateFinal(x, y, z);
|
||||
+ }
|
||||
+ public BlockState getBlockStateFinal(final int x, final int y, final int z) {
|
||||
+ // Copied and modified from below
|
||||
+ final int sectionIndex = this.getSectionIndex(y);
|
||||
+ if (sectionIndex < 0 || sectionIndex >= this.sections.length
|
||||
+ || this.sections[sectionIndex].nonEmptyBlockCount == 0) {
|
||||
+ return Blocks.AIR.defaultBlockState();
|
||||
+ }
|
||||
+ return this.sections[sectionIndex].states.get((y & 15) << 8 | (z & 15) << 4 | x & 15);
|
||||
+ }
|
||||
@Override
|
||||
public BlockState getBlockState(BlockPos pos) {
|
||||
+ if (true) {
|
||||
+ return this.getBlockStateFinal(pos.getX(), pos.getY(), pos.getZ());
|
||||
+ }
|
||||
+ // Paper end - Perf: Reduce instructions and provide final method
|
||||
int i = pos.getX();
|
||||
int j = pos.getY();
|
||||
int k = pos.getZ();
|
||||
@@ -243,7 +273,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ // Paper start - If loaded util
|
||||
@Override
|
||||
+ public final FluidState getFluidIfLoaded(BlockPos blockposition) {
|
||||
+ return this.getFluidState(blockposition);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public final BlockState getBlockStateIfLoaded(BlockPos blockposition) {
|
||||
+ return this.getBlockState(blockposition);
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
+ @Override
|
||||
public FluidState getFluidState(BlockPos pos) {
|
||||
return this.getFluidState(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
@@ -272,78 +314,86 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +203,7 @@
|
||||
this.updateBlockEntityTicker(tileentity);
|
||||
}
|
||||
}
|
||||
@@ -375,7 +392,12 @@
|
||||
@@ -375,7 +425,12 @@
|
||||
|
||||
@Nullable
|
||||
public BlockEntity getBlockEntity(BlockPos pos, LevelChunk.EntityCreationType creationType) {
|
||||
@@ -167,7 +217,7 @@
|
||||
|
||||
if (tileentity == null) {
|
||||
CompoundTag nbttagcompound = (CompoundTag) this.pendingBlockEntities.remove(pos);
|
||||
@@ -447,6 +469,7 @@
|
||||
@@ -447,6 +502,7 @@
|
||||
|
||||
if (!iblockdata.hasBlockEntity()) {
|
||||
LevelChunk.LOGGER.warn("Trying to set block entity {} at position {}, but state {} does not allow it", new Object[]{blockEntity, blockposition, iblockdata});
|
||||
@@ -175,7 +225,7 @@
|
||||
} else {
|
||||
BlockState iblockdata1 = blockEntity.getBlockState();
|
||||
|
||||
@@ -500,6 +523,12 @@
|
||||
@@ -500,6 +556,12 @@
|
||||
if (this.isInLevel()) {
|
||||
BlockEntity tileentity = (BlockEntity) this.blockEntities.remove(pos);
|
||||
|
||||
@@ -188,7 +238,7 @@
|
||||
if (tileentity != null) {
|
||||
Level world = this.level;
|
||||
|
||||
@@ -549,10 +578,61 @@
|
||||
@@ -549,9 +611,68 @@
|
||||
if (this.postLoad != null) {
|
||||
this.postLoad.run(this);
|
||||
this.postLoad = null;
|
||||
@@ -198,7 +248,11 @@
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ public void loadCallback() {
|
||||
+ // Paper start
|
||||
+ this.loadedTicketLevel = true;
|
||||
+ // Paper end
|
||||
+ org.bukkit.Server server = this.level.getCraftServer();
|
||||
+ this.level.getChunkSource().addLoadedChunk(this); // Paper
|
||||
+ if (server != null) {
|
||||
+ /*
|
||||
+ * If it's a new world, the first few chunks are generated inside
|
||||
@@ -239,18 +293,21 @@
|
||||
+ server.getPluginManager().callEvent(unloadEvent);
|
||||
+ // note: saving can be prevented, but not forced if no saving is actually required
|
||||
+ this.mustNotSave = !unloadEvent.isSaveChunk();
|
||||
}
|
||||
|
||||
+ this.level.getChunkSource().removeLoadedChunk(this); // Paper
|
||||
+ // Paper start
|
||||
+ this.loadedTicketLevel = false;
|
||||
+ // Paper end
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isUnsaved() {
|
||||
+ return super.isUnsaved() && !this.mustNotSave;
|
||||
+ }
|
||||
}
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
@@ -750,7 +830,7 @@
|
||||
@@ -750,7 +871,7 @@
|
||||
|
||||
private <T extends BlockEntity> void updateBlockEntityTicker(T blockEntity) {
|
||||
BlockState iblockdata = blockEntity.getBlockState();
|
||||
@@ -259,7 +316,7 @@
|
||||
|
||||
if (blockentityticker == null) {
|
||||
this.removeBlockEntityTicker(blockEntity.getBlockPos());
|
||||
@@ -841,7 +921,7 @@
|
||||
@@ -841,7 +962,7 @@
|
||||
private boolean loggedInvalidBlockState;
|
||||
|
||||
BoundTickingBlockEntity(final BlockEntity tileentity, final BlockEntityTicker blockentityticker) {
|
||||
@@ -268,7 +325,7 @@
|
||||
this.ticker = blockentityticker;
|
||||
}
|
||||
|
||||
@@ -855,6 +935,7 @@
|
||||
@@ -855,6 +976,7 @@
|
||||
ProfilerFiller gameprofilerfiller = Profiler.get();
|
||||
|
||||
gameprofilerfiller.push(this::getType);
|
||||
@@ -276,7 +333,7 @@
|
||||
BlockState iblockdata = LevelChunk.this.getBlockState(blockposition);
|
||||
|
||||
if (this.blockEntity.getType().isValid(iblockdata)) {
|
||||
@@ -872,6 +953,10 @@
|
||||
@@ -872,6 +994,10 @@
|
||||
|
||||
this.blockEntity.fillCrashReportCategory(crashreportsystemdetails);
|
||||
throw new ReportedException(crashreport);
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
--- a/net/minecraft/world/level/chunk/LevelChunkSection.java
|
||||
+++ b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
||||
@@ -23,7 +23,7 @@
|
||||
@@ -19,11 +19,11 @@
|
||||
public static final int SECTION_HEIGHT = 16;
|
||||
public static final int SECTION_SIZE = 4096;
|
||||
public static final int BIOME_CONTAINER_BITS = 2;
|
||||
- private short nonEmptyBlockCount;
|
||||
+ short nonEmptyBlockCount; // Paper - package private
|
||||
private short tickingBlockCount;
|
||||
private short tickingFluidCount;
|
||||
public final PalettedContainer<BlockState> states;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
--- a/net/minecraft/world/level/chunk/ProtoChunk.java
|
||||
+++ b/net/minecraft/world/level/chunk/ProtoChunk.java
|
||||
@@ -81,7 +81,19 @@
|
||||
@Override
|
||||
public ChunkAccess.PackedTicks getTicksForSerialization(long time) {
|
||||
return new ChunkAccess.PackedTicks(this.blockTicks.pack(time), this.fluidTicks.pack(time));
|
||||
+ }
|
||||
+
|
||||
+ // Paper start - If loaded util
|
||||
+ @Override
|
||||
+ public final FluidState getFluidIfLoaded(BlockPos blockposition) {
|
||||
+ return this.getFluidState(blockposition);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public final BlockState getBlockStateIfLoaded(BlockPos blockposition) {
|
||||
+ return this.getBlockState(blockposition);
|
||||
}
|
||||
+ // Paper end
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(BlockPos pos) {
|
||||
@@ -18,9 +18,12 @@
|
||||
ChunkStatusTasks.postLoadProtoChunk(worldserver, protochunk.getEntities());
|
||||
});
|
||||
generationchunkholder.replaceProtoChunk(new ImposterProtoChunk(chunk1, false));
|
||||
@@ -170,7 +170,17 @@
|
||||
@@ -168,9 +168,19 @@
|
||||
}, context.mainThreadExecutor());
|
||||
}
|
||||
|
||||
private static void postLoadProtoChunk(ServerLevel world, List<CompoundTag> entities) {
|
||||
- private static void postLoadProtoChunk(ServerLevel world, List<CompoundTag> entities) {
|
||||
+ public static void postLoadProtoChunk(ServerLevel world, List<CompoundTag> entities) { // Paper - public
|
||||
if (!entities.isEmpty()) {
|
||||
- world.addWorldGenChunkEntities(EntityType.loadEntitiesRecursive(entities, world, EntitySpawnReason.LOAD));
|
||||
+ // CraftBukkit start - these are spawned serialized (DefinedStructure) and we don't call an add event below at the moment due to ordering complexities
|
||||
|
||||
Reference in New Issue
Block a user