aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower-stripped/net/minecraft/world/level/Level.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower-stripped/net/minecraft/world/level/Level.java.patch')
-rw-r--r--patch-remap/mache-vineflower-stripped/net/minecraft/world/level/Level.java.patch341
1 files changed, 341 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower-stripped/net/minecraft/world/level/Level.java.patch b/patch-remap/mache-vineflower-stripped/net/minecraft/world/level/Level.java.patch
new file mode 100644
index 0000000000..1511956e29
--- /dev/null
+++ b/patch-remap/mache-vineflower-stripped/net/minecraft/world/level/Level.java.patch
@@ -0,0 +1,341 @@
+--- a/net/minecraft/world/level/Level.java
++++ b/net/minecraft/world/level/Level.java
+@@ -73,6 +79,27 @@
+ import net.minecraft.world.phys.Vec3;
+ import net.minecraft.world.scores.Scoreboard;
+
++// CraftBukkit start
++import java.util.HashMap;
++import java.util.Map;
++import net.minecraft.network.protocol.game.ClientboundSetBorderCenterPacket;
++import net.minecraft.network.protocol.game.ClientboundSetBorderLerpSizePacket;
++import net.minecraft.network.protocol.game.ClientboundSetBorderSizePacket;
++import net.minecraft.network.protocol.game.ClientboundSetBorderWarningDelayPacket;
++import net.minecraft.network.protocol.game.ClientboundSetBorderWarningDistancePacket;
++import org.bukkit.Bukkit;
++import org.bukkit.Location;
++import org.bukkit.craftbukkit.CraftServer;
++import org.bukkit.craftbukkit.CraftWorld;
++import org.bukkit.craftbukkit.block.CapturedBlockState;
++import org.bukkit.craftbukkit.block.data.CraftBlockData;
++import org.bukkit.craftbukkit.util.CraftSpawnCategory;
++import org.bukkit.craftbukkit.util.CraftNamespacedKey;
++import org.bukkit.entity.SpawnCategory;
++import org.bukkit.event.block.BlockPhysicsEvent;
++import org.bukkit.event.world.GenericGameEvent;
++// CraftBukkit end
++
+ public abstract class Level implements LevelAccessor, AutoCloseable {
+ public static final Codec<ResourceKey<Level>> RESOURCE_KEY_CODEC = ResourceKey.codec(Registries.DIMENSION);
+ public static final ResourceKey<Level> OVERWORLD = ResourceKey.create(Registries.DIMENSION, new ResourceLocation("overworld"));
+@@ -113,35 +142,63 @@
+ private final DamageSources damageSources;
+ private long subTickCount;
+
+- protected Level(
+- WritableLevelData levelData,
+- ResourceKey<Level> dimension,
+- RegistryAccess registryAccess,
+- Holder<DimensionType> dimensionTypeRegistration,
+- Supplier<ProfilerFiller> profiler,
+- boolean isClientSide,
+- boolean isDebug,
+- long biomeZoomSeed,
+- int maxChainedNeighborUpdates
+- ) {
+- this.profiler = profiler;
+- this.levelData = levelData;
+- this.dimensionTypeRegistration = dimensionTypeRegistration;
+- this.dimensionTypeId = dimensionTypeRegistration.unwrapKey()
+- .orElseThrow(() -> new IllegalArgumentException("Dimension must be registered, got " + dimensionTypeRegistration));
+- final DimensionType dimensionType = dimensionTypeRegistration.value();
+- this.dimension = dimension;
+- this.isClientSide = isClientSide;
+- if (dimensionType.coordinateScale() != 1.0) {
++ // CraftBukkit start Added the following
++ private final CraftWorld world;
++ public boolean pvpMode;
++ public boolean keepSpawnInMemory = true;
++ public org.bukkit.generator.ChunkGenerator generator;
++
++ public boolean preventPoiUpdated = false; // CraftBukkit - SPIGOT-5710
++ public boolean captureBlockStates = false;
++ public boolean captureTreeGeneration = false;
++ public Map<BlockPos, CapturedBlockState> capturedBlockStates = new java.util.LinkedHashMap<>();
++ public Map<BlockPos, BlockEntity> capturedTileEntities = new HashMap<>();
++ public List<ItemEntity> captureDrops;
++ public final it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<SpawnCategory> ticksPerSpawnCategory = new it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<>();
++ public boolean populating;
++
++ public CraftWorld getWorld() {
++ return this.world;
++ }
++
++ public CraftServer getCraftServer() {
++ return (CraftServer) Bukkit.getServer();
++ }
++
++ public abstract ResourceKey<LevelStem> getTypeKey();
++
++ protected Level(WritableLevelData worlddatamutable, ResourceKey<Level> resourcekey, RegistryAccess iregistrycustom, Holder<DimensionType> holder, Supplier<ProfilerFiller> supplier, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env) {
++ this.generator = gen;
++ this.world = new CraftWorld((ServerLevel) this, gen, biomeProvider, env);
++
++ // CraftBukkit Ticks things
++ for (SpawnCategory spawnCategory : SpawnCategory.values()) {
++ if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
++ this.ticksPerSpawnCategory.put(spawnCategory, (long) this.getCraftServer().getTicksPerSpawns(spawnCategory));
++ }
++ }
++
++ // CraftBukkit end
++ this.profiler = supplier;
++ this.levelData = worlddatamutable;
++ this.dimensionTypeRegistration = holder;
++ this.dimensionTypeId = (ResourceKey) holder.unwrapKey().orElseThrow(() -> {
++ return new IllegalArgumentException("Dimension must be registered, got " + holder);
++ });
++ final DimensionType dimensionmanager = (DimensionType) holder.value();
++
++ this.dimension = resourcekey;
++ this.isClientSide = flag;
++ if (dimensionmanager.coordinateScale() != 1.0D) {
+ this.worldBorder = new WorldBorder() {
+ @Override
+ public double getCenterX() {
+- return super.getCenterX() / dimensionType.coordinateScale();
++ return super.getCenterX(); // CraftBukkit
+ }
+
+ @Override
+ public double getCenterZ() {
+- return super.getCenterZ() / dimensionType.coordinateScale();
++ return super.getCenterZ(); // CraftBukkit
+ }
+ };
+ } else {
+@@ -149,11 +206,47 @@
+ }
+
+ this.thread = Thread.currentThread();
+- this.biomeManager = new BiomeManager(this, biomeZoomSeed);
+- this.isDebug = isDebug;
+- this.neighborUpdater = new CollectingNeighborUpdater(this, maxChainedNeighborUpdates);
+- this.registryAccess = registryAccess;
+- this.damageSources = new DamageSources(registryAccess);
++ this.biomeManager = new BiomeManager(this, i);
++ this.isDebug = flag1;
++ this.neighborUpdater = new CollectingNeighborUpdater(this, j);
++ this.registryAccess = iregistrycustom;
++ this.damageSources = new DamageSources(iregistrycustom);
++ // CraftBukkit start
++ getWorldBorder().world = (ServerLevel) this;
++ // From PlayerList.setPlayerFileData
++ getWorldBorder().addListener(new BorderChangeListener() {
++ @Override
++ public void onBorderSizeSet(WorldBorder border, double size) {
++ getCraftServer().getHandle().broadcastAll(new ClientboundSetBorderSizePacket(border), border.world);
++ }
++
++ @Override
++ public void onBorderSizeLerping(WorldBorder border, double oldSize, double d1, long newSize) {
++ getCraftServer().getHandle().broadcastAll(new ClientboundSetBorderLerpSizePacket(border), border.world);
++ }
++
++ @Override
++ public void onBorderCenterSet(WorldBorder border, double x, double d1) {
++ getCraftServer().getHandle().broadcastAll(new ClientboundSetBorderCenterPacket(border), border.world);
++ }
++
++ @Override
++ public void onBorderSetWarningTime(WorldBorder border, int warningTime) {
++ getCraftServer().getHandle().broadcastAll(new ClientboundSetBorderWarningDelayPacket(border), border.world);
++ }
++
++ @Override
++ public void onBorderSetWarningBlocks(WorldBorder border, int warningBlocks) {
++ getCraftServer().getHandle().broadcastAll(new ClientboundSetBorderWarningDistancePacket(border), border.world);
++ }
++
++ @Override
++ public void onBorderSetDamagePerBlock(WorldBorder border, double damagePerBlock) {}
++
++ @Override
++ public void onBorderSetDamageSafeZOne(WorldBorder border, double damageSafeZone) {}
++ });
++ // CraftBukkit end
+ }
+
+ @Override
+@@ -209,7 +303,18 @@
+ }
+
+ @Override
+- public boolean setBlock(BlockPos pos, BlockState state, int flags, int recursionLeft) {
++ public boolean setBlock(BlockPos pos, IBlockData state, int flags, int recursionLeft) {
++ // CraftBukkit start - tree generation
++ if (this.captureTreeGeneration) {
++ CapturedBlockState blockstate = capturedBlockStates.get(pos);
++ if (blockstate == null) {
++ blockstate = CapturedBlockState.getTreeBlockState(this, pos, flags);
++ this.capturedBlockStates.put(pos.immutable(), blockstate);
++ }
++ blockstate.setData(state);
++ return true;
++ }
++ // CraftBukkit end
+ if (this.isOutsideBuildHeight(pos)) {
+ return false;
+ } else if (!this.isClientSide && this.isDebug()) {
+@@ -217,8 +322,24 @@
+ } else {
+ LevelChunk chunkAt = this.getChunkAt(pos);
+ Block block = state.getBlock();
+- BlockState blockState = chunkAt.setBlockState(pos, state, (flags & 64) != 0);
+- if (blockState == null) {
++
++ // CraftBukkit start - capture blockstates
++ boolean captured = false;
++ if (this.captureBlockStates && !this.capturedBlockStates.containsKey(pos)) {
++ CapturedBlockState blockstate = CapturedBlockState.getBlockState(this, pos, flags);
++ this.capturedBlockStates.put(pos.immutable(), blockstate);
++ captured = true;
++ }
++ // CraftBukkit end
++
++ IBlockData iblockdata1 = chunk.setBlockState(pos, state, (flags & 64) != 0, (flags & 1024) == 0); // CraftBukkit custom NO_PLACE flag
++
++ if (iblockdata1 == null) {
++ // CraftBukkit start - remove blockstate if failed (or the same)
++ if (this.captureBlockStates && captured) {
++ this.capturedBlockStates.remove(pos);
++ }
++ // CraftBukkit end
+ return false;
+ } else {
+ BlockState blockState1 = this.getBlockState(pos);
+@@ -250,13 +373,66 @@
+ this.onBlockStateChange(pos, blockState, blockState1);
+ }
+
++ // CraftBukkit start
++ if (!this.captureBlockStates) { // Don't notify clients or update physics while capturing blockstates
++ // Modularize client and physic updates
++ notifyAndUpdatePhysics(pos, chunk, iblockdata1, state, iblockdata2, flags, recursionLeft);
++ }
++ // CraftBukkit end
++
+ return true;
+ }
+ }
+ }
+
+- public void onBlockStateChange(BlockPos pos, BlockState blockState, BlockState newState) {
++ // CraftBukkit start - Split off from above in order to directly send client and physic updates
++ public void notifyAndUpdatePhysics(BlockPos blockposition, LevelChunk chunk, IBlockData oldBlock, IBlockData newBlock, IBlockData actualBlock, int i, int j) {
++ IBlockData iblockdata = newBlock;
++ IBlockData iblockdata1 = oldBlock;
++ IBlockData iblockdata2 = actualBlock;
++ if (iblockdata2 == iblockdata) {
++ if (iblockdata1 != iblockdata2) {
++ this.setBlocksDirty(blockposition, iblockdata1, iblockdata2);
++ }
++
++ if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && (this.isClientSide || chunk == null || (chunk.getFullStatus() != null && chunk.getFullStatus().isOrAfter(FullChunkStatus.BLOCK_TICKING)))) { // allow chunk to be null here as chunk.isReady() is false when we send our notification during block placement
++ this.sendBlockUpdated(blockposition, iblockdata1, iblockdata, i);
++ }
++
++ if ((i & 1) != 0) {
++ this.blockUpdated(blockposition, iblockdata1.getBlock());
++ if (!this.isClientSide && iblockdata.hasAnalogOutputSignal()) {
++ this.updateNeighbourForOutputSignal(blockposition, newBlock.getBlock());
++ }
++ }
++
++ if ((i & 16) == 0 && j > 0) {
++ int k = i & -34;
++
++ // CraftBukkit start
++ iblockdata1.updateIndirectNeighbourShapes(this, blockposition, k, j - 1); // Don't call an event for the old block to limit event spam
++ CraftWorld world = ((ServerLevel) this).getWorld();
++ if (world != null) {
++ BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftBlockData.fromData(iblockdata));
++ this.getCraftServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ return;
++ }
++ }
++ // CraftBukkit end
++ iblockdata.updateNeighbourShapes(this, blockposition, k, j - 1);
++ iblockdata.updateIndirectNeighbourShapes(this, blockposition, k, j - 1);
++ }
++
++ // CraftBukkit start - SPIGOT-5710
++ if (!preventPoiUpdated) {
++ this.onBlockStateChange(blockposition, iblockdata1, iblockdata2);
++ }
++ // CraftBukkit end
++ }
+ }
++ // CraftBukkit end
+
+ @Override
+ public boolean removeBlock(BlockPos pos, boolean isMoving) {
+@@ -340,7 +518,15 @@
+ }
+
+ @Override
+- public BlockState getBlockState(BlockPos pos) {
++ public IBlockData getBlockState(BlockPos pos) {
++ // CraftBukkit start - tree generation
++ if (captureTreeGeneration) {
++ CapturedBlockState previous = capturedBlockStates.get(pos);
++ if (previous != null) {
++ return previous.getHandle();
++ }
++ }
++ // CraftBukkit end
+ if (this.isOutsideBuildHeight(pos)) {
+ return Blocks.VOID_AIR.defaultBlockState();
+ } else {
+@@ -630,19 +732,30 @@
+ @Nullable
+ @Override
+ public BlockEntity getBlockEntity(BlockPos pos) {
+- if (this.isOutsideBuildHeight(pos)) {
+- return null;
+- } else {
+- return !this.isClientSide && Thread.currentThread() != this.thread
+- ? null
+- : this.getChunkAt(pos).getBlockEntity(pos, LevelChunk.EntityCreationType.IMMEDIATE);
++ // CraftBukkit start
++ return getBlockEntity(pos, true);
++ }
++
++ @Nullable
++ public BlockEntity getBlockEntity(BlockPos blockposition, boolean validate) {
++ if (capturedTileEntities.containsKey(blockposition)) {
++ return capturedTileEntities.get(blockposition);
+ }
++ // CraftBukkit end
++ return this.isOutsideBuildHeight(blockposition) ? null : (!this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAt(blockposition).getBlockEntity(blockposition, LevelChunk.EnumTileEntityState.IMMEDIATE));
+ }
+
+ public void setBlockEntity(BlockEntity blockEntity) {
+- BlockPos blockPos = blockEntity.getBlockPos();
+- if (!this.isOutsideBuildHeight(blockPos)) {
+- this.getChunkAt(blockPos).addAndRegisterBlockEntity(blockEntity);
++ BlockPos blockposition = blockEntity.getBlockPos();
++
++ if (!this.isOutsideBuildHeight(blockposition)) {
++ // CraftBukkit start
++ if (captureBlockStates) {
++ capturedTileEntities.put(blockposition.immutable(), blockEntity);
++ return;
++ }
++ // CraftBukkit end
++ this.getChunkAt(blockposition).addAndRegisterBlockEntity(blockEntity);
+ }
+ }
+