2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/level/block/BlockComposter.java
+++ b/net/minecraft/world/level/block/BlockComposter.java
2023-03-14 17:30:00 +01:00
@@ -40,6 +40,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;
2023-03-14 17:30:00 +01:00
@@ -246,7 +252,14 @@
2021-11-21 23:00:00 +01:00
int i = (Integer) iblockdata.getValue(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())) {
2023-03-14 17:30:00 +01:00
- IBlockData iblockdata1 = addItem(entity, iblockdata, 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();
2023-03-14 17:30:00 +01:00
+ IBlockData iblockdata1 = addItem(entity, 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;
+ }
2023-03-14 17:30:00 +01:00
+ iblockdata1 = addItem(entity, iblockdata, worldserver, blockposition, itemstack, rand);
2020-06-30 04:18:39 +02:00
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
itemstack.shrink(1);
2020-08-11 23:00:00 +02:00
return iblockdata1;
2023-03-14 17:30:00 +01:00
@@ -256,6 +269,14 @@
2020-07-05 00:53:26 +02:00
}
2023-03-14 17:30:00 +01:00
public static IBlockData extractProduce(Entity entity, IBlockData iblockdata, World world, BlockPosition blockposition) {
+ // CraftBukkit start
+ if (entity != null && !(entity instanceof EntityHuman)) {
+ IBlockData iblockdata1 = empty(entity, 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) {
2023-03-14 17:30:00 +01:00
Vec3D vec3d = Vec3D.atLowerCornerWithOffset(blockposition, 0.5D, 1.01D, 0.5D).offsetRandom(world.random, 0.7F);
EntityItem entityitem = new EntityItem(world, vec3d.x(), vec3d.y(), vec3d.z(), new ItemStack(Items.BONE_MEAL));
@@ -279,10 +300,16 @@
2020-07-01 01:36:38 +02:00
}
2023-03-14 17:30:00 +01:00
static IBlockData addItem(@Nullable Entity entity, IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition, ItemStack itemstack) {
2020-07-01 01:36:38 +02:00
+ // CraftBukkit start
2023-03-14 17:30:00 +01:00
+ return addItem(entity, iblockdata, generatoraccess, blockposition, itemstack, generatoraccess.getRandom().nextDouble());
2020-07-01 01:36:38 +02:00
+ }
+
2023-03-14 17:30:00 +01:00
+ static IBlockData addItem(@Nullable Entity entity, IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition, ItemStack itemstack, double rand) {
2020-07-01 01:36:38 +02:00
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
int i = (Integer) iblockdata.getValue(BlockComposter.LEVEL);
2021-06-11 07:00:00 +02:00
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;
2023-03-14 17:30:00 +01:00
@@ -331,7 +358,8 @@
2021-11-21 23:00:00 +01:00
public IWorldInventory getContainer(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) {
int i = (Integer) iblockdata.getValue(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 {
2023-03-14 17:30:00 +01:00
@@ -346,6 +374,7 @@
2021-06-11 07:00:00 +02:00
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
2023-03-14 17:30:00 +01:00
@@ -370,8 +399,15 @@
2020-01-09 23:50:39 +01:00
@Override
2021-11-21 23:00:00 +01:00
public void setChanged() {
2023-03-14 17:30:00 +01:00
- BlockComposter.empty((Entity) null, this.state, this.level, this.pos);
2021-06-11 07:00:00 +02:00
- 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()) {
2023-03-14 17:30:00 +01:00
+ BlockComposter.empty((Entity) null, this.state, this.level, this.pos);
2021-06-11 07:00:00 +02:00
+ this.changed = true;
2020-01-09 23:50:39 +01:00
+ } else {
2021-11-21 23:00:00 +01:00
+ this.level.setBlock(this.pos, this.state, 3);
2021-06-11 07:00:00 +02:00
+ this.changed = false;
2020-01-09 23:50:39 +01:00
+ }
+ // CraftBukkit end
}
}
2019-04-23 04:00:00 +02:00
2023-03-14 17:30:00 +01:00
@@ -384,6 +420,7 @@
2021-06-11 07:00:00 +02:00
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;
2023-03-14 17:30:00 +01:00
@@ -426,8 +463,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