Paper/nms-patches/IDispenseBehavior.patch

563 lines
34 KiB
Diff
Raw Normal View History

2019-04-23 04:00:00 +02:00
--- a/net/minecraft/server/IDispenseBehavior.java
+++ b/net/minecraft/server/IDispenseBehavior.java
@@ -3,6 +3,15 @@
2019-04-23 04:00:00 +02:00
import java.util.Iterator;
import java.util.List;
import java.util.Random;
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.TreeType;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
2019-04-23 04:00:00 +02:00
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
+import org.bukkit.event.block.BlockDispenseEvent;
+import org.bukkit.event.world.StructureGrowEvent;
+// CraftBukkit end
public interface IDispenseBehavior {
@@ -44,7 +53,7 @@
2019-04-23 04:00:00 +02:00
BlockDispenser.a((IMaterial) Items.EGG, (IDispenseBehavior) (new DispenseBehaviorProjectile() {
@Override
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) {
- return (IProjectile) SystemUtils.a((Object) (new EntityEgg(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entityegg) -> {
+ return (IProjectile) SystemUtils.a((new EntityEgg(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entityegg) -> { // CraftBukkit - decompile error
entityegg.setItem(itemstack);
});
}
@@ -52,7 +61,7 @@
2019-04-23 04:00:00 +02:00
BlockDispenser.a((IMaterial) Items.SNOWBALL, (IDispenseBehavior) (new DispenseBehaviorProjectile() {
@Override
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) {
- return (IProjectile) SystemUtils.a((Object) (new EntitySnowball(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitysnowball) -> {
+ return (IProjectile) SystemUtils.a((new EntitySnowball(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitysnowball) -> { // CraftBukkit - decompile error
entitysnowball.setItem(itemstack);
});
}
@@ -60,7 +69,7 @@
2019-04-23 04:00:00 +02:00
BlockDispenser.a((IMaterial) Items.EXPERIENCE_BOTTLE, (IDispenseBehavior) (new DispenseBehaviorProjectile() {
@Override
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) {
- return (IProjectile) SystemUtils.a((Object) (new EntityThrownExpBottle(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitythrownexpbottle) -> {
+ return (IProjectile) SystemUtils.a((new EntityThrownExpBottle(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitythrownexpbottle) -> { // CraftBukkit - decompile error
entitythrownexpbottle.setItem(itemstack);
});
}
@@ -81,7 +90,7 @@
2019-04-23 04:00:00 +02:00
return (new DispenseBehaviorProjectile() {
@Override
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack1) {
- return (IProjectile) SystemUtils.a((Object) (new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitypotion) -> {
+ return (IProjectile) SystemUtils.a((new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitypotion) -> { // CraftBukkit - decompile error
entitypotion.setItem(itemstack1);
});
}
@@ -104,7 +113,7 @@
2019-04-23 04:00:00 +02:00
return (new DispenseBehaviorProjectile() {
@Override
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack1) {
- return (IProjectile) SystemUtils.a((Object) (new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitypotion) -> {
+ return (IProjectile) SystemUtils.a((new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitypotion) -> { // CraftBukkit - decompile error
entitypotion.setItem(itemstack1);
});
}
@@ -127,8 +136,36 @@
2019-07-20 01:00:00 +02:00
EnumDirection enumdirection = (EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING);
2020-06-25 02:00:00 +02:00
EntityTypes<?> entitytypes = ((ItemMonsterEgg) itemstack.getItem()).a(itemstack.getTag());
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2020-08-11 23:00:00 +02:00
+ WorldServer worldserver = isourceblock.getWorld();
2019-04-23 04:00:00 +02:00
+ ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
2020-08-11 23:00:00 +02:00
+ org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-04-23 04:00:00 +02:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-04-23 04:00:00 +02:00
+ }
+
+ if (event.isCancelled()) {
+ itemstack.add(1);
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ itemstack.add(1);
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+
entitytypes.spawnCreature(isourceblock.getWorld(), itemstack, (EntityHuman) null, isourceblock.getBlockPosition().shift(enumdirection), EnumMobSpawn.DISPENSER, enumdirection != EnumDirection.UP, false);
- itemstack.subtract(1);
+ // itemstack.subtract(1); // Handled during event processing
+ // CraftBukkit end
return itemstack;
}
};
2019-12-10 23:00:00 +01:00
@@ -146,12 +183,40 @@
EnumDirection enumdirection = (EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING);
BlockPosition blockposition = isourceblock.getBlockPosition().shift(enumdirection);
2020-08-11 23:00:00 +02:00
WorldServer worldserver = isourceblock.getWorld();
2019-12-10 23:00:00 +01:00
+
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
+ ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
2020-08-11 23:00:00 +02:00
+ org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-04-23 04:00:00 +02:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
2019-12-10 23:00:00 +01:00
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
2019-04-23 04:00:00 +02:00
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-04-23 04:00:00 +02:00
+ }
+
+ if (event.isCancelled()) {
+ itemstack.add(1);
+ return itemstack;
+ }
2019-12-10 23:00:00 +01:00
+
+ if (!event.getItem().equals(craftItem)) {
+ itemstack.add(1);
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+ // CraftBukkit end
+
2020-08-11 23:00:00 +02:00
EntityArmorStand entityarmorstand = new EntityArmorStand(worldserver, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D);
2020-08-11 23:00:00 +02:00
EntityTypes.a((World) worldserver, (EntityHuman) null, (Entity) entityarmorstand, itemstack.getTag());
2020-06-25 02:00:00 +02:00
entityarmorstand.yaw = enumdirection.o();
2020-08-11 23:00:00 +02:00
worldserver.addEntity(entityarmorstand);
- itemstack.subtract(1);
2019-12-10 23:00:00 +01:00
+ // itemstack.subtract(1); // CraftBukkit - Handled during event processing
return itemstack;
}
}));
2020-06-25 02:00:00 +02:00
@@ -252,12 +317,41 @@
@Override
public ItemStack a(ISourceBlock isourceblock, ItemStack itemstack) {
EnumDirection enumdirection = (EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING);
2019-12-10 23:00:00 +01:00
+ // CraftBukkit start
2020-08-11 23:00:00 +02:00
+ WorldServer worldserver = isourceblock.getWorld();
2019-12-10 23:00:00 +01:00
+ ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
2020-08-11 23:00:00 +02:00
+ org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-12-10 23:00:00 +01:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
2020-06-25 02:00:00 +02:00
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(enumdirection.getAdjacentX(), enumdirection.getAdjacentY(), enumdirection.getAdjacentZ()));
2019-12-10 23:00:00 +01:00
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-12-10 23:00:00 +01:00
+ }
+
+ if (event.isCancelled()) {
+ itemstack.add(1);
+ return itemstack;
+ }
+
2019-04-23 04:00:00 +02:00
+ if (!event.getItem().equals(craftItem)) {
+ itemstack.add(1);
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+
2019-04-23 04:00:00 +02:00
+ itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
2020-06-25 02:00:00 +02:00
EntityFireworks entityfireworks = new EntityFireworks(isourceblock.getWorld(), itemstack, isourceblock.getX(), isourceblock.getY(), isourceblock.getX(), true);
2019-12-10 23:00:00 +01:00
2020-06-25 02:00:00 +02:00
IDispenseBehavior.a(isourceblock, entityfireworks, enumdirection);
entityfireworks.shoot((double) enumdirection.getAdjacentX(), (double) enumdirection.getAdjacentY(), (double) enumdirection.getAdjacentZ(), 0.5F, 1.0F);
2019-12-10 23:00:00 +01:00
isourceblock.getWorld().addEntity(entityfireworks);
- itemstack.subtract(1);
2019-04-23 04:00:00 +02:00
+ // itemstack.subtract(1); // Handled during event processing
+ // CraftBukkit end
return itemstack;
}
2020-06-25 02:00:00 +02:00
@@ -280,10 +374,39 @@
2019-04-23 04:00:00 +02:00
double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentY();
double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentZ();
2020-08-11 23:00:00 +02:00
- worldserver.addEntity((Entity) SystemUtils.a((Object) (new EntitySmallFireball(worldserver, d0, d1, d2, d3, d4, d5)), (entitysmallfireball) -> {
2020-06-25 02:00:00 +02:00
- entitysmallfireball.setItem(itemstack);
2019-04-23 04:00:00 +02:00
- }));
- itemstack.subtract(1);
+ // CraftBukkit start
+ ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
2020-08-11 23:00:00 +02:00
+ org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-04-23 04:00:00 +02:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(d3, d4, d5));
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-04-23 04:00:00 +02:00
+ }
+
+ if (event.isCancelled()) {
+ itemstack.add(1);
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ itemstack.add(1);
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+
2020-08-11 23:00:00 +02:00
+ EntitySmallFireball entitysmallfireball = new EntitySmallFireball(worldserver, d0, d1, d2, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ());
2020-06-25 02:00:00 +02:00
+ entitysmallfireball.setItem(itemstack1);
2019-04-23 04:00:00 +02:00
+ entitysmallfireball.projectileSource = new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource((TileEntityDispenser) isourceblock.getTileEntity());
+
2020-08-11 23:00:00 +02:00
+ worldserver.addEntity(entitysmallfireball);
2019-04-23 04:00:00 +02:00
+ // itemstack.subtract(1); // Handled during event processing
+ // CraftBukkit end
return itemstack;
}
2020-06-25 02:00:00 +02:00
@@ -307,9 +430,52 @@
2019-07-20 01:00:00 +02:00
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING));
2020-08-11 23:00:00 +02:00
WorldServer worldserver = isourceblock.getWorld();
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
+ int x = blockposition.getX();
+ int y = blockposition.getY();
+ int z = blockposition.getZ();
2020-08-11 23:00:00 +02:00
+ IBlockData iblockdata = worldserver.getType(blockposition);
2019-04-23 04:00:00 +02:00
+ Material material = iblockdata.getMaterial();
2020-08-11 23:00:00 +02:00
+ if (worldserver.isEmpty(blockposition) || !material.isBuildable() || material.isReplaceable() || ((iblockdata.getBlock() instanceof IFluidContainer) && ((IFluidContainer) iblockdata.getBlock()).canPlace(worldserver, blockposition, iblockdata, itembucket.fluidType))) {
+ org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-04-23 04:00:00 +02:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(x, y, z));
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-04-23 04:00:00 +02:00
+ }
+
+ if (event.isCancelled()) {
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+
+ itembucket = (ItemBucket) CraftItemStack.asNMSCopy(event.getItem()).getItem();
+ }
+ // CraftBukkit end
+
2020-08-11 23:00:00 +02:00
if (itembucket.a((EntityHuman) null, (World) worldserver, blockposition, (MovingObjectPositionBlock) null)) {
itembucket.a((World) worldserver, itemstack, blockposition);
2019-04-23 04:00:00 +02:00
- return new ItemStack(Items.BUCKET);
+ // CraftBukkit start - Handle stacked buckets
+ Item item = Items.BUCKET;
+ itemstack.subtract(1);
+ if (itemstack.isEmpty()) {
+ itemstack.setItem(Items.BUCKET);
+ itemstack.setCount(1);
+ } else if (((TileEntityDispenser) isourceblock.getTileEntity()).addItem(new ItemStack(item)) < 0) {
+ this.b.dispense(isourceblock, new ItemStack(item));
+ }
+ // CraftBukkit end
+ return itemstack;
} else {
return this.b.dispense(isourceblock, itemstack);
}
2020-06-25 02:00:00 +02:00
@@ -333,13 +499,39 @@
2019-04-23 04:00:00 +02:00
Block block = iblockdata.getBlock();
if (block instanceof IFluidSource) {
2020-08-11 23:00:00 +02:00
- FluidType fluidtype = ((IFluidSource) block).removeFluid(worldserver, blockposition, iblockdata);
2019-04-23 04:00:00 +02:00
+ FluidType fluidtype = ((IFluidSource) block).removeFluid(DummyGeneratorAccess.INSTANCE, blockposition, iblockdata); // CraftBukkit
if (!(fluidtype instanceof FluidTypeFlowing)) {
return super.a(isourceblock, itemstack);
} else {
2019-12-10 23:00:00 +01:00
Item item = fluidtype.a();
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2020-08-11 23:00:00 +02:00
+ org.bukkit.block.Block bukkitBlock = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-04-23 04:00:00 +02:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-04-23 04:00:00 +02:00
+ }
+
+ if (event.isCancelled()) {
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+
2020-08-11 23:00:00 +02:00
+ fluidtype = ((IFluidSource) block).removeFluid(worldserver, blockposition, iblockdata); // From above
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
+
itemstack.subtract(1);
if (itemstack.isEmpty()) {
return new ItemStack(item);
2020-08-11 23:00:00 +02:00
@@ -361,13 +553,41 @@
2019-04-23 04:00:00 +02:00
protected ItemStack a(ISourceBlock isourceblock, ItemStack itemstack) {
2020-08-11 23:00:00 +02:00
WorldServer worldserver = isourceblock.getWorld();
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2020-08-11 23:00:00 +02:00
+ org.bukkit.block.Block bukkitBlock = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-04-23 04:00:00 +02:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-04-23 04:00:00 +02:00
+ }
+
+ if (event.isCancelled()) {
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+ // CraftBukkit end
+
2020-06-25 02:00:00 +02:00
this.a(true);
2020-08-11 23:00:00 +02:00
EnumDirection enumdirection = (EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING);
BlockPosition blockposition = isourceblock.getBlockPosition().shift(enumdirection);
IBlockData iblockdata = worldserver.getType(blockposition);
2019-04-23 04:00:00 +02:00
2020-08-11 23:00:00 +02:00
if (BlockFireAbstract.a((World) worldserver, blockposition, enumdirection)) {
- worldserver.setTypeUpdate(blockposition, BlockFireAbstract.a((IBlockAccess) worldserver, blockposition));
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start - Ignition by dispensing flint and steel
2020-08-11 23:00:00 +02:00
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(worldserver, blockposition, isourceblock.getBlockPosition()).isCancelled()) {
+ worldserver.setTypeUpdate(blockposition, BlockFireAbstract.a((IBlockAccess) worldserver, blockposition));
2019-04-23 04:00:00 +02:00
+ }
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
} else if (BlockCampfire.h(iblockdata)) {
2020-08-11 23:00:00 +02:00
worldserver.setTypeUpdate(blockposition, (IBlockData) iblockdata.set(BlockProperties.r, true));
2019-04-23 04:00:00 +02:00
} else if (iblockdata.getBlock() instanceof BlockTNT) {
2020-08-11 23:00:00 +02:00
@@ -390,12 +610,57 @@
2020-06-25 02:00:00 +02:00
this.a(true);
2020-08-11 23:00:00 +02:00
WorldServer worldserver = isourceblock.getWorld();
2019-07-20 01:00:00 +02:00
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING));
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2020-08-11 23:00:00 +02:00
+ org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-04-23 04:00:00 +02:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-04-23 04:00:00 +02:00
+ }
+
+ if (event.isCancelled()) {
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+
2020-08-11 23:00:00 +02:00
+ worldserver.captureTreeGeneration = true;
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2020-08-11 23:00:00 +02:00
if (!ItemBoneMeal.a(itemstack, (World) worldserver, blockposition) && !ItemBoneMeal.a(itemstack, (World) worldserver, blockposition, (EnumDirection) null)) {
2020-06-25 02:00:00 +02:00
this.a(false);
2020-08-11 23:00:00 +02:00
} else if (!worldserver.isClientSide) {
worldserver.triggerEffect(2005, blockposition, 0);
2019-04-23 04:00:00 +02:00
}
+ // CraftBukkit start
2020-08-11 23:00:00 +02:00
+ worldserver.captureTreeGeneration = false;
+ if (worldserver.capturedBlockStates.size() > 0) {
2019-04-23 04:00:00 +02:00
+ TreeType treeType = BlockSapling.treeType;
+ BlockSapling.treeType = null;
2020-08-11 23:00:00 +02:00
+ Location location = new Location(worldserver.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ List<org.bukkit.block.BlockState> blocks = new java.util.ArrayList<>(worldserver.capturedBlockStates.values());
+ worldserver.capturedBlockStates.clear();
2019-04-23 04:00:00 +02:00
+ StructureGrowEvent structureEvent = null;
+ if (treeType != null) {
+ structureEvent = new StructureGrowEvent(location, treeType, false, null, blocks);
+ org.bukkit.Bukkit.getPluginManager().callEvent(structureEvent);
+ }
+ if (structureEvent == null || !structureEvent.isCancelled()) {
+ for (org.bukkit.block.BlockState blockstate : blocks) {
+ blockstate.update(true);
+ }
+ }
+ }
+ // CraftBukkit end
return itemstack;
}
2020-08-11 23:00:00 +02:00
@@ -405,11 +670,40 @@
2019-04-23 04:00:00 +02:00
protected ItemStack a(ISourceBlock isourceblock, ItemStack itemstack) {
2020-08-11 23:00:00 +02:00
WorldServer worldserver = isourceblock.getWorld();
2019-07-20 01:00:00 +02:00
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING));
2020-08-11 23:00:00 +02:00
- EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldserver, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, (EntityLiving) null);
2019-04-23 04:00:00 +02:00
+ // EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, (EntityLiving) null);
+
+ // CraftBukkit start
+ ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
2020-08-11 23:00:00 +02:00
+ org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-04-23 04:00:00 +02:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector((double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D));
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-04-23 04:00:00 +02:00
+ }
+
+ if (event.isCancelled()) {
+ itemstack.add(1);
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ itemstack.add(1);
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+
2020-08-11 23:00:00 +02:00
+ EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), (EntityLiving) null);
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2020-08-11 23:00:00 +02:00
worldserver.addEntity(entitytntprimed);
worldserver.playSound((EntityHuman) null, entitytntprimed.locX(), entitytntprimed.locY(), entitytntprimed.locZ(), SoundEffects.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
2019-04-23 04:00:00 +02:00
- itemstack.subtract(1);
+ // itemstack.subtract(1); // CraftBukkit - handled above
return itemstack;
}
}));
2020-08-11 23:00:00 +02:00
@@ -433,6 +727,30 @@
2019-07-20 01:00:00 +02:00
EnumDirection enumdirection = (EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING);
2019-04-23 04:00:00 +02:00
BlockPosition blockposition = isourceblock.getBlockPosition().shift(enumdirection);
+ // CraftBukkit start
2020-08-11 23:00:00 +02:00
+ org.bukkit.block.Block bukkitBlock = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-04-23 04:00:00 +02:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-04-23 04:00:00 +02:00
+ }
+
+ if (event.isCancelled()) {
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+ // CraftBukkit end
+
2020-08-11 23:00:00 +02:00
if (worldserver.isEmpty(blockposition) && BlockWitherSkull.b((World) worldserver, blockposition, itemstack)) {
worldserver.setTypeAndData(blockposition, (IBlockData) Blocks.WITHER_SKELETON_SKULL.getBlockData().set(BlockSkull.a, enumdirection.n() == EnumDirection.EnumAxis.Y ? 0 : enumdirection.opposite().get2DRotationValue() * 4), 3);
TileEntity tileentity = worldserver.getTileEntity(blockposition);
@@ -457,6 +775,30 @@
2019-07-20 01:00:00 +02:00
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING));
2019-04-23 04:00:00 +02:00
BlockPumpkinCarved blockpumpkincarved = (BlockPumpkinCarved) Blocks.CARVED_PUMPKIN;
+ // CraftBukkit start
2020-08-11 23:00:00 +02:00
+ org.bukkit.block.Block bukkitBlock = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-04-23 04:00:00 +02:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-04-23 04:00:00 +02:00
+ }
+
+ if (event.isCancelled()) {
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+ // CraftBukkit end
+
2020-08-11 23:00:00 +02:00
if (worldserver.isEmpty(blockposition) && blockpumpkincarved.a((IWorldReader) worldserver, blockposition)) {
if (!worldserver.isClientSide) {
worldserver.setTypeAndData(blockposition, blockpumpkincarved.getBlockData(), 3);
@@ -504,6 +846,30 @@
2020-06-25 02:00:00 +02:00
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING));
2020-08-11 23:00:00 +02:00
IBlockData iblockdata = worldserver.getType(blockposition);
2019-12-10 23:00:00 +01:00
+ // CraftBukkit start
2020-08-11 23:00:00 +02:00
+ org.bukkit.block.Block bukkitBlock = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-12-10 23:00:00 +01:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-12-10 23:00:00 +01:00
+ }
+
+ if (event.isCancelled()) {
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+ // CraftBukkit end
+
2020-06-25 02:00:00 +02:00
if (iblockdata.a((Tag) TagsBlock.BEEHIVES, (blockbase_blockdata) -> {
return blockbase_blockdata.b(BlockBeehive.b);
}) && (Integer) iblockdata.get(BlockBeehive.b) >= 5) {