Files
OldSliceMC/patches/server/0002-Set-BlockData-without-light-updates.patch
Cryptite acc0ce346d 1.20.2
2023-11-06 08:25:12 -06:00

265 lines
16 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cryptite <cryptite@gmail.com>
Date: Mon, 10 Apr 2023 07:29:11 -0500
Subject: [PATCH] Set BlockData without light updates
diff --git a/src/main/java/net/minecraft/server/level/WorldGenRegion.java b/src/main/java/net/minecraft/server/level/WorldGenRegion.java
index 50ed7cfe1ecef6d075ba484804827cec83ba2bf2..6fefbd2ba0fb7aab592cb3ed00828cce942a4792 100644
--- a/src/main/java/net/minecraft/server/level/WorldGenRegion.java
+++ b/src/main/java/net/minecraft/server/level/WorldGenRegion.java
@@ -256,7 +256,7 @@ public class WorldGenRegion implements WorldGenLevel {
Block.dropResources(iblockdata, this.level, pos, tileentity, breakingEntity, ItemStack.EMPTY);
}
- return this.setBlock(pos, Blocks.AIR.defaultBlockState(), 3, maxUpdateDepth);
+ return this.setBlock(pos, Blocks.AIR.defaultBlockState(), 3, maxUpdateDepth, true); // Slice
}
}
@@ -331,7 +331,7 @@ public class WorldGenRegion implements WorldGenLevel {
}
@Override
- public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) {
+ public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, boolean checkLight) { // Slice
if (!this.ensureCanWrite(pos)) {
return false;
} else {
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 2354a0e5d15e9be633d9fe3a1a9feefe7b9b7782..763165618a47d9841bb8fc70651a4e80a2bbd67f 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -903,12 +903,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
}
@Override
- public final boolean setBlock(BlockPos pos, BlockState state, int flags) { // Paper - final for inline
- return this.setBlock(pos, state, flags, 512);
+ public final boolean setBlock(BlockPos pos, BlockState state, int flags, boolean checkLight) { // Paper - final for inline
+ return this.setBlock(pos, state, flags, 512, checkLight);
}
@Override
- public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) {
+ public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, boolean checkLight) {
// CraftBukkit start - tree generation
if (this.captureTreeGeneration) {
// Paper start
@@ -943,7 +943,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
}
// CraftBukkit end
- BlockState iblockdata1 = chunk.setBlockState(pos, state, (flags & 64) != 0, (flags & 1024) == 0); // CraftBukkit custom NO_PLACE flag
+ BlockState iblockdata1 = chunk.setBlockState(pos, state, (flags & 64) != 0, (flags & 1024) == 0, checkLight); // CraftBukkit custom NO_PLACE flag // Slice
this.chunkPacketBlockController.onBlockChange(this, pos, state, iblockdata1, flags, maxUpdateDepth); // Paper - Anti-Xray
if (iblockdata1 == null) {
@@ -1099,7 +1099,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
Block.dropResources(iblockdata, this, pos, tileentity, breakingEntity, ItemStack.EMPTY);
}
- boolean flag1 = this.setBlock(pos, fluid.createLegacyBlock(), 3, maxUpdateDepth);
+ boolean flag1 = this.setBlock(pos, fluid.createLegacyBlock(), 3, maxUpdateDepth, true);
if (flag1) {
this.gameEvent(GameEvent.BLOCK_DESTROY, pos, GameEvent.Context.of(breakingEntity, iblockdata));
diff --git a/src/main/java/net/minecraft/world/level/LevelWriter.java b/src/main/java/net/minecraft/world/level/LevelWriter.java
index 134e5ec79bf2dddd4e31930f8a7cb2c02fa29518..fd72d278a2719911a46b6bc9e7da2dc24bbe681e 100644
--- a/src/main/java/net/minecraft/world/level/LevelWriter.java
+++ b/src/main/java/net/minecraft/world/level/LevelWriter.java
@@ -7,10 +7,14 @@ import net.minecraft.world.level.block.state.BlockState;
public interface LevelWriter {
- boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth);
+ boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, boolean checkLight);
default boolean setBlock(BlockPos pos, BlockState state, int flags) {
- return this.setBlock(pos, state, flags, 512);
+ return this.setBlock(pos, state, flags, 512, true);
+ }
+
+ default boolean setBlock(BlockPos pos, BlockState state, int flags, boolean checkLight) {
+ return this.setBlock(pos, state, flags, 512, checkLight);
}
boolean removeBlock(BlockPos pos, boolean move);
diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
index d4cbff18adb62073a1dceb189043789620af6877..413eb8d315f5da04c69e082654e74054055705d6 100644
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
@@ -194,7 +194,7 @@ public class Block extends BlockBehaviour implements ItemLike {
world.destroyBlock(pos, (flags & 32) == 0, (Entity) null, maxUpdateDepth);
}
} else {
- world.setBlock(pos, newState, flags & -33, maxUpdateDepth);
+ world.setBlock(pos, newState, flags & -33, maxUpdateDepth, true); // Slice
}
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
index f7e5e016a7028a9196e689e950805b0d5b31fe38..10f8b1bfaca8cf607d895412417ad5f5e8d06df1 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
@@ -175,7 +175,6 @@ public abstract class ChunkAccess implements BlockGetter, BiomeManager.NoiseBiom
public abstract BlockState getBlockState(final int x, final int y, final int z); // Paper
@Nullable
public abstract BlockState setBlockState(BlockPos pos, BlockState state, boolean moved);
-
public abstract void setBlockEntity(BlockEntity blockEntity);
public abstract void addEntity(Entity entity);
diff --git a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
index 4a3ac7dedf5cb1e76f16ec4f18e82afc717d0ced..7eb5d6bc790717aef2b22453f5c16644fa128b7c 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
@@ -116,7 +116,13 @@ public class ImposterProtoChunk extends ProtoChunk {
@Nullable
@Override
public BlockState setBlockState(BlockPos pos, BlockState state, boolean moved) {
- return this.allowWrites ? this.wrapped.setBlockState(pos, state, moved) : null;
+ return setBlockState(pos, state, moved, true);
+ }
+
+ @Nullable
+ @Override
+ public BlockState setBlockState(BlockPos pos, BlockState state, boolean moved, boolean checkLight) {
+ return this.allowWrites ? this.wrapped.setBlockState(pos, state, moved, checkLight) : null;
}
@Override
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
index fa170cc1ce7011d201295b89718292d696c7fc24..55ac6607b3c0f31a478122e84ed97d85da80dcac 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
@@ -407,11 +407,15 @@ public class LevelChunk extends ChunkAccess {
@Nullable
@Override
public BlockState setBlockState(BlockPos pos, BlockState state, boolean moved) {
- return this.setBlockState(pos, state, moved, true);
+ return this.setBlockState(pos, state, moved, true, true);
+ }
+ @Nullable
+ public BlockState setBlockState(BlockPos pos, BlockState state, boolean moved, boolean doPlace) {
+ return this.setBlockState(pos, state, moved, doPlace, true);
}
@Nullable
- public BlockState setBlockState(BlockPos blockposition, BlockState iblockdata, boolean flag, boolean doPlace) {
+ public BlockState setBlockState(BlockPos blockposition, BlockState iblockdata, boolean flag, boolean doPlace, boolean checkLight) {
// CraftBukkit end
int i = blockposition.getY();
LevelChunkSection chunksection = this.getSection(this.getSectionIndex(i));
@@ -440,7 +444,7 @@ public class LevelChunk extends ChunkAccess {
this.level.getChunkSource().getLightEngine().updateSectionStatus(blockposition, flag2);
}
- if (LightEngine.hasDifferentLightProperties(this, blockposition, iblockdata1, iblockdata)) {
+ if (checkLight && LightEngine.hasDifferentLightProperties(this, blockposition, iblockdata1, iblockdata)) { // Slice
ProfilerFiller gameprofilerfiller = this.level.getProfiler();
gameprofilerfiller.push("updateSkyLightSources");
diff --git a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
index 7aa585875dad5296526bb5d67fc5ea0f8875e452..82432ef8b9d50ba96363b8db48150a4a52142a1d 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
@@ -113,6 +113,11 @@ public class ProtoChunk extends ChunkAccess {
@Nullable
@Override
public BlockState setBlockState(BlockPos pos, BlockState state, boolean moved) {
+ return setBlockState(pos, state, moved, true);
+ }
+
+ @Nullable
+ public BlockState setBlockState(BlockPos pos, BlockState state, boolean moved, boolean checkLight) { // Slice
int i = pos.getX();
int j = pos.getY();
int k = pos.getZ();
@@ -133,7 +138,7 @@ public class ProtoChunk extends ChunkAccess {
this.lightEngine.updateSectionStatus(pos, bl2);
}
- if (LightEngine.hasDifferentLightProperties(this, pos, blockState, state)) {
+ if (checkLight && LightEngine.hasDifferentLightProperties(this, pos, blockState, state)) { // Slice
// Paper - starlight - remove skyLightSources
this.lightEngine.checkBlock(pos);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
index 1a17875426468b287c8ea3f559ea516d0218f7a0..84a1150438dc8cdd8a6d3ad92e6bf2c4ad5f7cf0 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
@@ -287,7 +287,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
BlockPos pos = new BlockPos(x, y, z);
net.minecraft.world.level.block.state.BlockState old = this.getHandle().getBlockState(pos);
- CraftBlock.setTypeAndData(world, pos, old, ((CraftBlockData) blockData).getState(), true);
+ CraftBlock.setTypeAndData(world, pos, old, ((CraftBlockData) blockData).getState(), true, true);
}
@Override
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
index bec8e6b62dba2bd0e4e85a7d1fb51287384f1290..db565a24591748f66e01b9972796415ba2bf0f70 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
@@ -182,15 +182,20 @@ public class CraftBlock implements Block {
@Override
public void setBlockData(BlockData data, boolean applyPhysics) {
+ setBlockData(data, applyPhysics, true);
+ }
+
+ @Override
+ public void setBlockData(BlockData data, boolean applyPhysics, boolean checkLight) {
Preconditions.checkArgument(data != null, "BlockData cannot be null");
- this.setTypeAndData(((CraftBlockData) data).getState(), applyPhysics);
+ this.setTypeAndData(((CraftBlockData) data).getState(), applyPhysics, checkLight);
}
- boolean setTypeAndData(final net.minecraft.world.level.block.state.BlockState blockData, final boolean applyPhysics) {
- return CraftBlock.setTypeAndData(this.world, this.position, this.getNMS(), blockData, applyPhysics);
+ boolean setTypeAndData(final net.minecraft.world.level.block.state.BlockState blockData, final boolean applyPhysics, boolean checkLight) {
+ return CraftBlock.setTypeAndData(this.world, this.position, this.getNMS(), blockData, applyPhysics, checkLight);
}
- public static boolean setTypeAndData(LevelAccessor world, BlockPos position, net.minecraft.world.level.block.state.BlockState old, net.minecraft.world.level.block.state.BlockState blockData, boolean applyPhysics) {
+ public static boolean setTypeAndData(LevelAccessor world, BlockPos position, net.minecraft.world.level.block.state.BlockState old, net.minecraft.world.level.block.state.BlockState blockData, boolean applyPhysics, boolean checkLight) {
// SPIGOT-611: need to do this to prevent glitchiness. Easier to handle this here (like /setblock) than to fix weirdness in tile entity cleanup
if (old.hasBlockEntity() && blockData.getBlock() != old.getBlock()) { // SPIGOT-3725 remove old tile entity if block changes
// SPIGOT-4612: faster - just clear tile
@@ -204,7 +209,7 @@ public class CraftBlock implements Block {
if (applyPhysics) {
return world.setBlock(position, blockData, 3);
} else {
- boolean success = world.setBlock(position, blockData, 2 | 16 | 1024); // NOTIFY | NO_OBSERVER | NO_PLACE (custom)
+ boolean success = world.setBlock(position, blockData, 2 | 16 | 1024, checkLight); // NOTIFY | NO_OBSERVER | NO_PLACE (custom)
if (success && world instanceof net.minecraft.world.level.Level) {
world.getMinecraftWorld().sendBlockUpdated(
position,
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
index 390e1b7fd2721b99cb3ce268c6bc1bf0a38e08a3..f3c42e65c6c731e1f0f3d36f16c35b7d538604a0 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
@@ -217,7 +217,7 @@ public class CraftBlockState implements BlockState {
}
net.minecraft.world.level.block.state.BlockState newBlock = this.data;
- block.setTypeAndData(newBlock, applyPhysics);
+ block.setTypeAndData(newBlock, applyPhysics, true);
if (access instanceof net.minecraft.world.level.Level) {
this.world.getHandle().sendBlockUpdated(
this.position,
diff --git a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
index 23ee60e8843a6a05e7ae6512248a57ec2a08321b..c5e1afb7d5fa630ed85a739d5aada79297257d72 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
@@ -245,7 +245,7 @@ public class DummyGeneratorAccess implements WorldGenLevel {
}
@Override
- public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) {
+ public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, boolean checkLight) {
return false;
}