2012-10-25 05:53:23 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
|
|
import org.bukkit.event.block.BlockDispenseEvent;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
public class DispenseBehaviorItem implements IDispenseBehavior {
|
|
|
|
|
|
|
|
public DispenseBehaviorItem() {}
|
|
|
|
|
|
|
|
public final ItemStack a(ISourceBlock isourceblock, ItemStack itemstack) {
|
|
|
|
ItemStack itemstack1 = this.b(isourceblock, itemstack);
|
|
|
|
|
|
|
|
this.a(isourceblock);
|
2013-03-13 23:33:27 +01:00
|
|
|
this.a(isourceblock, BlockDispenser.j_(isourceblock.h()));
|
2012-10-25 05:53:23 +02:00
|
|
|
return itemstack1;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
|
2013-03-13 23:33:27 +01:00
|
|
|
EnumFacing enumfacing = BlockDispenser.j_(isourceblock.h());
|
2012-10-25 05:53:23 +02:00
|
|
|
IPosition iposition = BlockDispenser.a(isourceblock);
|
|
|
|
ItemStack itemstack1 = itemstack.a(1);
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
if (!a(isourceblock.k(), itemstack1, 6, enumfacing, isourceblock)) {
|
|
|
|
itemstack.count++;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CraftBukkit start - void -> boolean return, IPosition -> ISourceBlock last argument
|
|
|
|
public static boolean a(World world, ItemStack itemstack, int i, EnumFacing enumfacing, ISourceBlock isourceblock) {
|
|
|
|
IPosition iposition = BlockDispenser.a(isourceblock);
|
|
|
|
// CraftBukkit end
|
|
|
|
double d0 = iposition.getX();
|
|
|
|
double d1 = iposition.getY();
|
|
|
|
double d2 = iposition.getZ();
|
|
|
|
EntityItem entityitem = new EntityItem(world, d0, d1 - 0.3D, d2, itemstack);
|
|
|
|
double d3 = world.random.nextDouble() * 0.1D + 0.2D;
|
|
|
|
|
|
|
|
entityitem.motX = (double) enumfacing.c() * d3;
|
|
|
|
entityitem.motY = 0.20000000298023224D;
|
|
|
|
entityitem.motZ = (double) enumfacing.e() * d3;
|
|
|
|
entityitem.motX += world.random.nextGaussian() * 0.007499999832361937D * (double) i;
|
|
|
|
entityitem.motY += world.random.nextGaussian() * 0.007499999832361937D * (double) i;
|
|
|
|
entityitem.motZ += world.random.nextGaussian() * 0.007499999832361937D * (double) i;
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ());
|
2012-12-17 08:31:41 +01:00
|
|
|
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2012-12-17 08:31:41 +01:00
|
|
|
BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(entityitem.motX, entityitem.motY, entityitem.motZ));
|
2012-10-25 05:53:23 +02:00
|
|
|
if (!BlockDispenser.eventFired) {
|
|
|
|
world.getServer().getPluginManager().callEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-20 05:03:52 +01:00
|
|
|
entityitem.setItemStack(CraftItemStack.asNMSCopy(event.getItem()));
|
2012-10-25 05:53:23 +02:00
|
|
|
entityitem.motX = event.getVelocity().getX();
|
|
|
|
entityitem.motY = event.getVelocity().getY();
|
|
|
|
entityitem.motZ = event.getVelocity().getZ();
|
|
|
|
|
2012-12-17 08:31:41 +01:00
|
|
|
if (!event.getItem().equals(craftItem)) {
|
2012-10-25 05:53:23 +02:00
|
|
|
// Chain to handler for new item
|
2012-12-17 08:31:41 +01:00
|
|
|
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
|
2012-11-08 01:26:35 +01:00
|
|
|
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
|
2012-10-25 05:53:23 +02:00
|
|
|
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior.getClass() != DispenseBehaviorItem.class) {
|
2012-11-08 01:26:35 +01:00
|
|
|
idispensebehavior.a(isourceblock, eventStack);
|
|
|
|
} else {
|
|
|
|
world.addEntity(entityitem);
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-08 01:26:35 +01:00
|
|
|
world.addEntity(entityitem);
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
return true;
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void a(ISourceBlock isourceblock) {
|
|
|
|
isourceblock.k().triggerEffect(1000, isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void a(ISourceBlock isourceblock, EnumFacing enumfacing) {
|
|
|
|
isourceblock.k().triggerEffect(2000, isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ(), this.a(enumfacing));
|
|
|
|
}
|
|
|
|
|
|
|
|
private int a(EnumFacing enumfacing) {
|
|
|
|
return enumfacing.c() + 1 + (enumfacing.e() + 1) * 3;
|
|
|
|
}
|
|
|
|
}
|