Paper/nms-patches/DispenserRegistry.patch

570 lines
33 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/DispenserRegistry.java
+++ b/net/minecraft/server/DispenserRegistry.java
2018-12-25 22:00:00 +01:00
@@ -7,6 +7,16 @@
2015-02-26 23:41:06 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import java.util.List;
+import org.bukkit.Location;
+import org.bukkit.TreeType;
2015-02-26 23:41:06 +01:00
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
2015-02-26 23:41:06 +01:00
+import org.bukkit.event.block.BlockDispenseEvent;
+import org.bukkit.event.world.StructureGrowEvent;
2015-02-26 23:41:06 +01:00
+// CraftBukkit end
+
public class DispenserRegistry {
2016-02-29 22:32:46 +01:00
public static final PrintStream a = System.out;
2018-12-25 22:00:00 +01:00
@@ -105,11 +115,39 @@
2018-07-15 02:00:00 +02:00
EnumDirection enumdirection = (EnumDirection) isourceblock.e().get(BlockDispenser.FACING);
2018-12-25 22:00:00 +01:00
EntityTypes<?> entitytypes = ((ItemMonsterEgg) itemstack.getItem()).b(itemstack.getTag());
2018-07-15 02:00:00 +02:00
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
2015-07-30 08:56:52 +02:00
+ World world = isourceblock.getWorld();
+ ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
2015-02-26 23:41:06 +01:00
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
2018-07-15 02:00:00 +02:00
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
2015-02-26 23:41:06 +01:00
+ if (!BlockDispenser.eventFired) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ if (event.isCancelled()) {
2016-11-17 02:41:03 +01:00
+ itemstack.add(1);
2015-02-26 23:41:06 +01:00
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
2016-11-17 02:41:03 +01:00
+ itemstack.add(1);
2015-02-26 23:41:06 +01:00
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
2015-07-30 08:56:52 +02:00
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
2018-07-15 02:00:00 +02:00
+ idispensebehavior.dispense(isourceblock, eventStack);
2015-02-26 23:41:06 +01:00
+ return itemstack;
+ }
+ }
+
2018-07-15 02:00:00 +02:00
if (entitytypes != null) {
entitytypes.a(isourceblock.getWorld(), itemstack, (EntityHuman) null, isourceblock.getBlockPosition().shift(enumdirection), enumdirection != EnumDirection.UP, false);
2015-02-26 23:41:06 +01:00
}
2016-11-17 02:41:03 +01:00
- itemstack.subtract(1);
2018-07-15 02:00:00 +02:00
+ // itemstack.subtract(1); // Handled during event processing
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
return itemstack;
}
2018-07-15 02:00:00 +02:00
};
2018-12-25 22:00:00 +01:00
@@ -127,10 +165,39 @@
2015-02-26 23:41:06 +01:00
double d0 = isourceblock.getX() + (double) enumdirection.getAdjacentX();
double d1 = (double) ((float) isourceblock.getBlockPosition().getY() + 0.2F);
double d2 = isourceblock.getZ() + (double) enumdirection.getAdjacentZ();
2015-07-30 08:56:52 +02:00
- EntityFireworks entityfireworks = new EntityFireworks(isourceblock.getWorld(), d0, d1, d2, itemstack);
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
2015-07-30 08:56:52 +02:00
+ World world = isourceblock.getWorld();
+ ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
2015-02-26 23:41:06 +01:00
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(d0, d1, d2));
+ if (!BlockDispenser.eventFired) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ if (event.isCancelled()) {
2016-11-17 02:41:03 +01:00
+ itemstack.add(1);
2015-02-26 23:41:06 +01:00
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
2016-11-17 02:41:03 +01:00
+ itemstack.add(1);
2015-02-26 23:41:06 +01:00
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
2015-07-30 08:56:52 +02:00
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
2018-07-15 02:00:00 +02:00
+ idispensebehavior.dispense(isourceblock, eventStack);
2015-02-26 23:41:06 +01:00
+ return itemstack;
+ }
+ }
+
+ itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
2015-07-30 08:56:52 +02:00
+ EntityFireworks entityfireworks = new EntityFireworks(isourceblock.getWorld(), event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), itemstack1);
2015-02-26 23:41:06 +01:00
2015-07-30 08:56:52 +02:00
isourceblock.getWorld().addEntity(entityfireworks);
2016-11-17 02:41:03 +01:00
- itemstack.subtract(1);
+ // itemstack.subtract(1); // Handled during event processing
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
return itemstack;
}
2018-12-25 22:00:00 +01:00
@@ -151,8 +218,38 @@
2015-02-26 23:41:06 +01:00
double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentY();
double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentZ();
- world.addEntity(new EntitySmallFireball(world, d0, d1, d2, d3, d4, d5));
2016-11-17 02:41:03 +01:00
- itemstack.subtract(1);
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
2015-07-30 08:56:52 +02:00
+ ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
2015-02-26 23:41:06 +01:00
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(d3, d4, d5));
+ if (!BlockDispenser.eventFired) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ if (event.isCancelled()) {
2016-11-17 02:41:03 +01:00
+ itemstack.add(1);
2015-02-26 23:41:06 +01:00
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
2016-11-17 02:41:03 +01:00
+ itemstack.add(1);
2015-02-26 23:41:06 +01:00
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
2015-07-30 08:56:52 +02:00
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
2018-07-15 02:00:00 +02:00
+ idispensebehavior.dispense(isourceblock, eventStack);
2015-02-26 23:41:06 +01:00
+ return itemstack;
+ }
+ }
+
2016-02-29 22:32:46 +01:00
+ EntitySmallFireball fireball = new EntitySmallFireball(world, d0, d1, d2, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ());
+ fireball.projectileSource = new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource((TileEntityDispenser) isourceblock.getTileEntity());
2015-02-26 23:41:06 +01:00
+
2016-02-29 22:32:46 +01:00
+ world.addEntity(fireball);
2016-11-17 02:41:03 +01:00
+ // itemstack.subtract(1); // Handled during event processing
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
return itemstack;
}
2018-12-25 22:00:00 +01:00
@@ -174,9 +271,52 @@
2016-06-09 03:43:49 +02:00
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
2018-07-15 02:00:00 +02:00
World world = isourceblock.getWorld();
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
+ int x = blockposition.getX();
+ int y = blockposition.getY();
+ int z = blockposition.getZ();
+ IBlockData iblockdata = world.getType(blockposition);
+ Material material = iblockdata.getMaterial();
2018-08-26 04:00:00 +02:00
+ if (world.isEmpty(blockposition) || !material.isBuildable() || material.isReplaceable() || ((iblockdata.getBlock() instanceof IFluidContainer) && ((IFluidContainer) iblockdata.getBlock()).canPlace(world, blockposition, iblockdata, itembucket.fluidType))) {
2015-02-26 23:41:06 +01:00
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(x, y, z));
+ if (!BlockDispenser.eventFired) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ if (event.isCancelled()) {
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
2015-07-30 08:56:52 +02:00
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
2018-07-15 02:00:00 +02:00
+ idispensebehavior.dispense(isourceblock, eventStack);
2015-02-26 23:41:06 +01:00
+ return itemstack;
+ }
+ }
+
+ itembucket = (ItemBucket) CraftItemStack.asNMSCopy(event.getItem()).getItem();
+ }
2016-02-29 22:32:46 +01:00
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2018-07-15 02:00:00 +02:00
if (itembucket.a((EntityHuman) null, world, blockposition, (MovingObjectPosition) null)) {
itembucket.a(world, itemstack, blockposition);
2018-07-15 02:00:00 +02:00
- return new ItemStack(Items.BUCKET);
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - Handle stacked buckets
+ Item item = Items.BUCKET;
2016-11-17 02:41:03 +01:00
+ itemstack.subtract(1);
+ if (itemstack.isEmpty()) {
2015-02-26 23:41:06 +01:00
+ itemstack.setItem(Items.BUCKET);
2016-11-17 02:41:03 +01:00
+ itemstack.setCount(1);
2015-02-26 23:41:06 +01:00
+ } else if (((TileEntityDispenser) isourceblock.getTileEntity()).addItem(new ItemStack(item)) < 0) {
2018-07-15 02:00:00 +02:00
+ this.a.dispense(isourceblock, new ItemStack(item));
2015-02-26 23:41:06 +01:00
+ }
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
+ return itemstack;
2018-07-15 02:00:00 +02:00
} else {
return this.a.dispense(isourceblock, itemstack);
2015-02-26 23:41:06 +01:00
}
2018-12-25 22:00:00 +01:00
@@ -199,13 +339,39 @@
Block block = iblockdata.getBlock();
if (block instanceof IFluidSource) {
2018-12-25 22:00:00 +01:00
- FluidType fluidtype = ((IFluidSource) block).removeFluid(world, blockposition, iblockdata);
+ FluidType fluidtype = ((IFluidSource) block).removeFluid(DummyGeneratorAccess.INSTANCE, blockposition, iblockdata); // CraftBukkit
if (!(fluidtype instanceof FluidTypeFlowing)) {
return super.a(isourceblock, itemstack);
2018-07-15 02:00:00 +02:00
} else {
Item item = fluidtype.b();
+ // CraftBukkit start
+ org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ 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) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ 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;
+ }
+ }
+
2018-12-25 22:00:00 +01:00
+ fluidtype = ((IFluidSource) block).removeFluid(world, blockposition, iblockdata); // From above
2018-07-15 02:00:00 +02:00
+ // CraftBukkit end
+
itemstack.subtract(1);
if (itemstack.isEmpty()) {
return new ItemStack(item);
2018-12-25 22:00:00 +01:00
@@ -226,11 +392,39 @@
2018-07-15 02:00:00 +02:00
protected ItemStack a(ISourceBlock isourceblock, ItemStack itemstack) {
World world = isourceblock.getWorld();
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
+ org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
2018-07-15 02:00:00 +02:00
+ BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
2015-02-26 23:41:06 +01:00
+ if (!BlockDispenser.eventFired) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ if (event.isCancelled()) {
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
2015-07-30 08:56:52 +02:00
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
2018-07-15 02:00:00 +02:00
+ idispensebehavior.dispense(isourceblock, eventStack);
2015-02-26 23:41:06 +01:00
+ return itemstack;
+ }
+ }
+ // CraftBukkit end
+
2018-07-15 02:00:00 +02:00
this.a = true;
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
2015-02-26 23:41:06 +01:00
2018-07-15 02:00:00 +02:00
if (ItemFlintAndSteel.a((GeneratorAccess) world, blockposition)) {
- world.setTypeUpdate(blockposition, Blocks.FIRE.getBlockData());
+ // CraftBukkit start - Ignition by dispensing flint and steel
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition, isourceblock.getBlockPosition()).isCancelled()) {
+ world.setTypeUpdate(blockposition, Blocks.FIRE.getBlockData());
2018-07-22 04:00:00 +02:00
+ }
2018-07-15 02:00:00 +02:00
+ // CraftBukkit end
} else {
Block block = world.getType(blockposition).getBlock();
2018-12-25 22:00:00 +01:00
@@ -254,12 +448,57 @@
2018-07-15 02:00:00 +02:00
this.a = true;
World world = isourceblock.getWorld();
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
+ if (!BlockDispenser.eventFired) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ if (event.isCancelled()) {
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
2015-07-30 08:56:52 +02:00
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
2018-07-15 02:00:00 +02:00
+ idispensebehavior.dispense(isourceblock, eventStack);
2015-02-26 23:41:06 +01:00
+ return itemstack;
+ }
+ }
+
+ world.captureTreeGeneration = true;
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
2018-08-26 04:00:00 +02:00
if (!ItemBoneMeal.a(itemstack, world, blockposition) && !ItemBoneMeal.a(itemstack, world, blockposition, (EnumDirection) null)) {
2018-07-15 02:00:00 +02:00
this.a = false;
} else if (!world.isClientSide) {
world.triggerEffect(2005, blockposition, 0);
}
+ // CraftBukkit start
+ world.captureTreeGeneration = false;
+ if (world.capturedBlockStates.size() > 0) {
+ TreeType treeType = BlockSapling.treeType;
+ BlockSapling.treeType = null;
+ Location location = new Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ List<org.bukkit.block.BlockState> blocks = (List<org.bukkit.block.BlockState>) world.capturedBlockStates.clone();
+ world.capturedBlockStates.clear();
+ StructureGrowEvent structureEvent = null;
+ if (treeType != null) {
+ structureEvent = new StructureGrowEvent(location, treeType, false, null, blocks);
+ org.bukkit.Bukkit.getPluginManager().callEvent(structureEvent);
2015-02-26 23:41:06 +01:00
+ }
2018-07-15 02:00:00 +02:00
+ if (structureEvent == null || !structureEvent.isCancelled()) {
+ for (org.bukkit.block.BlockState blockstate : blocks) {
+ blockstate.update(true);
2015-02-26 23:41:06 +01:00
+ }
+ }
2018-07-15 02:00:00 +02:00
+ }
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
return itemstack;
}
2018-12-25 22:00:00 +01:00
@@ -268,11 +507,40 @@
2018-07-15 02:00:00 +02:00
protected ItemStack a(ISourceBlock isourceblock, ItemStack itemstack) {
2015-07-30 08:56:52 +02:00
World world = isourceblock.getWorld();
2016-06-09 03:43:49 +02:00
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
2015-02-26 23:41:06 +01:00
- EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, (EntityLiving) null);
+ // EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, (EntityLiving) null);
+
+ // CraftBukkit start
2015-07-30 08:56:52 +02:00
+ ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
2015-02-26 23:41:06 +01:00
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
2016-02-29 22:32:46 +01:00
+ 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));
2015-02-26 23:41:06 +01:00
+ if (!BlockDispenser.eventFired) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ if (event.isCancelled()) {
2016-11-17 02:41:03 +01:00
+ itemstack.add(1);
2015-02-26 23:41:06 +01:00
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
2016-11-17 02:41:03 +01:00
+ itemstack.add(1);
2015-02-26 23:41:06 +01:00
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
2015-07-30 08:56:52 +02:00
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
2018-07-15 02:00:00 +02:00
+ idispensebehavior.dispense(isourceblock, eventStack);
2015-02-26 23:41:06 +01:00
+ return itemstack;
+ }
+ }
+
+ EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), (EntityLiving) null);
+ // CraftBukkit end
world.addEntity(entitytntprimed);
2018-07-15 02:00:00 +02:00
world.a((EntityHuman) null, entitytntprimed.locX, entitytntprimed.locY, entitytntprimed.locZ, SoundEffects.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
2016-11-17 02:41:03 +01:00
- itemstack.subtract(1);
+ // itemstack.subtract(1); // CraftBukkit - handled above
2015-02-26 23:41:06 +01:00
return itemstack;
}
2018-07-15 02:00:00 +02:00
}));
2018-12-25 22:00:00 +01:00
@@ -294,6 +562,30 @@
2018-07-15 02:00:00 +02:00
EnumDirection enumdirection = (EnumDirection) isourceblock.e().get(BlockDispenser.FACING);
BlockPosition blockposition = isourceblock.getBlockPosition().shift(enumdirection);
+ // CraftBukkit start
+ org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ 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) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ 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) {
2018-07-15 02:00:00 +02:00
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+ // CraftBukkit end
+
2018-07-15 02:00:00 +02:00
this.a = true;
if (world.isEmpty(blockposition) && BlockWitherSkull.b(world, blockposition, itemstack)) {
2018-12-06 00:00:00 +01:00
world.setTypeAndData(blockposition, (IBlockData) Blocks.WITHER_SKELETON_SKULL.getBlockData().set(BlockSkull.a, enumdirection.k() == EnumDirection.EnumAxis.Y ? 0 : enumdirection.opposite().get2DRotationValue() * 4), 3);
2018-12-25 22:00:00 +01:00
@@ -317,6 +609,30 @@
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
2018-07-15 02:00:00 +02:00
BlockPumpkinCarved blockpumpkincarved = (BlockPumpkinCarved) Blocks.CARVED_PUMPKIN;
+ // CraftBukkit start
+ org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ 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) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ 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) {
2018-07-15 02:00:00 +02:00
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+ // CraftBukkit end
+
2018-07-15 02:00:00 +02:00
this.a = true;
if (world.isEmpty(blockposition) && blockpumpkincarved.a((IWorldReader) world, blockposition)) {
if (!world.isClientSide) {
2018-12-25 22:00:00 +01:00
@@ -384,6 +700,51 @@
2018-07-15 02:00:00 +02:00
}
2018-07-15 02:00:00 +02:00
d();
+ // CraftBukkit start - easier than fixing the decompile
+ DataConverterFlattenData.a(1440, "{Name:\'minecraft:portal\',Properties:{axis:\'x\'}}", new String[]{"{Name:\'minecraft:portal\',Properties:{axis:\'x\'}}"});
+
+ DataConverterMaterialId.ID_MAPPING.put(409, "minecraft:prismarine_shard");
+ DataConverterMaterialId.ID_MAPPING.put(410, "minecraft:prismarine_crystals");
+ DataConverterMaterialId.ID_MAPPING.put(411, "minecraft:rabbit");
+ DataConverterMaterialId.ID_MAPPING.put(412, "minecraft:cooked_rabbit");
+ DataConverterMaterialId.ID_MAPPING.put(413, "minecraft:rabbit_stew");
+ DataConverterMaterialId.ID_MAPPING.put(414, "minecraft:rabbit_foot");
+ DataConverterMaterialId.ID_MAPPING.put(415, "minecraft:rabbit_hide");
+ DataConverterMaterialId.ID_MAPPING.put(416, "minecraft:armor_stand");
+
+ DataConverterMaterialId.ID_MAPPING.put(423, "minecraft:mutton");
+ DataConverterMaterialId.ID_MAPPING.put(424, "minecraft:cooked_mutton");
+ DataConverterMaterialId.ID_MAPPING.put(425, "minecraft:banner");
+ DataConverterMaterialId.ID_MAPPING.put(426, "minecraft:end_crystal");
+ DataConverterMaterialId.ID_MAPPING.put(427, "minecraft:spruce_door");
+ DataConverterMaterialId.ID_MAPPING.put(428, "minecraft:birch_door");
+ DataConverterMaterialId.ID_MAPPING.put(429, "minecraft:jungle_door");
+ DataConverterMaterialId.ID_MAPPING.put(430, "minecraft:acacia_door");
+ DataConverterMaterialId.ID_MAPPING.put(431, "minecraft:dark_oak_door");
+ DataConverterMaterialId.ID_MAPPING.put(432, "minecraft:chorus_fruit");
+ DataConverterMaterialId.ID_MAPPING.put(433, "minecraft:chorus_fruit_popped");
+ DataConverterMaterialId.ID_MAPPING.put(434, "minecraft:beetroot");
+ DataConverterMaterialId.ID_MAPPING.put(435, "minecraft:beetroot_seeds");
+ DataConverterMaterialId.ID_MAPPING.put(436, "minecraft:beetroot_soup");
+ DataConverterMaterialId.ID_MAPPING.put(437, "minecraft:dragon_breath");
+ DataConverterMaterialId.ID_MAPPING.put(438, "minecraft:splash_potion");
+ DataConverterMaterialId.ID_MAPPING.put(439, "minecraft:spectral_arrow");
+ DataConverterMaterialId.ID_MAPPING.put(440, "minecraft:tipped_arrow");
+ DataConverterMaterialId.ID_MAPPING.put(441, "minecraft:lingering_potion");
+ DataConverterMaterialId.ID_MAPPING.put(442, "minecraft:shield");
+ DataConverterMaterialId.ID_MAPPING.put(443, "minecraft:elytra");
+ DataConverterMaterialId.ID_MAPPING.put(444, "minecraft:spruce_boat");
+ DataConverterMaterialId.ID_MAPPING.put(445, "minecraft:birch_boat");
+ DataConverterMaterialId.ID_MAPPING.put(446, "minecraft:jungle_boat");
+ DataConverterMaterialId.ID_MAPPING.put(447, "minecraft:acacia_boat");
+ DataConverterMaterialId.ID_MAPPING.put(448, "minecraft:dark_oak_boat");
+ DataConverterMaterialId.ID_MAPPING.put(449, "minecraft:totem_of_undying");
+ DataConverterMaterialId.ID_MAPPING.put(450, "minecraft:shulker_shell");
+ DataConverterMaterialId.ID_MAPPING.put(452, "minecraft:iron_nugget");
+ DataConverterMaterialId.ID_MAPPING.put(453, "minecraft:knowledge_book");
+
+ DataConverterSpawnEgg.ID_MAPPING[23] = "Arrow";
+ // CraftBukkit end
}
}
}
2018-12-25 22:00:00 +01:00
@@ -481,6 +842,30 @@
2018-07-15 02:00:00 +02:00
BlockPosition blockposition = isourceblock.getBlockPosition().shift(enumdirection);
EnumDirection enumdirection1 = isourceblock.getWorld().isEmpty(blockposition.down()) ? enumdirection : EnumDirection.UP;
+ // CraftBukkit start
+ org.bukkit.block.Block bukkitBlock = isourceblock.getWorld().getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
2018-07-15 02:00:00 +02:00
+ BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ if (!BlockDispenser.eventFired) {
+ isourceblock.getWorld().getServer().getPluginManager().callEvent(event);
+ }
+
2018-07-15 02:00:00 +02:00
+ if (event.isCancelled()) {
+ return itemstack;
+ }
+
2018-07-15 02:00:00 +02:00
+ 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
+
this.a = ((ItemBlock) item).a((BlockActionContext) (new DispenserRegistry.b(isourceblock.getWorld(), blockposition, enumdirection, itemstack, enumdirection1))) == EnumInteractionResult.SUCCESS;
if (this.a) {
itemstack.subtract(1);
2018-12-25 22:00:00 +01:00
@@ -530,12 +915,40 @@
2016-02-29 22:32:46 +01:00
d3 = 0.0D;
}
- EntityBoat entityboat = new EntityBoat(world, d0, d1 + d3, d2);
+ // EntityBoat entityboat = new EntityBoat(world, d0, d1 + d3, d2);
+ // CraftBukkit start
+ ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(d0, d1 + d3, d2));
+ if (!BlockDispenser.eventFired) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ if (event.isCancelled()) {
2016-11-17 02:41:03 +01:00
+ itemstack.add(1);
2016-02-29 22:32:46 +01:00
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
2016-11-17 02:41:03 +01:00
+ itemstack.add(1);
2016-02-29 22:32:46 +01:00
+ // 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) {
2018-07-15 02:00:00 +02:00
+ idispensebehavior.dispense(isourceblock, eventStack);
2016-02-29 22:32:46 +01:00
+ return itemstack;
+ }
+ }
+
+ EntityBoat entityboat = new EntityBoat(world, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ());
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
entityboat.setType(this.b);
2016-11-17 02:41:03 +01:00
entityboat.yaw = enumdirection.l();
- world.addEntity(entityboat);
2016-11-17 02:41:03 +01:00
- itemstack.subtract(1);
+ if (!world.addEntity(entityboat)) itemstack.add(1); // CraftBukkit
2016-11-17 02:41:03 +01:00
+ // itemstack.subtract(1); // CraftBukkit - handled during event processing
2016-02-29 22:32:46 +01:00
return itemstack;
}