@Override protected float getSaturation(ItemStack stack) { byte data = stack.getData().getData(); switch (data) { case 0: return 6f; case 1: return 9.6f; default: throw new IllegalArgumentException("Cannot find fish(350) for data: " + data); } }
@Override protected int getFoodLevel(ItemStack stack) { byte data = stack.getData().getData(); switch (data) { case 0: return 5; case 1: return 6; default: throw new IllegalArgumentException("Cannot find fish(350) for data: " + data); } } }
@Override protected float getSaturation(ItemStack stack) { byte data = stack.getData().getData(); switch (data) { case 0: case 1: return 0.4f; case 2: case 3: return 0.2f; default: throw new IllegalArgumentException("Cannot find fish(349) for data: " + data); } }
@Override protected int getFoodLevel(ItemStack stack) { byte data = stack.getData().getData(); switch (data) { case 0: case 1: return 2; case 2: case 3: return 1; default: throw new IllegalArgumentException("Cannot find fish(349) for data: " + data); } }
/** * Called when a block is placed to calculate what the block will become. * * @param player the player who placed the block * @param state the BlockState to edit * @param holding the ItemStack that was being held * @param face the face off which the block is being placed * @param clickedLoc where in the block the click occurred */ public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) { state.setType(holding.getType()); state.setData(holding.getData()); }
private int countAllItems(Inventory inventory, Material material, int data, int maxCount) { if (material == null) { return Arrays.stream(inventory.getContents()) .filter(stack -> !InventoryUtil.isEmpty(stack)).mapToInt(ItemStack::getAmount) .sum(); } int count = 0; for (ItemStack stack : inventory.getContents()) { if (stack.getType() == material && (data == -1 || data == stack.getData().getData()) && (maxCount == -1 || maxCount == 0 || count < maxCount)) { if (maxCount == -1 || maxCount == 0) { count += stack.getAmount(); } else { for (int i = 0; i < stack.getAmount(); i++) { if (count < maxCount) { count++; } else { return count; } } } } } return count; }
private boolean matchingType(GlowBlock block, BlockFace face, ItemStack holding, boolean ignoreFace) { if (holding == null) { return false; } Material blockType = block.getType(); byte blockData = block.getData(); byte holdingData = holding.getData().getData(); return (blockType == Material.STEP || blockType == Material.WOOD_STEP || blockType == Material.STONE_SLAB2 || blockType == Material.PURPUR_SLAB) && blockType == holding.getType() && (face == BlockFace.UP && blockData == holdingData || face == BlockFace.DOWN && blockData - 8 == holdingData || ignoreFace && blockData % 8 == holdingData); }
/** * Creates a new item stack derived from the specified stack * * @param stack the stack to copy * @throws IllegalArgumentException if the specified stack is null or * returns an item meta not created by the item factory */ public ItemStack(final ItemStack stack) throws IllegalArgumentException { Validate.notNull(stack, "Cannot copy null stack"); this.type = stack.getTypeId(); this.amount = stack.getAmount(); this.durability = stack.getDurability(); this.data = stack.getData(); if (stack.hasItemMeta()) { setItemMeta0(stack.getItemMeta(), getType0()); } }
@Override public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) { GlowBlockState state = block.getState(); MaterialData data = state.getData(); if (!(data instanceof FlowerPot)) { warnMaterialData(FlowerPot.class, data); return false; } if (state instanceof GlowFlowerPot) { GlowFlowerPot pot = (GlowFlowerPot) state; ItemStack heldItem = player.getItemInHand(); // Only change contents if there is none and if the held item is valid pot contents. if (pot.getContents() == null && heldItem != null && isValidContents( heldItem.getData())) { pot.setContents(heldItem.getData().clone()); // Null-check in isValidContents. return pot.update(); } } return false; }
@Override @Deprecated public int clear(int id, int data) { int numCleared = 0; for (int i = 0; i < getSize(); ++i) { ItemStack stack = getItem(i); if (stack != null && (id == -1 || stack.getTypeId() == id) && (data == -1 || stack.getData().getData() == data)) { setItem(i, InventoryUtil.createEmptyStack()); if (!InventoryUtil.isEmpty(stack)) { // never report AIR as removed - else will report all empty slots cleared numCleared += stack.getAmount(); // report # items, not # stacks removed } } } return numCleared; }
Color color = ((Dye) item.getData()).getColor().getColor(); colors.add(color); continue;
if (blockType == Material.STEP) { state.setType(Material.DOUBLE_STEP); state.setData(holding.getData()); return; } else if (blockType == Material.WOOD_STEP) { state.setType(Material.WOOD_DOUBLE_STEP); state.setData(holding.getData()); return; } else if (blockType == Material.STONE_SLAB2) { state.setType(Material.DOUBLE_STONE_SLAB2); state.setData(holding.getData()); return; } else if (blockType == Material.PURPUR_SLAB) { state.setType(Material.PURPUR_DOUBLE_SLAB); state.setData(holding.getData()); return;
/** * Remove all matching items from the inventory. * * @param type the item to remove, or null to remove everything * @param data the data value to match on, or null to match all data values * @return the number of items (not stacks) removed */ public int clear(Material type, MaterialData data) { if (type == Material.AIR) { return 0; } int numCleared = 0; for (int i = 0; i < getSize(); ++i) { ItemStack stack = getItem(i); if (stack != null && (type == null || stack.getType() == type) && (data == null || stack .getData().equals(data))) { setItem(i, InventoryUtil.createEmptyStack()); if (!InventoryUtil.isEmpty(stack)) { // never report AIR as removed - else will report all empty slots cleared numCleared += stack.getAmount(); // report # items, not # stacks removed } } } return numCleared; }
@Override public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) { if (block.getType() == Material.BED_BLOCK) { GlowBed bed = (GlowBed) block.getState(); bed.setColor(DyeColor.getByWoolData(holding.getData().getData())); bed.update(true); BlockFace direction = ((Bed) bed.getData()).getFacing(); GlowBlock headBlock = block.getRelative(direction); headBlock.setType(Material.BED_BLOCK); GlowBed headBlockState = (GlowBed) headBlock.getState(); headBlockState.setColor(DyeColor.getByWoolData(holding.getData().getData())); MaterialData data = headBlockState.getData(); ((Bed) data).setHeadOfBed(true); ((Bed) data).setFacingDirection(direction); headBlockState.setData(data); headBlockState.update(true); } }
@Override public boolean eat(GlowPlayer player, ItemStack item) { if (!super.eat(player, item)) { return false; } if (item.getData().getData() == 3) { player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, TickUtil.minutesToTicks(1), 3), true); player.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, TickUtil.secondsToTicks(15), 2), true); player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, TickUtil.secondsToTicks(15), 1), true); } return true; }
Dye dye = (Dye) item.getData(); colors.add(dye.getColor().getFireworkColor()); break;
Dye dye = (Dye) hand.getData(); DyeColor color = dye.getColor(); setCollarColor(color);
MaterialData data = holding.getData(); if (!(data instanceof Sponge)) { warnMaterialData(Sponge.class, data);
@Override public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc, EquipmentSlot hand) { MaterialData data = holding.getData(); if (data instanceof Dye) { Dye dye = (Dye) data;
@Override public boolean eat(GlowPlayer player, ItemStack item) { if (!super.eat(player, item)) { return false; } byte data = item.getData().getData(); if (data == 0) { player.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, TickUtil.minutesToTicks(2), 0), true); player .addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, TickUtil.secondsToTicks(5), 1), true); } else if (data == 1) { player.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, TickUtil.minutesToTicks(2), 3),true); player .addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, TickUtil.secondsToTicks(20), 1), true); player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, TickUtil.minutesToTicks(5), 0), true); player .addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, TickUtil.minutesToTicks(5), 0),true); } return true; } }