#877: Improve and simplify CraftBlockState

By: blablubbabc <lukas@wirsindwir.de>
This commit is contained in:
CraftBukkit/Spigot
2021-09-29 18:56:16 +10:00
parent 65625f410c
commit f27c8f74f8
47 changed files with 591 additions and 977 deletions

View File

@@ -21,7 +21,7 @@
+ // CraftBukkit start - special case for handling block placement with water lilies and snow buckets
+ org.bukkit.block.BlockState blockstate = null;
+ if (this instanceof ItemWaterLily || this instanceof SolidBucketItem) {
+ blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(blockactioncontext1.getWorld(), blockactioncontext1.getClickPosition());
+ blockstate = org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockactioncontext1.getWorld(), blockactioncontext1.getClickPosition());
+ }
+ // CraftBukkit end

View File

@@ -1,18 +1,19 @@
--- a/net/minecraft/world/level/block/BlockConcretePowder.java
+++ b/net/minecraft/world/level/block/BlockConcretePowder.java
@@ -13,6 +13,11 @@
@@ -13,6 +13,12 @@
import net.minecraft.world.level.block.state.BlockBase;
import net.minecraft.world.level.block.state.IBlockData;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.craftbukkit.block.CraftBlockStates;
+import org.bukkit.event.block.BlockFormEvent;
+// CraftBukkit end
+
public class BlockConcretePowder extends BlockFalling {
private final IBlockData concrete;
@@ -25,7 +30,7 @@
@@ -25,7 +31,7 @@
@Override
public void a(World world, BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1, EntityFallingBlock entityfallingblock) {
if (canHarden(world, blockposition, iblockdata1)) {
@@ -21,7 +22,7 @@
}
}
@@ -36,7 +41,24 @@
@@ -36,7 +42,24 @@
BlockPosition blockposition = blockactioncontext.getClickPosition();
IBlockData iblockdata = world.getType(blockposition);
@@ -32,7 +33,7 @@
+ }
+
+ // TODO: An event factory call for methods like this
+ CraftBlockState blockState = CraftBlockState.getBlockState(world, blockposition);
+ CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockposition);
+ blockState.setData(this.concrete);
+
+ BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState);
@@ -47,7 +48,7 @@
}
private static boolean canHarden(IBlockAccess iblockaccess, BlockPosition blockposition, IBlockData iblockdata) {
@@ -72,7 +94,25 @@
@@ -72,7 +95,25 @@
@Override
public IBlockData updateState(IBlockData iblockdata, EnumDirection enumdirection, IBlockData iblockdata1, GeneratorAccess generatoraccess, BlockPosition blockposition, BlockPosition blockposition1) {
@@ -58,7 +59,7 @@
+ if (!(generatoraccess instanceof World)) {
+ return this.concrete;
+ }
+ CraftBlockState blockState = CraftBlockState.getBlockState(generatoraccess, blockposition);
+ CraftBlockState blockState = CraftBlockStates.getBlockState(generatoraccess, blockposition);
+ blockState.setData(this.concrete);
+
+ BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState);

View File

@@ -1,11 +1,12 @@
--- a/net/minecraft/world/level/block/BlockFire.java
+++ b/net/minecraft/world/level/block/BlockFire.java
@@ -28,6 +28,13 @@
@@ -28,6 +28,14 @@
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import net.minecraft.world.phys.shapes.VoxelShapes;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.craftbukkit.block.CraftBlockStates;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.block.BlockBurnEvent;
+import org.bukkit.event.block.BlockFadeEvent;
@@ -14,7 +15,7 @@
public class BlockFire extends BlockFireAbstract {
public static final int MAX_AGE = 15;
@@ -93,7 +100,24 @@
@@ -93,7 +101,24 @@
@Override
public IBlockData updateState(IBlockData iblockdata, EnumDirection enumdirection, IBlockData iblockdata1, GeneratorAccess generatoraccess, BlockPosition blockposition, BlockPosition blockposition1) {
@@ -25,7 +26,7 @@
+ if (!(generatoraccess instanceof World)) {
+ return Blocks.AIR.getBlockData();
+ }
+ CraftBlockState blockState = CraftBlockState.getBlockState(generatoraccess, blockposition);
+ CraftBlockState blockState = CraftBlockStates.getBlockState(generatoraccess, blockposition);
+ blockState.setData(Blocks.AIR.getBlockData());
+
+ BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState);
@@ -40,7 +41,7 @@
}
@Override
@@ -142,7 +166,7 @@
@@ -142,7 +167,7 @@
worldserver.getBlockTickList().a(blockposition, this, a(worldserver.random));
if (worldserver.getGameRules().getBoolean(GameRules.RULE_DOFIRETICK)) {
if (!iblockdata.canPlace(worldserver, blockposition)) {
@@ -49,7 +50,7 @@
}
IBlockData iblockdata1 = worldserver.getType(blockposition.down());
@@ -150,7 +174,7 @@
@@ -150,7 +175,7 @@
int i = (Integer) iblockdata.get(BlockFire.AGE);
if (!flag && worldserver.isRaining() && this.a((World) worldserver, blockposition) && random.nextFloat() < 0.2F + (float) i * 0.03F) {
@@ -58,7 +59,7 @@
} else {
int j = Math.min(15, i + random.nextInt(3) / 2);
@@ -164,14 +188,14 @@
@@ -164,14 +189,14 @@
BlockPosition blockposition1 = blockposition.down();
if (!worldserver.getType(blockposition1).d(worldserver, blockposition1, EnumDirection.UP) || i > 3) {
@@ -75,7 +76,7 @@
return;
}
}
@@ -179,12 +203,14 @@
@@ -179,12 +204,14 @@
boolean flag1 = worldserver.u(blockposition);
int k = flag1 ? -50 : 0;
@@ -96,7 +97,7 @@
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
for (int l = -1; l <= 1; ++l) {
@@ -210,7 +236,15 @@
@@ -210,7 +237,15 @@
if (i2 > 0 && random.nextInt(k1) <= i2 && (!worldserver.isRaining() || !this.a((World) worldserver, (BlockPosition) blockposition_mutableblockposition))) {
int j2 = Math.min(15, i + random.nextInt(5) / 4);
@@ -113,7 +114,7 @@
}
}
}
@@ -234,12 +268,24 @@
@@ -234,12 +269,24 @@
return iblockdata.b(BlockProperties.WATERLOGGED) && (Boolean) iblockdata.get(BlockProperties.WATERLOGGED) ? 0 : this.flameOdds.getInt(iblockdata.getBlock());
}

