3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00
Paper/nms-patches/BlockComposter.patch

139 Zeilen
7.1 KiB
Diff

2019-04-23 04:00:00 +02:00
--- a/net/minecraft/server/BlockComposter.java
+++ b/net/minecraft/server/BlockComposter.java
@@ -4,13 +4,17 @@
2019-04-23 04:00:00 +02:00
import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap;
import java.util.Random;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftBlockInventoryHolder;
+import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
+// CraftBukkit end
2019-04-23 04:00:00 +02:00
public class BlockComposter extends Block implements IInventoryHolder {
2020-06-25 02:00:00 +02:00
public static final BlockStateInteger a = BlockProperties.as;
2019-04-23 04:00:00 +02:00
public static final Object2FloatMap<IMaterial> b = new Object2FloatOpenHashMap();
2020-06-25 02:00:00 +02:00
private static final VoxelShape c = VoxelShapes.b();
2019-04-23 04:00:00 +02:00
- private static final VoxelShape[] d = (VoxelShape[]) SystemUtils.a((Object) (new VoxelShape[9]), (avoxelshape) -> {
+ private static final VoxelShape[] d = (VoxelShape[]) SystemUtils.a((new VoxelShape[9]), (avoxelshape) -> { // CraftBukkit - decompile error
for (int i = 0; i < 8; ++i) {
avoxelshape[i] = VoxelShapes.a(BlockComposter.c, Block.a(2.0D, (double) Math.max(2, 1 + i * 2), 2.0D, 14.0D, 16.0D, 14.0D), OperatorBoolean.ONLY_FIRST);
}
@@ -156,18 +160,25 @@
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;
}
}
- public static IBlockData a(IBlockData iblockdata, WorldServer worldserver, ItemStack itemstack, BlockPosition blockposition) {
+ public static IBlockData a(IBlockData iblockdata, WorldServer worldserver, ItemStack itemstack, BlockPosition blockposition, Entity entity) { // CraftBukkit
int i = (Integer) iblockdata.get(BlockComposter.a);
if (i < 7 && BlockComposter.b.containsKey(itemstack.getItem())) {
- IBlockData iblockdata1 = b(iblockdata, (GeneratorAccess) worldserver, blockposition, itemstack);
+ // CraftBukkit start
2020-07-01 01:36:38 +02:00
+ double rand = worldserver.getRandom().nextDouble();
+ IBlockData iblockdata1 = b(iblockdata, DummyGeneratorAccess.INSTANCE, blockposition, itemstack, rand);
+ if (iblockdata == iblockdata1 || org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1).isCancelled()) {
+ return iblockdata;
+ }
2020-07-01 01:36:38 +02:00
+ iblockdata1 = b(iblockdata, (GeneratorAccess) worldserver, blockposition, itemstack, rand);
+ // CraftBukkit end
itemstack.subtract(1);
worldserver.triggerEffect(1500, blockposition, iblockdata != iblockdata1 ? 1 : 0);
@@ -177,7 +188,15 @@
}
}
- 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) {
+ IBlockData iblockdata1 = d(iblockdata, DummyGeneratorAccess.INSTANCE, blockposition);
+ 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;
@@ -203,10 +222,16 @@
2020-07-01 01:36:38 +02:00
}
private static IBlockData b(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition, ItemStack itemstack) {
+ // CraftBukkit start
+ return b(iblockdata, generatoraccess, blockposition, itemstack, generatoraccess.getRandom().nextDouble());
+ }
+
+ private static IBlockData b(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition, ItemStack itemstack, double rand) {
+ // CraftBukkit end
int i = (Integer) iblockdata.get(BlockComposter.a);
float f = BlockComposter.b.getFloat(itemstack.getItem());
- 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;
@@ -254,7 +279,8 @@
2019-04-23 04:00:00 +02:00
public IWorldInventory a(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) {
int i = (Integer) iblockdata.get(BlockComposter.a);
- 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)));
}
static class ContainerInput extends InventorySubcontainer implements IWorldInventory {
@@ -266,6 +292,7 @@
2019-04-23 04:00:00 +02:00
public ContainerInput(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) {
super(1);
+ this.bukkitOwner = new CraftBlockInventoryHolder(generatoraccess, blockposition, this); // CraftBukkit
this.a = iblockdata;
this.b = generatoraccess;
this.c = blockposition;
@@ -318,6 +345,7 @@
2020-01-21 22:00:00 +01:00
this.blockData = iblockdata;
this.generatorAccess = generatoraccess;
this.blockPosition = blockposition;
2019-04-23 04:00:00 +02:00
+ this.bukkitOwner = new CraftBlockInventoryHolder(generatoraccess, blockposition, this); // CraftBukkit
}
@Override
@@ -342,15 +370,23 @@
@Override
public void update() {
2020-01-21 22:00:00 +01:00
- BlockComposter.d(this.blockData, this.generatorAccess, this.blockPosition);
- this.emptied = true;
+ // CraftBukkit start - allow putting items back (eg cancelled InventoryMoveItemEvent)
2020-01-21 22:00:00 +01:00
+ if (this.isEmpty()) {
+ BlockComposter.d(this.blockData, this.generatorAccess, this.blockPosition);
+ this.emptied = true;
+ } else {
2020-01-21 22:00:00 +01:00
+ this.generatorAccess.setTypeAndData(this.blockPosition, this.blockData, 3);
+ this.emptied = false;
+ }
+ // CraftBukkit end
}
}
2019-04-23 04:00:00 +02:00
static class ContainerEmpty extends InventorySubcontainer implements IWorldInventory {
- public ContainerEmpty() {
+ public ContainerEmpty(GeneratorAccess generatoraccess, BlockPosition blockposition) { // CraftBukkit
super(0);
+ this.bukkitOwner = new CraftBlockInventoryHolder(generatoraccess, blockposition, this); // CraftBukkit
}
@Override