Java Code Examples for net.minecraft.item.ItemStack#isItemStackDamageable()
The following examples show how to use
net.minecraft.item.ItemStack#isItemStackDamageable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GTUtility.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
/** * Applies specific amount of damage to item, either to durable items (which implement IDamagableItem) * or to electric items, which have capability IElectricItem * Damage amount is equal to EU amount used for electric items * * @return if damage was applied successfully */ //TODO get rid of that public static boolean doDamageItem(ItemStack itemStack, int vanillaDamage, boolean simulate) { Item item = itemStack.getItem(); if (item instanceof IToolItem) { //if item implements IDamagableItem, it manages it's own durability itself IToolItem damagableItem = (IToolItem) item; return damagableItem.damageItem(itemStack, vanillaDamage, simulate); } else if (itemStack.hasCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null)) { //if we're using electric item, use default energy multiplier for textures IElectricItem capability = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null); int energyNeeded = vanillaDamage * ConfigHolder.energyUsageMultiplier; //noinspection ConstantConditions return capability.discharge(energyNeeded, Integer.MAX_VALUE, true, false, simulate) == energyNeeded; } else if (itemStack.isItemStackDamageable()) { if (!simulate && itemStack.attemptDamageItem(vanillaDamage, new Random(), null)) { //if we can't accept more damage, just shrink stack and mark it as broken //actually we would play broken animation here, but we don't have an entity who holds item itemStack.shrink(1); } return true; } return false; }
Example 2
Source File: ItemUtils.java From TofuCraftReload with MIT License | 5 votes |
public static void damageItemStack(ItemStack stack, int amount) { if (stack.isItemStackDamageable()) { stack.setItemDamage(stack.getItemDamage() + amount); if (stack.getItemDamage() > stack.getMaxDamage()) { stack.shrink(1); } } }
Example 3
Source File: MetaTileEntityWorkbench.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Nonnull @Override public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { if (!(stack.getItem() instanceof ToolMetaItem) && !(stack.getItem() instanceof ItemTool) && !(stack.isItemStackDamageable())) { return stack; } return super.insertItem(slot, stack, simulate); }
Example 4
Source File: GTTileAutocrafter.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
public void tryToDamageItems(ItemStack stack) { if (stack.isItemStackDamageable()) { if (this.isRendering()) { stack.attemptDamageItem(1, this.world.rand, null); } } }
Example 5
Source File: ThaumcraftApiHelper.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 5 votes |
public static boolean areItemsEqual(ItemStack s1,ItemStack s2) { if (s1.isItemStackDamageable() && s2.isItemStackDamageable()) { return s1.getItem() == s2.getItem(); } else return s1.getItem() == s2.getItem() && s1.getItemDamage() == s2.getItemDamage(); }
Example 6
Source File: DataManager.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
public static void setHeldItemAsTool() { EntityPlayer player = Minecraft.getMinecraft().player; if (player != null) { ItemStack stack = player.getHeldItemMainhand(); toolItem = stack.isEmpty() ? ItemStack.EMPTY : stack.copy(); String cfgStr = ""; if (stack.isEmpty() == false) { cfgStr = Item.REGISTRY.getNameForObject(stack.getItem()).toString(); NBTTagCompound nbt = stack.getTagCompound(); if (stack.isItemStackDamageable() == false || nbt != null) { cfgStr += "@" + stack.getMetadata(); if (nbt != null) { cfgStr += nbt.toString(); } } } Configs.Generic.TOOL_ITEM.setValueFromString(cfgStr); InfoUtils.printActionbarMessage("litematica.message.set_currently_held_item_as_tool"); } }
Example 7
Source File: ItemNullifier.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean isItemValidForSlot(int slot, ItemStack stack) { // Only allow in stackable, non-damageable items, so that there hopefully // won't be many issues with item usage not consuming the item or changing it... return stack.isEmpty() == false && stack.getMaxStackSize() > 1 && stack.isItemStackDamageable() == false; }
Example 8
Source File: Schematic.java From Framez with GNU General Public License v3.0 | 5 votes |
/** * This is called each time an item matches a requirement. By default, it * will increase damage of items that can be damaged by the amount of the * requirement, and remove the intended amount of items that can't be * damaged. * * Client may override this behavior. Note that this subprogram may be * called twice with the same parameters, once with a copy of requirements * and stack to check if the entire requirements can be fulfilled, and once * with the real inventory. Implementer is responsible for updating req * (with the remaining requirements if any) and slot (after usage). * * returns what was used (similar to req, but created from slot, so that any * NBT based differences are drawn from the correct source) */ public ItemStack useItem(IBuilderContext context, ItemStack req, IInvSlot slot) { ItemStack stack = slot.getStackInSlot(); ItemStack result = stack.copy(); if (stack.isItemStackDamageable()) { if (req.getItemDamage() + stack.getItemDamage() <= stack.getMaxDamage()) { stack.setItemDamage(req.getItemDamage() + stack.getItemDamage()); result.setItemDamage(req.getItemDamage()); req.stackSize = 0; } if (stack.getItemDamage() >= stack.getMaxDamage()) { slot.decreaseStackInSlot(1); } } else { if (stack.stackSize >= req.stackSize) { result.stackSize = req.stackSize; stack.stackSize -= req.stackSize; req.stackSize = 0; } else { req.stackSize -= stack.stackSize; stack.stackSize = 0; } } if (stack.stackSize == 0 && stack.getItem().getContainerItem() != null) { Item container = stack.getItem().getContainerItem(); ItemStack newStack = new ItemStack(container); slot.setStackInSlot(newStack); } else if (stack.stackSize == 0) { slot.setStackInSlot(null); } return result; }
Example 9
Source File: ItemBlueprint.java From Cyberware with MIT License | 5 votes |
public static ItemStack getBlueprintForItem(ItemStack stack) { if (stack != null && CyberwareAPI.canDeconstruct(stack)) { ItemStack toBlue = stack.copy(); toBlue.stackSize = 1; if (toBlue.isItemStackDamageable()) { toBlue.setItemDamage(0); } toBlue.setTagCompound(null); ItemStack ret = new ItemStack(CyberwareContent.blueprint); NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound itemTag = new NBTTagCompound(); toBlue.writeToNBT(itemTag); tag.setTag("blueprintItem", itemTag); ret.setTagCompound(tag); return ret; } else { return null; } }
Example 10
Source File: AdapterArcaneBore.java From OpenPeripheral-Integration with MIT License | 5 votes |
@Asynchronous(false) @ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Is the Arcane bore active?") public boolean isWorking(Object target) { ItemStack pick = getPick(target); Boolean hasPower = GETTING_POWER.call(target); return hasPower && hasFocus(target) && hasPickaxe(target) && pick.isItemStackDamageable() && !isPickaxeBroken(target); }
Example 11
Source File: ThaumcraftApiHelper.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
public static boolean areItemsEqual(ItemStack s1,ItemStack s2) { if (s1.isItemStackDamageable() && s2.isItemStackDamageable()) { return s1.getItem() == s2.getItem(); } else return s1.getItem() == s2.getItem() && s1.getItemDamage() == s2.getItemDamage(); }
Example 12
Source File: SlotPottery.java From GardenCollection with MIT License | 5 votes |
@Override public void onPickupFromSlot (EntityPlayer player, ItemStack itemStack) { FMLCommonHandler.instance().firePlayerCraftingEvent(player, itemStack, inputInventory); onCrafting(itemStack); ItemStack itemTarget = inputInventory.getStackInSlot(1); if (itemTarget != null) { inputInventory.decrStackSize(1, 1); if (itemTarget.getItem().hasContainerItem(itemTarget)) { ItemStack itemContainer = itemTarget.getItem().getContainerItem(itemTarget); if (itemContainer != null && itemContainer.isItemStackDamageable() && itemContainer.getItemDamage() > itemContainer.getMaxDamage()) { MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(this.player, itemContainer)); return; } if (!itemTarget.getItem().doesContainerItemLeaveCraftingGrid(itemTarget) || !this.player.inventory.addItemStackToInventory(itemContainer)) { if (inputInventory.getStackInSlot(1) == null) inputInventory.setInventorySlotContents(1, itemContainer); else this.player.dropPlayerItemWithRandomChoice(itemContainer, false); } } } ItemStack itemPattern = inputInventory.getStackInSlot(0); if (itemPattern != null && itemPattern.getItem() == Items.dye) { inputInventory.decrStackSize(0, 1); } }
Example 13
Source File: LexiconRecipeMappings.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 4 votes |
public static boolean ignoreMeta(ItemStack stack) { return stack.isItemStackDamageable() || stack.getItem() instanceof IManaItem; }
Example 14
Source File: InfiniteStackSizeHandler.java From NotEnoughItems with MIT License | 4 votes |
@Override public boolean canHandleItem(ItemStack stack) { return !stack.isItemStackDamageable(); }
Example 15
Source File: ForgePlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public BaseBlock getBlockInHand() { ItemStack is = this.player.getHeldItem(EnumHand.MAIN_HAND); return is == null ? EditSession.nullBlock : new BaseBlock(Item.getIdFromItem(is.getItem()), is.isItemStackDamageable() ? 0 : is.getItemDamage()); }
Example 16
Source File: ForgePlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public BaseBlock getBlockInHand() { ItemStack is = this.player.getHeldItem(EnumHand.MAIN_HAND); return is == null ? EditSession.nullBlock : new BaseBlock(Item.getIdFromItem(is.getItem()), is.isItemStackDamageable() ? 0 : is.getItemDamage()); }
Example 17
Source File: ForgePlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public BaseBlock getBlockInHand() { ItemStack is = this.player.getCurrentEquippedItem(); return is == null ? EditSession.nullBlock : new BaseBlock(Item.getIdFromItem(is.getItem()), is.isItemStackDamageable() ? 0 : is.getItemDamage()); }
Example 18
Source File: HackableLivingDisarm.java From PneumaticCraft with GNU General Public License v3.0 | 4 votes |
@Override public void onHackFinished(Entity entity, EntityPlayer player){ if(!entity.worldObj.isRemote) { Random rand = new Random(); if(fieldDropChance == null) { fieldDropChance = ReflectionHelper.findField(EntityLiving.class, "field_82174_bp", "equipmentDropChances"); } try { float[] equipmentDropChances = (float[])fieldDropChance.get(entity); for(int i = 0; i < ((EntityLiving)entity).getLastActiveItems().length; i++) { ItemStack stack = ((EntityLiving)entity).getLastActiveItems()[i]; float equipmentDropChance = equipmentDropChances[i]; boolean flag1 = equipmentDropChance > 1.0F; if(stack != null && rand.nextFloat() < equipmentDropChance) { if(!flag1 && stack.isItemStackDamageable()) { int k = Math.max(stack.getMaxDamage() - 25, 1); int l = stack.getMaxDamage() - rand.nextInt(rand.nextInt(k) + 1); if(l > k) { l = k; } if(l < 1) { l = 1; } stack.setItemDamage(l); } entity.entityDropItem(stack, 0.0F); } ((EntityLiving)entity).setCurrentItemOrArmor(i, null); } ((EntityLiving)entity).setCanPickUpLoot(false); } catch(Exception e) { Log.error("Reflection failed on HackableLivingDisarm"); e.printStackTrace(); } } }
Example 19
Source File: InfiniteStackSizeHandler.java From NotEnoughItems with MIT License | 4 votes |
@Override public boolean canHandleItem(ItemStack stack) { return !stack.isItemStackDamageable(); }
Example 20
Source File: GTTileDisassembler.java From GT-Classic with GNU Lesser General Public License v3.0 | 4 votes |
public static boolean canItemBeReturned(ItemStack stack) { return !GTHelperStack.isEqual(stack, Ic2Items.uuMatter.copy()) && !stack.isItemStackDamageable() && !stack.getUnlocalizedName().contains("bucket"); }