View File

@@ -1,18 +1,19 @@
--- a/net/minecraft/world/level/block/LayeredCauldronBlock.java
+++ b/net/minecraft/world/level/block/LayeredCauldronBlock.java
@@ -17,6 +17,11 @@
@@ -17,6 +17,12 @@
import net.minecraft.world.level.material.FluidType;
import net.minecraft.world.level.material.FluidTypes;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.craftbukkit.block.CraftBlockStates;
+import org.bukkit.event.block.CauldronLevelChangeEvent;
+// CraftBukkit end
+
public class LayeredCauldronBlock extends AbstractCauldronBlock {
public static final int MIN_FILL_LEVEL = 1;
@@ -56,10 +61,14 @@
@@ -56,10 +62,14 @@
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
if (!world.isClientSide && entity.isBurning() && this.a(iblockdata, blockposition, entity)) {
@@ -29,7 +30,7 @@
}
}
@@ -69,15 +78,38 @@
@@ -69,15 +79,38 @@
}
public static void e(IBlockData iblockdata, World world, BlockPosition blockposition) {
@@ -46,7 +47,7 @@
+ // CraftBukkit start
+ public static boolean changeLevel(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData newBlock, Entity entity, CauldronLevelChangeEvent.ChangeReason reason) {
+ CraftBlockState newState = CraftBlockState.getBlockState(world, blockposition);
+ CraftBlockState newState = CraftBlockStates.getBlockState(world, blockposition);
+ newState.setData(newBlock);
+
+ CauldronLevelChangeEvent event = new CauldronLevelChangeEvent(
@@ -70,7 +71,7 @@
}
}
@@ -94,7 +126,11 @@
@@ -94,7 +127,11 @@
@Override
protected void a(IBlockData iblockdata, World world, BlockPosition blockposition, FluidType fluidtype) {
if (!this.c(iblockdata)) {