Repackage patches

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2021-03-16 09:00:00 +11:00
parent 2777f7b780
commit 18496e998f
433 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
--- a/net/minecraft/server/BiomeStorage.java
+++ b/net/minecraft/server/BiomeStorage.java
@@ -87,4 +87,14 @@
return this.h[i1 << BiomeStorage.e + BiomeStorage.e | j1 << BiomeStorage.e | l];
}
+
+ // CraftBukkit start
+ public void setBiome(int i, int j, int k, BiomeBase biome) {
+ int l = i & BiomeStorage.b;
+ int i1 = MathHelper.clamp(j, 0, BiomeStorage.c);
+ int j1 = k & BiomeStorage.b;
+
+ this.h[i1 << BiomeStorage.e + BiomeStorage.e | j1 << BiomeStorage.e | l] = biome;
+ }
+ // CraftBukkit end
}

View File

@@ -0,0 +1,217 @@
--- a/net/minecraft/server/Chunk.java
+++ b/net/minecraft/server/Chunk.java
@@ -31,7 +31,7 @@
private BiomeStorage d;
private final Map<BlockPosition, NBTTagCompound> e;
public boolean loaded;
- public final World world;
+ public final WorldServer world; // CraftBukkit - type
public final Map<HeightMap.Type, HeightMap> heightMap;
private final ChunkConverter i;
public final Map<BlockPosition, TileEntity> tileEntities;
@@ -65,7 +65,7 @@
this.m = Maps.newHashMap();
this.n = new ShortList[16];
this.entitySlices = (EntitySlice[]) (new EntitySlice[16]);
- this.world = world;
+ this.world = (WorldServer) world; // CraftBukkit - type
this.loc = chunkcoordintpair;
this.i = chunkconverter;
HeightMap.Type[] aheightmap_type = HeightMap.Type.values();
@@ -96,8 +96,22 @@
}
}
+ // CraftBukkit start
+ this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
}
+ public org.bukkit.Chunk bukkitChunk;
+ public org.bukkit.Chunk getBukkitChunk() {
+ return bukkitChunk;
+ }
+
+ public boolean mustNotSave;
+ public boolean needsDecoration;
+
+ private static final org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry();
+ public final org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer persistentDataContainer = new org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer(DATA_TYPE_REGISTRY);
+ // CraftBukkit end
+
public Chunk(World world, ProtoChunk protochunk) {
this(world, protochunk.getPos(), protochunk.getBiomeIndex(), protochunk.p(), protochunk.n(), protochunk.o(), protochunk.getInhabitedTime(), protochunk.getSections(), (Consumer) null);
Iterator iterator = protochunk.y().iterator();
@@ -139,6 +153,7 @@
this.b(protochunk.r());
this.s = true;
+ this.needsDecoration = true; // CraftBukkit
}
@Override
@@ -229,9 +244,16 @@
}
}
+ // CraftBukkit start
@Nullable
@Override
public IBlockData setType(BlockPosition blockposition, IBlockData iblockdata, boolean flag) {
+ return this.setType(blockposition, iblockdata, flag, true);
+ }
+
+ @Nullable
+ public IBlockData setType(BlockPosition blockposition, IBlockData iblockdata, boolean flag, boolean doPlace) {
+ // CraftBukkit end
int i = blockposition.getX() & 15;
int j = blockposition.getY();
int k = blockposition.getZ() & 15;
@@ -283,7 +305,8 @@
}
}
- if (!this.world.isClientSide) {
+ // CraftBukkit - Don't place while processing the BlockPlaceEvent, unless it's a BlockContainer. Prevents blocks such as TNT from activating when cancelled.
+ if (!this.world.isClientSide && doPlace && (!this.world.captureBlockStates || block instanceof BlockTileEntity)) {
iblockdata.onPlace(this.world, blockposition, iblockdata1, flag);
}
@@ -378,7 +401,12 @@
@Nullable
public TileEntity a(BlockPosition blockposition, Chunk.EnumTileEntityState chunk_enumtileentitystate) {
- TileEntity tileentity = (TileEntity) this.tileEntities.get(blockposition);
+ // CraftBukkit start
+ TileEntity tileentity = world.capturedTileEntities.get(blockposition);
+ if (tileentity == null) {
+ tileentity = (TileEntity) this.tileEntities.get(blockposition);
+ }
+ // CraftBukkit end
if (tileentity == null) {
NBTTagCompound nbttagcompound = (NBTTagCompound) this.e.remove(blockposition);
@@ -424,6 +452,13 @@
tileentity1.al_();
}
+ // CraftBukkit start
+ } else {
+ System.out.println("Attempted to place a tile entity (" + tileentity + ") at " + tileentity.position.getX() + "," + tileentity.position.getY() + "," + tileentity.position.getZ()
+ + " (" + getType(blockposition) + ") where there was no entity tile!");
+ System.out.println("Chunk coordinates: " + (this.loc.x * 16) + "," + (this.loc.z * 16));
+ new Exception().printStackTrace();
+ // CraftBukkit end
}
}
@@ -473,6 +508,50 @@
}
+ // CraftBukkit start
+ public void loadCallback() {
+ org.bukkit.Server server = this.world.getServer();
+ if (server != null) {
+ /*
+ * If it's a new world, the first few chunks are generated inside
+ * the World constructor. We can't reliably alter that, so we have
+ * no way of creating a CraftWorld/CraftServer at that point.
+ */
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkLoadEvent(this.bukkitChunk, this.needsDecoration));
+
+ if (this.needsDecoration) {
+ this.needsDecoration = false;
+ java.util.Random random = new java.util.Random();
+ random.setSeed(world.getSeed());
+ long xRand = random.nextLong() / 2L * 2L + 1L;
+ long zRand = random.nextLong() / 2L * 2L + 1L;
+ random.setSeed((long) this.loc.x * xRand + (long) this.loc.z * zRand ^ world.getSeed());
+
+ org.bukkit.World world = this.world.getWorld();
+ if (world != null) {
+ this.world.populating = true;
+ try {
+ for (org.bukkit.generator.BlockPopulator populator : world.getPopulators()) {
+ populator.populate(world, random, bukkitChunk);
+ }
+ } finally {
+ this.world.populating = false;
+ }
+ }
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk));
+ }
+ }
+ }
+
+ public void unloadCallback() {
+ org.bukkit.Server server = this.world.getServer();
+ org.bukkit.event.world.ChunkUnloadEvent unloadEvent = new org.bukkit.event.world.ChunkUnloadEvent(this.bukkitChunk, this.isNeedsSaving());
+ server.getPluginManager().callEvent(unloadEvent);
+ // note: saving can be prevented, but not forced if no saving is actually required
+ this.mustNotSave = !unloadEvent.isSaveChunk();
+ }
+ // CraftBukkit end
+
public void markDirty() {
this.s = true;
}
@@ -526,7 +605,7 @@
Iterator iterator = this.entitySlices[k].a(Entity.class).iterator();
while (iterator.hasNext()) {
- Entity entity = (Entity) iterator.next();
+ T entity = (T) iterator.next(); // CraftBukkit - decompile error
if ((entitytypes == null || entity.getEntityType() == entitytypes) && entity.getBoundingBox().c(axisalignedbb) && predicate.test(entity)) {
list.add(entity);
@@ -547,7 +626,7 @@
Iterator iterator = this.entitySlices[k].a(oclass).iterator();
while (iterator.hasNext()) {
- T t0 = (Entity) iterator.next();
+ T t0 = (T) iterator.next(); // CraftBukkit - decompile error
if (t0.getBoundingBox().c(axisalignedbb) && (predicate == null || predicate.test(t0))) {
list.add(t0);
@@ -621,7 +700,7 @@
@Override
public boolean isNeedsSaving() {
- return this.s || this.q && this.world.getTime() != this.lastSaved;
+ return (this.s || this.q && this.world.getTime() != this.lastSaved) && !this.mustNotSave; // CraftBukkit
}
public void d(boolean flag) {
@@ -763,7 +842,7 @@
public void B() {
if (this.o instanceof ProtoChunkTickList) {
- ((ProtoChunkTickList) this.o).a(this.world.getBlockTickList(), (blockposition) -> {
+ ((ProtoChunkTickList<Block>) this.o).a(this.world.getBlockTickList(), (blockposition) -> { // CraftBukkit - decompile error
return this.getType(blockposition).getBlock();
});
this.o = TickListEmpty.b();
@@ -773,7 +852,7 @@
}
if (this.p instanceof ProtoChunkTickList) {
- ((ProtoChunkTickList) this.p).a(this.world.getFluidTickList(), (blockposition) -> {
+ ((ProtoChunkTickList<FluidType>) this.p).a(this.world.getFluidTickList(), (blockposition) -> { // CraftBukkit - decompile error
return this.getFluid(blockposition).getType();
});
this.p = TickListEmpty.b();
@@ -785,12 +864,12 @@
}
public void a(WorldServer worldserver) {
- if (this.o == TickListEmpty.b()) {
+ if (this.o == TickListEmpty.<Block>b()) { // CraftBukkit - decompile error
this.o = new TickListChunk<>(IRegistry.BLOCK::getKey, worldserver.getBlockTickList().a(this.loc, true, false), worldserver.getTime());
this.setNeedsSaving(true);
}
- if (this.p == TickListEmpty.b()) {
+ if (this.p == TickListEmpty.<FluidType>b()) { // CraftBukkit - decompile error
this.p = new TickListChunk<>(IRegistry.FLUID::getKey, worldserver.getFluidTickList().a(this.loc, true, false), worldserver.getTime());
this.setNeedsSaving(true);
}

View File

@@ -0,0 +1,35 @@
--- a/net/minecraft/server/ChunkGenerator.java
+++ b/net/minecraft/server/ChunkGenerator.java
@@ -210,7 +210,16 @@
while (iterator.hasNext()) {
Supplier<StructureFeature<?, ?>> supplier = (Supplier) iterator.next();
- this.a((StructureFeature) supplier.get(), iregistrycustom, structuremanager, ichunkaccess, definedstructuremanager, i, chunkcoordintpair, biomebase);
+ // CraftBukkit start
+ StructureFeature<?, ?> structurefeature = (StructureFeature) supplier.get();
+ if (structurefeature.c == StructureGenerator.STRONGHOLD) {
+ synchronized (structurefeature) {
+ this.a(structurefeature, iregistrycustom, structuremanager, ichunkaccess, definedstructuremanager, i, chunkcoordintpair, biomebase);
+ }
+ } else {
+ this.a(structurefeature, iregistrycustom, structuremanager, ichunkaccess, definedstructuremanager, i, chunkcoordintpair, biomebase);
+ }
+ // CraftBukkit end
}
}
@@ -294,9 +303,11 @@
}
static {
- IRegistry.a(IRegistry.CHUNK_GENERATOR, "noise", (Object) ChunkGeneratorAbstract.d);
- IRegistry.a(IRegistry.CHUNK_GENERATOR, "flat", (Object) ChunkProviderFlat.d);
- IRegistry.a(IRegistry.CHUNK_GENERATOR, "debug", (Object) ChunkProviderDebug.d);
+ // CraftBukkit start - decompile errors
+ IRegistry.a(IRegistry.CHUNK_GENERATOR, "noise", ChunkGeneratorAbstract.d);
+ IRegistry.a(IRegistry.CHUNK_GENERATOR, "flat", ChunkProviderFlat.d);
+ IRegistry.a(IRegistry.CHUNK_GENERATOR, "debug", ChunkProviderDebug.d);
+ // CraftBukkit end
a = IRegistry.CHUNK_GENERATOR.dispatchStable(ChunkGenerator::a, Function.identity());
}
}

View File

@@ -0,0 +1,20 @@
--- a/net/minecraft/server/ChunkStatus.java
+++ b/net/minecraft/server/ChunkStatus.java
@@ -27,7 +27,7 @@
});
public static final ChunkStatus STRUCTURE_STARTS = a("structure_starts", ChunkStatus.EMPTY, 0, ChunkStatus.n, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess) -> {
if (!ichunkaccess.getChunkStatus().b(chunkstatus)) {
- if (worldserver.getMinecraftServer().getSaveData().getGeneratorSettings().shouldGenerateMapFeatures()) {
+ if (worldserver.worldDataServer.getGeneratorSettings().shouldGenerateMapFeatures()) { // CraftBukkit
chunkgenerator.createStructures(worldserver.r(), worldserver.getStructureManager(), ichunkaccess, definedstructuremanager, worldserver.getSeed());
}
@@ -90,7 +90,7 @@
return (CompletableFuture) function.apply(ichunkaccess);
});
private static final List<ChunkStatus> q = ImmutableList.of(ChunkStatus.FULL, ChunkStatus.FEATURES, ChunkStatus.LIQUID_CARVERS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS);
- private static final IntList r = (IntList) SystemUtils.a((Object) (new IntArrayList(a().size())), (intarraylist) -> {
+ private static final IntList r = (IntList) SystemUtils.a((new IntArrayList(a().size())), (java.util.function.Consumer<IntArrayList>) (intarraylist) -> { // CraftBukkit - decompile error
int i = 0;
for (int j = a().size() - 1; j >= 0; --j) {

View File

@@ -0,0 +1,57 @@
--- a/net/minecraft/server/ChunkRegionLoader.java
+++ b/net/minecraft/server/ChunkRegionLoader.java
@@ -91,7 +91,7 @@
if (nbttagcompound1.hasKeyOfType("TileTicks", 9)) {
nbttaglist1 = nbttagcompound1.getList("TileTicks", 10);
- function = IRegistry.BLOCK::getKey;
+ function = (block) -> IRegistry.BLOCK.getKey((Block) block); // CraftBukkit - decompile error
registryblocks = IRegistry.BLOCK;
registryblocks.getClass();
object1 = TickListChunk.a(nbttaglist1, function, registryblocks::get);
@@ -103,7 +103,7 @@
if (nbttagcompound1.hasKeyOfType("LiquidTicks", 9)) {
nbttaglist1 = nbttagcompound1.getList("LiquidTicks", 10);
- function = IRegistry.FLUID::getKey;
+ function = (fluid) -> IRegistry.FLUID.getKey((FluidType) fluid); // CraftBukkit - decompile error
registryblocks = IRegistry.FLUID;
registryblocks.getClass();
object2 = TickListChunk.a(nbttaglist1, function, registryblocks::get);
@@ -113,6 +113,12 @@
object = new Chunk(worldserver.getMinecraftWorld(), chunkcoordintpair, biomestorage, chunkconverter, (TickList) object1, (TickList) object2, j, achunksection, (chunk) -> {
loadEntities(nbttagcompound1, chunk);
+ // CraftBukkit start - load chunk persistent data from nbt
+ NBTBase persistentBase = nbttagcompound1.get("ChunkBukkitValues");
+ if (persistentBase instanceof NBTTagCompound) {
+ chunk.persistentDataContainer.putAll((NBTTagCompound) persistentBase);
+ }
+ // CraftBukkit end
});
} else {
ProtoChunk protochunk = new ProtoChunk(chunkcoordintpair, chunkconverter, achunksection, protochunkticklist, protochunkticklist1);
@@ -246,8 +252,9 @@
NBTTagCompound nbttagcompound2;
for (int i = -1; i < 17; ++i) {
+ int finalI = i; // CraftBukkit - decompile errors
ChunkSection chunksection = (ChunkSection) Arrays.stream(achunksection).filter((chunksection1) -> {
- return chunksection1 != null && chunksection1.getYPosition() >> 4 == i;
+ return chunksection1 != null && chunksection1.getYPosition() >> 4 == finalI; // CraftBukkit - decompile errors
}).findFirst().orElse(Chunk.a);
NibbleArray nibblearray = lightenginethreaded.a(EnumSkyBlock.BLOCK).a(SectionPosition.a(chunkcoordintpair, i));
NibbleArray nibblearray1 = lightenginethreaded.a(EnumSkyBlock.SKY).a(SectionPosition.a(chunkcoordintpair, i));
@@ -302,6 +309,12 @@
if (ichunkaccess.getChunkStatus().getType() == ChunkStatus.Type.LEVELCHUNK) {
Chunk chunk = (Chunk) ichunkaccess;
+ // CraftBukkit start - store chunk persistent data in nbt
+ if (!chunk.persistentDataContainer.isEmpty()) {
+ nbttagcompound1.set("ChunkBukkitValues", chunk.persistentDataContainer.toTagCompound());
+ }
+ // CraftBukkit end
+
chunk.d(false);
for (int j = 0; j < chunk.getEntitySlices().length; ++j) {

View File

@@ -0,0 +1,53 @@
--- a/net/minecraft/server/IChunkLoader.java
+++ b/net/minecraft/server/IChunkLoader.java
@@ -18,10 +18,49 @@
this.a = new IOWorker(file, flag, "chunk");
}
- public NBTTagCompound getChunkData(ResourceKey<World> resourcekey, Supplier<WorldPersistentData> supplier, NBTTagCompound nbttagcompound) {
+ // CraftBukkit start
+ private boolean check(ChunkProviderServer cps, int x, int z) throws IOException {
+ ChunkCoordIntPair pos = new ChunkCoordIntPair(x, z);
+ if (cps != null) {
+ com.google.common.base.Preconditions.checkState(org.bukkit.Bukkit.isPrimaryThread(), "primary thread");
+ if (cps.isLoaded(x, z)) {
+ return true;
+ }
+ }
+
+ NBTTagCompound nbt = read(pos);
+ if (nbt != null) {
+ NBTTagCompound level = nbt.getCompound("Level");
+ if (level.getBoolean("TerrainPopulated")) {
+ return true;
+ }
+
+ ChunkStatus status = ChunkStatus.a(level.getString("Status"));
+ if (status != null && status.b(ChunkStatus.FEATURES)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public NBTTagCompound getChunkData(ResourceKey<DimensionManager> resourcekey, Supplier<WorldPersistentData> supplier, NBTTagCompound nbttagcompound, ChunkCoordIntPair pos, @Nullable GeneratorAccess generatoraccess) throws IOException {
+ // CraftBukkit end
int i = a(nbttagcompound);
boolean flag = true;
+ // CraftBukkit start
+ if (i < 1466) {
+ NBTTagCompound level = nbttagcompound.getCompound("Level");
+ if (level.getBoolean("TerrainPopulated") && !level.getBoolean("LightPopulated")) {
+ ChunkProviderServer cps = (generatoraccess == null) ? null : ((WorldServer) generatoraccess).getChunkProvider();
+ if (check(cps, pos.x - 1, pos.z) && check(cps, pos.x - 1, pos.z - 1) && check(cps, pos.x, pos.z - 1)) {
+ level.setBoolean("LightPopulated", true);
+ }
+ }
+ }
+ // CraftBukkit end
+
if (i < 1493) {
nbttagcompound = GameProfileSerializer.a(this.b, DataFixTypes.CHUNK, nbttagcompound, i, 1493);
if (nbttagcompound.getCompound("Level").getBoolean("hasLegacyStructureData")) {

View File

@@ -0,0 +1,42 @@
--- a/net/minecraft/server/RegionFileCache.java
+++ b/net/minecraft/server/RegionFileCache.java
@@ -21,7 +21,7 @@
this.c = flag;
}
- private RegionFile getFile(ChunkCoordIntPair chunkcoordintpair) throws IOException {
+ private RegionFile getFile(ChunkCoordIntPair chunkcoordintpair, boolean existingOnly) throws IOException { // CraftBukkit
long i = ChunkCoordIntPair.pair(chunkcoordintpair.getRegionX(), chunkcoordintpair.getRegionZ());
RegionFile regionfile = (RegionFile) this.cache.getAndMoveToFirst(i);
@@ -37,6 +37,7 @@
}
File file = new File(this.b, "r." + chunkcoordintpair.getRegionX() + "." + chunkcoordintpair.getRegionZ() + ".mca");
+ if (existingOnly && !file.exists()) return null; // CraftBukkit
RegionFile regionfile1 = new RegionFile(file, this.b, this.c);
this.cache.putAndMoveToFirst(i, regionfile1);
@@ -46,7 +47,12 @@
@Nullable
public NBTTagCompound read(ChunkCoordIntPair chunkcoordintpair) throws IOException {
- RegionFile regionfile = this.getFile(chunkcoordintpair);
+ // CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
+ RegionFile regionfile = this.getFile(chunkcoordintpair, true);
+ if (regionfile == null) {
+ return null;
+ }
+ // CraftBukkit end
DataInputStream datainputstream = regionfile.a(chunkcoordintpair);
Throwable throwable = null;
@@ -81,7 +87,7 @@
}
protected void write(ChunkCoordIntPair chunkcoordintpair, NBTTagCompound nbttagcompound) throws IOException {
- RegionFile regionfile = this.getFile(chunkcoordintpair);
+ RegionFile regionfile = this.getFile(chunkcoordintpair, false); // CraftBukkit
DataOutputStream dataoutputstream = regionfile.c(chunkcoordintpair);
Throwable throwable = null;