use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project PaperDev by Kamillaova.
the class DispenseBehaviorItem method a.
// CraftBukkit start - void -> boolean return, IPosition -> ISourceBlock last argument
public static boolean a(World world, ItemStack itemstack, int i, EnumDirection enumdirection, ISourceBlock isourceblock) {
IPosition iposition = BlockDispenser.a(isourceblock);
// CraftBukkit end
double d0 = iposition.getX();
double d1 = iposition.getY();
double d2 = iposition.getZ();
if (enumdirection.k() == EnumDirection.EnumAxis.Y) {
d1 -= 0.125D;
} else {
d1 -= 0.15625D;
}
EntityItem entityitem = new EntityItem(world, d0, d1, d2, itemstack);
double d3 = world.random.nextDouble() * 0.1D + 0.2D;
entityitem.motX = (double) enumdirection.getAdjacentX() * d3;
entityitem.motY = 0.20000000298023224D;
entityitem.motZ = (double) enumdirection.getAdjacentZ() * 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.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(entityitem.motX, entityitem.motY, entityitem.motZ));
if (!BlockDispenser.eventFired) {
world.getServer().getPluginManager().callEvent(event);
}
if (event.isCancelled()) {
return false;
}
entityitem.setItemStack(CraftItemStack.asNMSCopy(event.getItem()));
entityitem.motX = event.getVelocity().getX();
entityitem.motY = event.getVelocity().getY();
entityitem.motZ = event.getVelocity().getZ();
if (!event.getItem().getType().equals(craftItem.getType())) {
// 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.getClass() != DispenseBehaviorItem.class) {
idispensebehavior.a(isourceblock, eventStack);
} else {
world.addEntity(entityitem);
}
return false;
}
world.addEntity(entityitem);
return true;
// CraftBukkit end
}
use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project PaperDev by Kamillaova.
the class DispenserRegistry method b.
static void b() {
BlockDispenser.REGISTRY.a(Items.ARROW, new DispenseBehaviorProjectile() {
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) {
EntityTippedArrow entitytippedarrow = new EntityTippedArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
entitytippedarrow.fromPlayer = EntityArrow.PickupStatus.ALLOWED;
return entitytippedarrow;
}
});
BlockDispenser.REGISTRY.a(Items.TIPPED_ARROW, new DispenseBehaviorProjectile() {
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) {
EntityTippedArrow entitytippedarrow = new EntityTippedArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
entitytippedarrow.a(itemstack);
entitytippedarrow.fromPlayer = EntityArrow.PickupStatus.ALLOWED;
return entitytippedarrow;
}
});
BlockDispenser.REGISTRY.a(Items.SPECTRAL_ARROW, new DispenseBehaviorProjectile() {
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) {
EntitySpectralArrow entityspectralarrow = new EntitySpectralArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
entityspectralarrow.fromPlayer = EntityArrow.PickupStatus.ALLOWED;
return entityspectralarrow;
}
});
BlockDispenser.REGISTRY.a(Items.EGG, new DispenseBehaviorProjectile() {
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) {
return new EntityEgg(world, iposition.getX(), iposition.getY(), iposition.getZ());
}
});
BlockDispenser.REGISTRY.a(Items.SNOWBALL, new DispenseBehaviorProjectile() {
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) {
return new EntitySnowball(world, iposition.getX(), iposition.getY(), iposition.getZ());
}
});
BlockDispenser.REGISTRY.a(Items.EXPERIENCE_BOTTLE, new DispenseBehaviorProjectile() {
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) {
return new EntityThrownExpBottle(world, iposition.getX(), iposition.getY(), iposition.getZ());
}
protected float a() {
return super.a() * 0.5F;
}
protected float getPower() {
return super.getPower() * 1.25F;
}
});
BlockDispenser.REGISTRY.a(Items.SPLASH_POTION, new IDispenseBehavior() {
public ItemStack a(ISourceBlock isourceblock, final ItemStack itemstack) {
return (new DispenseBehaviorProjectile() {
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack1) {
// CraftBukkit - decompile issue
return new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ(), itemstack1.cloneItemStack());
}
protected float a() {
return super.a() * 0.5F;
}
protected float getPower() {
return super.getPower() * 1.25F;
}
}).a(isourceblock, itemstack);
}
});
BlockDispenser.REGISTRY.a(Items.LINGERING_POTION, new IDispenseBehavior() {
public ItemStack a(ISourceBlock isourceblock, final ItemStack itemstack) {
return (new DispenseBehaviorProjectile() {
protected IProjectile a(World world, IPosition iposition, ItemStack itemstack1) {
// CraftBukkit - decompile issue
return new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ(), itemstack1.cloneItemStack());
}
protected float a() {
return super.a() * 0.5F;
}
protected float getPower() {
return super.getPower() * 1.25F;
}
}).a(isourceblock, itemstack);
}
});
BlockDispenser.REGISTRY.a(Items.SPAWN_EGG, new DispenseBehaviorItem() {
public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
EnumDirection enumdirection = (EnumDirection) isourceblock.e().get(BlockDispenser.FACING);
double d0 = isourceblock.getX() + (double) enumdirection.getAdjacentX();
double d1 = (double) ((float) (isourceblock.getBlockPosition().getY() + enumdirection.getAdjacentY()) + 0.2F);
double d2 = isourceblock.getZ() + (double) enumdirection.getAdjacentZ();
// Entity entity = ItemMonsterEgg.a(isourceblock.getWorld(), ItemMonsterEgg.h(itemstack), d0, d1, d2);
// CraftBukkit start
World world = isourceblock.getWorld();
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, d2));
if (!BlockDispenser.eventFired) {
world.getServer().getPluginManager().callEvent(event);
}
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.a(isourceblock, eventStack);
return itemstack;
}
}
itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
Entity entity = ItemMonsterEgg.spawnCreature(isourceblock.getWorld(), ItemMonsterEgg.h(itemstack), event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DISPENSE_EGG);
if (entity instanceof EntityLiving && itemstack.hasName()) {
entity.setCustomName(itemstack.getName());
}
ItemMonsterEgg.a(isourceblock.getWorld(), (EntityHuman) null, itemstack, entity);
// CraftBukkit end
return itemstack;
}
});
BlockDispenser.REGISTRY.a(Items.FIREWORKS, new DispenseBehaviorItem() {
public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
EnumDirection enumdirection = (EnumDirection) isourceblock.e().get(BlockDispenser.FACING);
double d0 = isourceblock.getX() + (double) enumdirection.getAdjacentX();
double d1 = (double) ((float) isourceblock.getBlockPosition().getY() + 0.2F);
double d2 = isourceblock.getZ() + (double) enumdirection.getAdjacentZ();
// CraftBukkit start
World world = isourceblock.getWorld();
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, d2));
if (!BlockDispenser.eventFired) {
world.getServer().getPluginManager().callEvent(event);
}
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.a(isourceblock, eventStack);
return itemstack;
}
}
itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
EntityFireworks entityfireworks = new EntityFireworks(isourceblock.getWorld(), event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), itemstack1);
isourceblock.getWorld().addEntity(entityfireworks);
// CraftBukkit end
return itemstack;
}
protected void a(ISourceBlock isourceblock) {
isourceblock.getWorld().triggerEffect(1004, isourceblock.getBlockPosition(), 0);
}
});
BlockDispenser.REGISTRY.a(Items.FIRE_CHARGE, new DispenseBehaviorItem() {
public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
EnumDirection enumdirection = (EnumDirection) isourceblock.e().get(BlockDispenser.FACING);
IPosition iposition = BlockDispenser.a(isourceblock);
double d0 = iposition.getX() + (double) ((float) enumdirection.getAdjacentX() * 0.3F);
double d1 = iposition.getY() + (double) ((float) enumdirection.getAdjacentY() * 0.3F);
double d2 = iposition.getZ() + (double) ((float) enumdirection.getAdjacentZ() * 0.3F);
World world = isourceblock.getWorld();
Random random = world.random;
double d3 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentX();
double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentY();
double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentZ();
// 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(d3, d4, d5));
if (!BlockDispenser.eventFired) {
world.getServer().getPluginManager().callEvent(event);
}
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.a(isourceblock, eventStack);
return itemstack;
}
}
EntitySmallFireball fireball = new EntitySmallFireball(world, d0, d1, d2, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ());
fireball.projectileSource = new org.bukkit.craftbukkit.v1_12_R1.projectiles.CraftBlockProjectileSource((TileEntityDispenser) isourceblock.getTileEntity());
world.addEntity(fireball);
// CraftBukkit end
return itemstack;
}
protected void a(ISourceBlock isourceblock) {
isourceblock.getWorld().triggerEffect(1018, isourceblock.getBlockPosition(), 0);
}
});
BlockDispenser.REGISTRY.a(Items.aH, new DispenserRegistry.a(EntityBoat.EnumBoatType.OAK));
BlockDispenser.REGISTRY.a(Items.aI, new DispenserRegistry.a(EntityBoat.EnumBoatType.SPRUCE));
BlockDispenser.REGISTRY.a(Items.aJ, new DispenserRegistry.a(EntityBoat.EnumBoatType.BIRCH));
BlockDispenser.REGISTRY.a(Items.aK, new DispenserRegistry.a(EntityBoat.EnumBoatType.JUNGLE));
BlockDispenser.REGISTRY.a(Items.aM, new DispenserRegistry.a(EntityBoat.EnumBoatType.DARK_OAK));
BlockDispenser.REGISTRY.a(Items.aL, new DispenserRegistry.a(EntityBoat.EnumBoatType.ACACIA));
DispenseBehaviorItem dispensebehavioritem = new DispenseBehaviorItem() {
private final DispenseBehaviorItem b = new DispenseBehaviorItem();
public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
ItemBucket itembucket = (ItemBucket) itemstack.getItem();
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
// CraftBukkit start
World world = isourceblock.getWorld();
int x = blockposition.getX();
int y = blockposition.getY();
int z = blockposition.getZ();
if (world.isEmpty(blockposition) || !world.getType(blockposition).getMaterial().isBuildable()) {
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());
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
idispensebehavior.a(isourceblock, eventStack);
return itemstack;
}
}
itembucket = (ItemBucket) CraftItemStack.asNMSCopy(event.getItem()).getItem();
}
if (itembucket.a((EntityHuman) null, isourceblock.getWorld(), blockposition)) {
// 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.a(isourceblock, new ItemStack(item));
}
// CraftBukkit end
return itemstack;
} else {
return this.b.a(isourceblock, itemstack);
}
}
};
BlockDispenser.REGISTRY.a(Items.LAVA_BUCKET, dispensebehavioritem);
BlockDispenser.REGISTRY.a(Items.WATER_BUCKET, dispensebehavioritem);
BlockDispenser.REGISTRY.a(Items.BUCKET, new DispenseBehaviorItem() {
private final DispenseBehaviorItem b = new DispenseBehaviorItem();
public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
World world = isourceblock.getWorld();
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
IBlockData iblockdata = world.getType(blockposition);
Block block = iblockdata.getBlock();
Material material = iblockdata.getMaterial();
Item item;
if (Material.WATER.equals(material) && block instanceof BlockFluids && ((Integer) iblockdata.get(BlockFluids.LEVEL)).intValue() == 0) {
item = Items.WATER_BUCKET;
} else {
if (!Material.LAVA.equals(material) || !(block instanceof BlockFluids) || ((Integer) iblockdata.get(BlockFluids.LEVEL)).intValue() != 0) {
return super.b(isourceblock, itemstack);
}
item = Items.LAVA_BUCKET;
}
// 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.a(isourceblock, eventStack);
return itemstack;
}
}
// CraftBukkit end
world.setAir(blockposition);
itemstack.subtract(1);
if (itemstack.isEmpty()) {
return new ItemStack(item);
} else {
if (((TileEntityDispenser) isourceblock.getTileEntity()).addItem(new ItemStack(item)) < 0) {
this.b.a(isourceblock, new ItemStack(item));
}
return itemstack;
}
}
});
BlockDispenser.REGISTRY.a(Items.FLINT_AND_STEEL, new DispenserRegistry.b() {
protected ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
World world = isourceblock.getWorld();
// 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());
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
idispensebehavior.a(isourceblock, eventStack);
return itemstack;
}
}
// CraftBukkit end
this.b = true;
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
if (world.isEmpty(blockposition)) {
// CraftBukkit start - Ignition by dispensing flint and steel
if (!org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition.getX(), blockposition.getY(), blockposition.getZ(), isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ()).isCancelled()) {
world.setTypeUpdate(blockposition, Blocks.FIRE.getBlockData());
if (itemstack.isDamaged(1, world.random, (EntityPlayer) null)) {
itemstack.setCount(0);
}
}
// CraftBukkit end
} else if (world.getType(blockposition).getBlock() == Blocks.TNT) {
Blocks.TNT.postBreak(world, blockposition, Blocks.TNT.getBlockData().set(BlockTNT.EXPLODE, Boolean.valueOf(true)));
world.setAir(blockposition);
} else {
this.b = false;
}
return itemstack;
}
});
BlockDispenser.REGISTRY.a(Items.DYE, new DispenserRegistry.b() {
protected ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
this.b = true;
if (EnumColor.WHITE == EnumColor.fromInvColorIndex(itemstack.getData())) {
World world = isourceblock.getWorld();
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
// 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());
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
idispensebehavior.a(isourceblock, eventStack);
return itemstack;
}
}
world.captureTreeGeneration = true;
if (ItemDye.a(itemstack, world, blockposition)) {
if (!world.isClientSide) {
world.triggerEffect(2005, blockposition, 0);
}
} else {
this.b = false;
}
// 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);
}
if (structureEvent == null || !structureEvent.isCancelled()) {
for (org.bukkit.block.BlockState blockstate : blocks) {
blockstate.update(true);
}
}
}
return itemstack;
} else {
return super.b(isourceblock, itemstack);
}
}
});
BlockDispenser.REGISTRY.a(Item.getItemOf(Blocks.TNT), new DispenseBehaviorItem() {
protected ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
World world = isourceblock.getWorld();
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
// 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);
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((double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D));
if (!BlockDispenser.eventFired) {
world.getServer().getPluginManager().callEvent(event);
}
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.a(isourceblock, eventStack);
return itemstack;
}
}
EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), (EntityLiving) null);
// CraftBukkit end
world.addEntity(entitytntprimed);
world.a((EntityHuman) null, entitytntprimed.locX, entitytntprimed.locY, entitytntprimed.locZ, SoundEffects.hW, SoundCategory.BLOCKS, 1.0F, 1.0F);
// itemstack.subtract(1); // CraftBukkit - handled above
return itemstack;
}
});
BlockDispenser.REGISTRY.a(Items.SKULL, new DispenserRegistry.b() {
protected ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
World world = isourceblock.getWorld();
EnumDirection enumdirection = (EnumDirection) isourceblock.e().get(BlockDispenser.FACING);
BlockPosition blockposition = isourceblock.getBlockPosition().shift(enumdirection);
BlockSkull blockskull = Blocks.SKULL;
// 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.a(isourceblock, eventStack);
return itemstack;
}
}
// CraftBukkit end
this.b = true;
if (world.isEmpty(blockposition) && blockskull.b(world, blockposition, itemstack)) {
if (!world.isClientSide) {
world.setTypeAndData(blockposition, blockskull.getBlockData().set(BlockSkull.FACING, EnumDirection.UP), 3);
TileEntity tileentity = world.getTileEntity(blockposition);
if (tileentity instanceof TileEntitySkull) {
if (itemstack.getData() == 3) {
GameProfile gameprofile = null;
if (itemstack.hasTag()) {
NBTTagCompound nbttagcompound = itemstack.getTag();
if (nbttagcompound.hasKeyOfType("SkullOwner", 10)) {
gameprofile = GameProfileSerializer.deserialize(nbttagcompound.getCompound("SkullOwner"));
} else if (nbttagcompound.hasKeyOfType("SkullOwner", 8)) {
String s = nbttagcompound.getString("SkullOwner");
if (!UtilColor.b(s)) {
gameprofile = new GameProfile((UUID) null, s);
}
}
}
((TileEntitySkull) tileentity).setGameProfile(gameprofile);
} else {
((TileEntitySkull) tileentity).setSkullType(itemstack.getData());
}
((TileEntitySkull) tileentity).setRotation(enumdirection.opposite().get2DRotationValue() * 4);
Blocks.SKULL.a(world, blockposition, (TileEntitySkull) tileentity);
}
itemstack.subtract(1);
}
} else if (ItemArmor.a(isourceblock, itemstack).isEmpty()) {
this.b = false;
}
return itemstack;
}
});
BlockDispenser.REGISTRY.a(Item.getItemOf(Blocks.PUMPKIN), new DispenserRegistry.b() {
protected ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
World world = isourceblock.getWorld();
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
BlockPumpkin blockpumpkin = (BlockPumpkin) Blocks.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) {
idispensebehavior.a(isourceblock, eventStack);
return itemstack;
}
}
// CraftBukkit end
this.b = true;
if (world.isEmpty(blockposition) && blockpumpkin.b(world, blockposition)) {
if (!world.isClientSide) {
world.setTypeAndData(blockposition, blockpumpkin.getBlockData(), 3);
}
itemstack.subtract(1);
} else {
ItemStack itemstack1 = ItemArmor.a(isourceblock, itemstack);
if (itemstack1.isEmpty()) {
this.b = false;
}
}
return itemstack;
}
});
EnumColor[] aenumcolor = EnumColor.values();
int i = aenumcolor.length;
for (int j = 0; j < i; ++j) {
EnumColor enumcolor = aenumcolor[j];
BlockDispenser.REGISTRY.a(Item.getItemOf(BlockShulkerBox.a(enumcolor)), new DispenserRegistry.c(null));
}
}
use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project PaperDev by Kamillaova.
the class ShapedRecipes method toBukkitRecipe.
// CraftBukkit start
public org.bukkit.inventory.ShapedRecipe toBukkitRecipe() {
CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
CraftShapedRecipe recipe = new CraftShapedRecipe(result, this);
switch(this.height) {
case 1:
switch(this.width) {
case 1:
recipe.shape("a");
break;
case 2:
recipe.shape("ab");
break;
case 3:
recipe.shape("abc");
break;
}
break;
case 2:
switch(this.width) {
case 1:
recipe.shape("a", "b");
break;
case 2:
recipe.shape("ab", "cd");
break;
case 3:
recipe.shape("abc", "def");
break;
}
break;
case 3:
switch(this.width) {
case 1:
recipe.shape("a", "b", "c");
break;
case 2:
recipe.shape("ab", "cd", "ef");
break;
case 3:
recipe.shape("abc", "def", "ghi");
break;
}
break;
}
char c = 'a';
for (RecipeItemStack list : this.items) {
if (list != null && list.choices.length > 0) {
net.minecraft.server.v1_12_R1.ItemStack stack = list.choices[0];
recipe.setIngredient(c, org.bukkit.craftbukkit.v1_12_R1.util.CraftMagicNumbers.getMaterial(stack.getItem()), (list.choices.length) > 1 ? 32767 : stack.getData());
}
c++;
}
return recipe;
}
use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project PaperDev by Kamillaova.
the class ShapelessRecipes method toBukkitRecipe.
// CraftBukkit start
@SuppressWarnings("unchecked")
public org.bukkit.inventory.ShapelessRecipe toBukkitRecipe() {
CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
CraftShapelessRecipe recipe = new CraftShapelessRecipe(result, this);
for (RecipeItemStack list : this.ingredients) {
if (list != null) {
net.minecraft.server.v1_12_R1.ItemStack stack = list.choices[0];
recipe.addIngredient(org.bukkit.craftbukkit.v1_12_R1.util.CraftMagicNumbers.getMaterial(stack.getItem()), (list.choices.length) > 1 ? 32767 : stack.getData());
}
}
return recipe;
}
use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project PaperDev by Kamillaova.
the class TileEntityFurnace method burn.
public void burn() {
if (this.canBurn()) {
ItemStack itemstack = (ItemStack) this.items.get(0);
ItemStack itemstack1 = RecipesFurnace.getInstance().getResult(itemstack);
ItemStack itemstack2 = (ItemStack) this.items.get(2);
// CraftBukkit start - fire FurnaceSmeltEvent
CraftItemStack source = CraftItemStack.asCraftMirror(itemstack);
org.bukkit.inventory.ItemStack result = CraftItemStack.asBukkitCopy(itemstack1);
FurnaceSmeltEvent furnaceSmeltEvent = new FurnaceSmeltEvent(this.world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()), source, result);
this.world.getServer().getPluginManager().callEvent(furnaceSmeltEvent);
if (furnaceSmeltEvent.isCancelled()) {
return;
}
result = furnaceSmeltEvent.getResult();
itemstack1 = CraftItemStack.asNMSCopy(result);
if (!itemstack1.isEmpty()) {
if (itemstack2.isEmpty()) {
this.items.set(2, itemstack1.cloneItemStack());
} else if (CraftItemStack.asCraftMirror(itemstack2).isSimilar(result)) {
itemstack2.add(itemstack1.getCount());
} else {
return;
}
}
if (itemstack.getItem() == Item.getItemOf(Blocks.SPONGE) && itemstack.getData() == 1 && !((ItemStack) this.items.get(1)).isEmpty() && ((ItemStack) this.items.get(1)).getItem() == Items.BUCKET) {
this.items.set(1, new ItemStack(Items.WATER_BUCKET));
}
itemstack.subtract(1);
}
}
Aggregations