// alkazia private boolean k() { IInventory iinventory = this.l(); if (iinventory == null) { return false; } else { for (int i = 0; i < this.getSize(); ++i) { if (this.getItem(i) != null) { ItemStack itemstack = this.getItem(i).cloneItemStack(); // CraftBukkit start - Call event when pushing items into other inventories CraftItemStack oitemstack = CraftItemStack.asCraftMirror(this.splitStack(i, 1)); Inventory destinationInventory; // Have to special case large chests as they work oddly if (iinventory instanceof InventoryLargeChest) { destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest( (InventoryLargeChest) iinventory); } else if (isIronChest) { destinationInventory = null; } else { destinationInventory = iinventory.getOwner().getInventory(); } InventoryMoveItemEvent event = new InventoryMoveItemEvent( this.getOwner().getInventory(), oitemstack.clone(), destinationInventory, true); this.getWorld().getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { this.setItem(i, itemstack); this.c(world.spigotConfig.hopperTransfer); // Spigot return false; } ItemStack itemstack1 = addItem( iinventory, CraftItemStack.asNMSCopy(event.getItem()), Facing.OPPOSITE_FACING[BlockHopper.b(this.p())]); if (itemstack1 == null || itemstack1.count == 0) { if (event.getItem().equals(oitemstack)) { iinventory.update(); } else { this.setItem(i, itemstack); } // CraftBukkit end return true; } this.setItem(i, itemstack); } } return false; } }
private static boolean tryTakeInItemFromSlot( IHopper ihopper, IInventory iinventory, int i, int j) { ItemStack itemstack = iinventory.getItem(i); if (itemstack != null && canTakeItemFromInventory(iinventory, itemstack, i, j)) { ItemStack itemstack1 = itemstack.cloneItemStack(); // CraftBukkit start - Call event on collection of items from inventories into the hopper CraftItemStack oitemstack = CraftItemStack.asCraftMirror(iinventory.splitStack(i, 1)); Inventory sourceInventory; // Have to special case large chests as they work oddly if (iinventory instanceof InventoryLargeChest) { sourceInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest( (InventoryLargeChest) iinventory); } else if (isIronChest) { sourceInventory = null; } else { sourceInventory = iinventory.getOwner().getInventory(); } InventoryMoveItemEvent event = new InventoryMoveItemEvent( sourceInventory, oitemstack.clone(), ihopper.getOwner().getInventory(), false); ihopper.getWorld().getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { iinventory.setItem(i, itemstack1); if (ihopper instanceof TileEntityHopper) { ((TileEntityHopper) ihopper).c(ihopper.getWorld().spigotConfig.hopperTransfer); // Spigot } else if (ihopper instanceof EntityMinecartHopper) { ((EntityMinecartHopper) ihopper) .l(ihopper.getWorld().spigotConfig.hopperTransfer / 2); // Spigot } return false; } ItemStack itemstack2 = addItem(ihopper, CraftItemStack.asNMSCopy(event.getItem()), -1); if (itemstack2 == null || itemstack2.count == 0) { if (event.getItem().equals(oitemstack)) { iinventory.update(); } else { iinventory.setItem(i, itemstack1); } // CraftBukkit end return true; } iinventory.setItem(i, itemstack1); } return false; }
public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) { EnumFacing enumfacing = BlockDispenser.b(isourceblock.h()); double d0 = isourceblock.getX() + (double) enumfacing.c(); double d1 = (double) ((float) isourceblock.getBlockY() + 0.2F); double d2 = isourceblock.getZ() + (double) enumfacing.e(); // CraftBukkit start World world = isourceblock.k(); ItemStack itemstack1 = itemstack.a(1); org.bukkit.block.Block block = world .getWorld() .getBlockAt( isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ()); 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.count++; return itemstack; } if (!event.getItem().equals(craftItem)) { itemstack.count++; // Chain to handler for new item ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem()); if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) { idispensebehavior.a(isourceblock, eventStack); return itemstack; } } itemstack1 = CraftItemStack.asNMSCopy(event.getItem()); EntityFireworks entityfireworks = new EntityFireworks( isourceblock.k(), event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), itemstack1); isourceblock.k().addEntity(entityfireworks); // itemstack.a(1); // Handled during event processing // CraftBukkit end return itemstack; }
public void die(DamageSource damagesource) { // CraftBukkit start if (this.dead) { return; } java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>(); boolean keepInventory = this.world.getGameRules().getBoolean("keepInventory"); if (!keepInventory) { for (int i = 0; i < this.inventory.items.length; ++i) { if (this.inventory.items[i] != null) { loot.add(CraftItemStack.asCraftMirror(this.inventory.items[i])); } } for (int i = 0; i < this.inventory.armor.length; ++i) { if (this.inventory.armor[i] != null) { loot.add(CraftItemStack.asCraftMirror(this.inventory.armor[i])); } } } org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent( this, loot, damagesource.getLocalizedDeathMessage(this)); String deathMessage = event.getDeathMessage(); if (deathMessage != null && deathMessage.length() > 0) { this.server.getPlayerList().k(event.getDeathMessage()); } // CraftBukkit - we clean the player's inventory after the EntityDeathEvent is called so plugins // can get the exact state of the inventory. if (!keepInventory) { for (int i = 0; i < this.inventory.items.length; ++i) { this.inventory.items[i] = null; } for (int i = 0; i < this.inventory.armor.length; ++i) { this.inventory.armor[i] = null; } } this.closeInventory(); // Update effects on player death this.updateEffects = true; // CraftBukkit end }
public void setItemOnCursor(ItemStack item) { net.minecraft.server.ItemStack stack = CraftItemStack.asNMSCopy(item); getHandle().inventory.setCarried(stack); if (this instanceof CraftPlayer) { ((EntityPlayer) getHandle()).broadcastCarriedItem(); // Send set slot for cursor } }
// 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 (ItemStack stack : this.items) { if (stack != null) { recipe.setIngredient( c, org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(stack.getItem()), stack.getData()); } c++; } return recipe; }
protected void dropDeathLoot(boolean flag, int i) { // CraftBukkit start java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>(); int j = this.random.nextInt(3); int k; if (j > 0) { loot.add(CraftItemStack.asNewCraftStack(Item.byId[Block.RED_ROSE.id], j)); } k = 3 + this.random.nextInt(3); if (k > 0) { loot.add(CraftItemStack.asNewCraftStack(Item.IRON_INGOT, k)); } org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, loot); // CraftBukkit end }
@Override public boolean addRecipe(Recipe recipe) { // GameRegistry.addRecipe((IRecipe) recipe); if (recipe instanceof ShapedRecipe) { ShapedRecipe r = (ShapedRecipe) recipe; boolean useOreDict = false; // Map<Character,net.minecraft.item.ItemStack> nmsRecipe = Maps.newHashMap(); List<Object> objRecipe = new ArrayList<Object>(); objRecipe.addAll(Arrays.asList(r.getShape())); for (Character j : r.getIngredientMap().keySet()) { ItemStack x = r.getIngredientMap().get(j); net.minecraft.item.ItemStack nms = CraftItemStack.createNMSItemStack(x); if (OreDictionary.getOreID(nms) != -1) { useOreDict = true; } if (LiquidContainerRegistry.isContainer(nms)) { useOreDict = true; } objRecipe.add(j); objRecipe.add(nms); } if (useOreDict) { ShapedOreRecipe rec = new ShapedOreRecipe(CraftItemStack.createNMSItemStack(recipe.getResult()), objRecipe); GameRegistry.addRecipe(rec); } else { GameRegistry.addRecipe(CraftItemStack.createNMSItemStack(recipe.getResult()), objRecipe); } } else if (recipe instanceof ShapelessRecipe) { ShapelessRecipe r = (ShapelessRecipe) recipe; List<net.minecraft.item.ItemStack> items = new ArrayList<net.minecraft.item.ItemStack>(); boolean useOreDict = false; for (ItemStack i : r.getIngredientList()) { net.minecraft.item.ItemStack nms = CraftItemStack.createNMSItemStack(i); if (OreDictionary.getOreID(nms) != -1) { useOreDict = true; } if (LiquidContainerRegistry.isContainer(nms)) { useOreDict = true; } items.add(nms); } if (useOreDict) { // TODO: Check if the new Class is even required // ShapelessOreRecipe nmsRec = new ShapelessOreRecipe(CraftItemStack.createNMSItemStack(recipe.getResult()), items); } else { ShapelessRecipes nmsRec = new ShapelessRecipes(CraftItemStack.createNMSItemStack(recipe.getResult()), items); GameRegistry.addRecipe(nmsRec); } } return true; }
// CraftBukkit - priv to public public void dispense(World world, int i, int j, int k, Random random) { int l = world.getData(i, j, k); byte b0 = 0; byte b1 = 0; if (l == 3) { b1 = 1; } else if (l == 2) { b1 = -1; } else if (l == 5) { b0 = 1; } else { b0 = -1; } TileEntityDispenser tileentitydispenser = (TileEntityDispenser) world.getTileEntity(i, j, k); if (tileentitydispenser != null) { // CraftBukkit start int dispenseSlot = tileentitydispenser.findDispenseSlot(); ItemStack itemstack = null; if (dispenseSlot > -1) { itemstack = tileentitydispenser.getContents()[dispenseSlot]; // Copy item stack, because we want it to have 1 item itemstack = new ItemStack(itemstack.id, 1, itemstack.getData(), itemstack.getEnchantments()); } // CraftBukkit end double d0 = (double) i + (double) b0 * 0.6D + 0.5D; double d1 = (double) j + 0.5D; double d2 = (double) k + (double) b1 * 0.6D + 0.5D; if (itemstack == null) { world.triggerEffect(1001, i, j, k, 0); } else { // CraftBukkit start double d3 = random.nextDouble() * 0.1D + 0.2D; double motX = (double) b0 * d3; double motY = 0.20000000298023224D; double motZ = (double) b1 * d3; motX += random.nextGaussian() * 0.007499999832361937D * 6.0D; motY += random.nextGaussian() * 0.007499999832361937D * 6.0D; motZ += random.nextGaussian() * 0.007499999832361937D * 6.0D; org.bukkit.block.Block block = world.getWorld().getBlockAt(i, j, k); org.bukkit.inventory.ItemStack bukkitItem = new CraftItemStack(itemstack).clone(); BlockDispenseEvent event = new BlockDispenseEvent(block, bukkitItem, new Vector(motX, motY, motZ)); world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; } if (event.getItem().equals(bukkitItem)) { // Actually remove the item tileentitydispenser.splitStack(dispenseSlot, 1); } motX = event.getVelocity().getX(); motY = event.getVelocity().getY(); motZ = event.getVelocity().getZ(); itemstack = CraftItemStack.createNMSItemStack(event.getItem()); // CraftBukkit end if (itemstack.id == Item.ARROW.id) { EntityArrow entityarrow = new EntityArrow(world, d0, d1, d2); entityarrow.shoot((double) b0, 0.10000000149011612D, (double) b1, 1.1F, 6.0F); entityarrow.fromPlayer = true; world.addEntity(entityarrow); world.triggerEffect(1002, i, j, k, 0); } else if (itemstack.id == Item.EGG.id) { EntityEgg entityegg = new EntityEgg(world, d0, d1, d2); entityegg.a((double) b0, 0.10000000149011612D, (double) b1, 1.1F, 6.0F); world.addEntity(entityegg); world.triggerEffect(1002, i, j, k, 0); } else if (itemstack.id == Item.SNOW_BALL.id) { EntitySnowball entitysnowball = new EntitySnowball(world, d0, d1, d2); entitysnowball.a((double) b0, 0.10000000149011612D, (double) b1, 1.1F, 6.0F); world.addEntity(entitysnowball); world.triggerEffect(1002, i, j, k, 0); } else if (itemstack.id == Item.POTION.id && ItemPotion.c(itemstack.getData())) { EntityPotion entitypotion = new EntityPotion(world, d0, d1, d2, itemstack.getData()); entitypotion.a((double) b0, 0.10000000149011612D, (double) b1, 1.375F, 3.0F); world.addEntity(entitypotion); world.triggerEffect(1002, i, j, k, 0); } else if (itemstack.id == Item.EXP_BOTTLE.id) { EntityThrownExpBottle entitythrownexpbottle = new EntityThrownExpBottle(world, d0, d1, d2); entitythrownexpbottle.a((double) b0, 0.10000000149011612D, (double) b1, 1.375F, 3.0F); world.addEntity(entitythrownexpbottle); world.triggerEffect(1002, i, j, k, 0); } else if (itemstack.id == Item.MONSTER_EGG.id) { ItemMonsterEgg.a( world, itemstack.getData(), d0 + (double) b0 * 0.3D, d1 - 0.3D, d2 + (double) b1 * 0.3D); world.triggerEffect(1002, i, j, k, 0); } else if (itemstack.id == Item.FIREBALL.id) { EntitySmallFireball entitysmallfireball = new EntitySmallFireball( world, d0 + (double) b0 * 0.3D, d1, d2 + (double) b1 * 0.3D, (double) b0 + random.nextGaussian() * 0.05D, random.nextGaussian() * 0.05D, (double) b1 + random.nextGaussian() * 0.05D); world.addEntity(entitysmallfireball); world.triggerEffect(1009, i, j, k, 0); } else { EntityItem entityitem = new EntityItem(world, d0, d1 - 0.3D, d2, itemstack); // CraftBukkit start // double d3 = random.nextDouble() * 0.1D + 0.2D; // Moved up entityitem.motX = motX; entityitem.motY = motY; entityitem.motZ = motZ; // CraftBukkit end world.addEntity(entityitem); world.triggerEffect(1000, i, j, k, 0); } world.triggerEffect(2000, i, j, k, b0 + 1 + (b1 + 1) * 3); } } }
public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) { ItemBucket itembucket = (ItemBucket) itemstack.getItem(); BlockPosition blockposition = isourceblock.getBlockPosition().shift(BlockDispenser.b(isourceblock.f())); // CraftBukkit start World world = isourceblock.i(); int x = blockposition.getX(); int y = blockposition.getY(); int z = blockposition.getZ(); if (world.isEmpty(blockposition) || !world.getType(blockposition).getBlock().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.M.get(eventStack.getItem()); if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) { idispensebehavior.a(isourceblock, eventStack); return itemstack; } } itembucket = (ItemBucket) CraftItemStack.asNMSCopy(event.getItem()).getItem(); } // CraftBukkit end if (itembucket.a(isourceblock.i(), blockposition)) { // CraftBukkit start - Handle stacked buckets Item item = Items.BUCKET; if (--itemstack.count == 0) { itemstack.setItem(Items.BUCKET); itemstack.count = 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); } }
public ItemStack getItemOnCursor() { return CraftItemStack.asCraftMirror(getHandle().inventory.getCarried()); }
public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) { World world = isourceblock.i(); IPosition iposition = BlockDispenser.a(isourceblock); EnumDirection enumdirection = BlockDispenser.b(isourceblock.f()); IProjectile iprojectile = this.a(world, iposition); // iprojectile.shoot((double) enumdirection.getAdjacentX(), (double) ((float) // enumdirection.getAdjacentY() + 0.1F), (double) enumdirection.getAdjacentZ(), this.b(), // this.a()); // CraftBukkit start ItemStack itemstack1 = itemstack.a(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) enumdirection.getAdjacentX(), (double) ((float) enumdirection.getAdjacentY() + 0.1F), (double) enumdirection.getAdjacentZ())); if (!BlockDispenser.eventFired) { world.getServer().getPluginManager().callEvent(event); } if (event.isCancelled()) { itemstack.count++; return itemstack; } if (!event.getItem().equals(craftItem)) { itemstack.count++; // Chain to handler for new item ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.N.get(eventStack.getItem()); if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) { idispensebehavior.a(isourceblock, eventStack); return itemstack; } } iprojectile.shoot( event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), this.b(), this.a()); ((Entity) iprojectile).projectileSource = new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource( (TileEntityDispenser) isourceblock.getTileEntity()); // CraftBukkit end world.addEntity((Entity) iprojectile); // itemstack.a(1); // CraftBukkit - Handled during event processing return itemstack; }