2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/level/block/BlockComposter.java
+++ b/net/minecraft/world/level/block/BlockComposter.java
2021-06-11 07:00:00 +02:00
@@ -38,6 +38,12 @@
2021-03-15 23:00:00 +01:00
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import net.minecraft.world.phys.shapes.VoxelShapes;
2021-03-08 22:47:33 +01:00
2020-06-30 04:18:39 +02:00
+// CraftBukkit start
2021-03-15 23:00:00 +01:00
+import net.minecraft.world.entity.Entity;
2020-06-30 04:18:39 +02:00
+import org.bukkit.craftbukkit.inventory.CraftBlockInventoryHolder;
+import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
+// CraftBukkit end
2021-03-08 22:47:33 +01:00
+
2019-04-23 04:00:00 +02:00
public class BlockComposter extends Block implements IInventoryHolder {
2021-06-11 07:00:00 +02:00
public static final int READY = 8;
@@ -47,7 +53,7 @@
public static final Object2FloatMap<IMaterial> COMPOSTABLES = new Object2FloatOpenHashMap();
private static final int AABB_SIDE_THICKNESS = 2;
private static final VoxelShape OUTER_SHAPE = VoxelShapes.b();
- private static final VoxelShape[] SHAPES = (VoxelShape[]) SystemUtils.a((Object) (new VoxelShape[9]), (avoxelshape) -> {
+ private static final VoxelShape[] SHAPES = (VoxelShape[]) SystemUtils.a((new VoxelShape[9]), (avoxelshape) -> { // CraftBukkit - decompile error
2019-04-23 04:00:00 +02:00
for (int i = 0; i < 8; ++i) {
2021-06-11 07:00:00 +02:00
avoxelshape[i] = VoxelShapes.a(BlockComposter.OUTER_SHAPE, Block.a(2.0D, (double) Math.max(2, 1 + i * 2), 2.0D, 14.0D, 16.0D, 14.0D), OperatorBoolean.ONLY_FIRST);
2019-04-23 04:00:00 +02:00
}
2021-06-11 07:00:00 +02:00
@@ -225,18 +231,25 @@
2020-07-05 00:53:26 +02:00
return EnumInteractionResult.a(world.isClientSide);
} else if (i == 8) {
- d(iblockdata, world, blockposition);
+ d(iblockdata, world, blockposition, (Entity) null); // CraftBukkit - no event for players
return EnumInteractionResult.a(world.isClientSide);
} else {
return EnumInteractionResult.PASS;
2020-06-30 04:18:39 +02:00
}
}
- public static IBlockData a(IBlockData iblockdata, WorldServer worldserver, ItemStack itemstack, BlockPosition blockposition) {
2020-07-05 00:53:26 +02:00
+ public static IBlockData a(IBlockData iblockdata, WorldServer worldserver, ItemStack itemstack, BlockPosition blockposition, Entity entity) { // CraftBukkit
2021-06-11 07:00:00 +02:00
int i = (Integer) iblockdata.get(BlockComposter.LEVEL);
2020-06-30 04:18:39 +02:00
2021-06-11 07:00:00 +02:00
if (i < 7 && BlockComposter.COMPOSTABLES.containsKey(itemstack.getItem())) {
- IBlockData iblockdata1 = a(iblockdata, (GeneratorAccess) worldserver, blockposition, itemstack);
2020-06-30 04:18:39 +02:00
+ // CraftBukkit start
2020-07-01 01:36:38 +02:00
+ double rand = worldserver.getRandom().nextDouble();
2021-06-11 07:00:00 +02:00
+ IBlockData iblockdata1 = a(iblockdata, DummyGeneratorAccess.INSTANCE, blockposition, itemstack, rand);
2020-06-30 04:18:39 +02:00
+ if (iblockdata == iblockdata1 || org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1).isCancelled()) {
+ return iblockdata;
+ }
2021-06-11 07:00:00 +02:00
+ iblockdata1 = a(iblockdata, (GeneratorAccess) worldserver, blockposition, itemstack, rand);
2020-06-30 04:18:39 +02:00
+ // CraftBukkit end
itemstack.subtract(1);
2020-08-11 23:00:00 +02:00
return iblockdata1;
2021-06-11 07:00:00 +02:00
@@ -245,7 +258,15 @@
2020-07-05 00:53:26 +02:00
}
}
- public static IBlockData d(IBlockData iblockdata, World world, BlockPosition blockposition) {
+ // CraftBukkit start
+ public static IBlockData d(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (entity != null) {
2021-06-11 07:00:00 +02:00
+ IBlockData iblockdata1 = c(iblockdata, DummyGeneratorAccess.INSTANCE, blockposition);
2020-07-05 00:53:26 +02:00
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1).isCancelled()) {
+ return iblockdata;
+ }
+ }
+ // CraftBukkit end
if (!world.isClientSide) {
float f = 0.7F;
double d0 = (double) (world.random.nextFloat() * 0.7F) + 0.15000000596046448D;
2021-06-11 07:00:00 +02:00
@@ -271,10 +292,16 @@
2020-07-01 01:36:38 +02:00
}
2021-06-11 07:00:00 +02:00
static IBlockData a(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition, ItemStack itemstack) {
2020-07-01 01:36:38 +02:00
+ // CraftBukkit start
2021-06-11 07:00:00 +02:00
+ return a(iblockdata, generatoraccess, blockposition, itemstack, generatoraccess.getRandom().nextDouble());
2020-07-01 01:36:38 +02:00
+ }
+
2021-06-11 07:00:00 +02:00
+ static IBlockData a(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition, ItemStack itemstack, double rand) {
2020-07-01 01:36:38 +02:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
int i = (Integer) iblockdata.get(BlockComposter.LEVEL);
float f = BlockComposter.COMPOSTABLES.getFloat(itemstack.getItem());
2020-07-01 01:36:38 +02:00
- if ((i != 0 || f <= 0.0F) && generatoraccess.getRandom().nextDouble() >= (double) f) {
+ if ((i != 0 || f <= 0.0F) && rand >= (double) f) {
return iblockdata;
} else {
int j = i + 1;
2021-07-06 16:00:00 +02:00
@@ -322,7 +349,8 @@
2019-04-23 04:00:00 +02:00
public IWorldInventory a(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) {
2021-06-11 07:00:00 +02:00
int i = (Integer) iblockdata.get(BlockComposter.LEVEL);
2019-04-23 04:00:00 +02:00
- return (IWorldInventory) (i == 8 ? new BlockComposter.ContainerOutput(iblockdata, generatoraccess, blockposition, new ItemStack(Items.BONE_MEAL)) : (i < 7 ? new BlockComposter.ContainerInput(iblockdata, generatoraccess, blockposition) : new BlockComposter.ContainerEmpty()));
+ // CraftBukkit - empty generatoraccess, blockposition
+ return (IWorldInventory) (i == 8 ? new BlockComposter.ContainerOutput(iblockdata, generatoraccess, blockposition, new ItemStack(Items.BONE_MEAL)) : (i < 7 ? new BlockComposter.ContainerInput(iblockdata, generatoraccess, blockposition) : new BlockComposter.ContainerEmpty(generatoraccess, blockposition)));
}
2021-07-06 16:00:00 +02:00
public static class ContainerOutput extends InventorySubcontainer implements IWorldInventory {
2021-06-11 07:00:00 +02:00
@@ -337,6 +365,7 @@
this.state = iblockdata;
this.level = generatoraccess;
this.pos = blockposition;
2019-04-23 04:00:00 +02:00
+ this.bukkitOwner = new CraftBlockInventoryHolder(generatoraccess, blockposition, this); // CraftBukkit
}
@Override
2021-07-06 16:00:00 +02:00
@@ -361,8 +390,15 @@
2020-01-09 23:50:39 +01:00
@Override
public void update() {
2021-06-11 07:00:00 +02:00
- BlockComposter.c(this.state, this.level, this.pos);
- this.changed = true;
2020-01-09 23:50:39 +01:00
+ // CraftBukkit start - allow putting items back (eg cancelled InventoryMoveItemEvent)
2020-01-21 22:00:00 +01:00
+ if (this.isEmpty()) {
2021-06-11 07:00:00 +02:00
+ BlockComposter.c(this.state, this.level, this.pos);
+ this.changed = true;
2020-01-09 23:50:39 +01:00
+ } else {
2021-06-11 07:00:00 +02:00
+ this.level.setTypeAndData(this.pos, this.state, 3);
+ this.changed = false;
2020-01-09 23:50:39 +01:00
+ }
+ // CraftBukkit end
}
}
2019-04-23 04:00:00 +02:00
2021-06-11 07:00:00 +02:00
@@ -375,6 +411,7 @@
public ContainerInput(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) {
super(1);
+ this.bukkitOwner = new CraftBlockInventoryHolder(generatoraccess, blockposition, this); // CraftBukkit
this.state = iblockdata;
this.level = generatoraccess;
this.pos = blockposition;
2021-07-06 16:00:00 +02:00
@@ -417,8 +454,9 @@
2021-06-11 07:00:00 +02:00
2021-07-06 16:00:00 +02:00
public static class ContainerEmpty extends InventorySubcontainer implements IWorldInventory {
2019-04-23 04:00:00 +02:00
- public ContainerEmpty() {
+ public ContainerEmpty(GeneratorAccess generatoraccess, BlockPosition blockposition) { // CraftBukkit
super(0);
+ this.bukkitOwner = new CraftBlockInventoryHolder(generatoraccess, blockposition, this); // CraftBukkit
}
@Override