Java Code Examples for net.minecraft.item.ItemStack#getMaxDamage()
The following examples show how to use
net.minecraft.item.ItemStack#getMaxDamage() .
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: ProxyCommon.java From WearableBackpacks with MIT License | 5 votes |
/** Called when a mob spawns with a backpack with a 1 tick delay. */ private void onSpawnedWith(EntityLivingBase entity, BackpackCapability backpack, BackpackEntry entry) { ItemStack stack = new ItemStack(entry.getBackpackItem()); if (entry.colorRange != null) // Set a random color! NbtUtils.set(stack, entry.colorRange.getRandom(), "display", "color"); // Set damage to a random amount (25% - 75%). int maxDamage = stack.getMaxDamage(); int damage = maxDamage / 4 + ((maxDamage / 2 > 0) ? entity.world.rand.nextInt(maxDamage / 2) : 0); stack.setItemDamage(damage); if (BackpackHelper.equipAsChestArmor) { // If the entity spawned with enchanted armor, // then move over all compatible enchantments. ItemStack armor = entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST); if ((armor != null) && armor.isItemEnchanted()) { NBTTagList enchList = armor.getEnchantmentTagList(); for (int i = 0; i < enchList.tagCount(); ++i) { NBTTagCompound enchTag = enchList.getCompoundTagAt(i); Enchantment enchantment = Enchantment.getEnchantmentByID(enchTag.getShort("id")); // If the enchantment doesn't work with the backpack, remove it. if (!enchantment.canApply(stack)) enchList.removeTag(i--); } if (enchList.tagCount() > 0) NbtUtils.set(stack, enchList, "ench"); } } IBackpackType type = entry.getBackpackItem(); IBackpackData data = type.createBackpackData(stack); BackpackHelper.setEquippedBackpack(entity, stack, data); type.onSpawnedWith(entity, backpack, entry.lootTable); backpack.spawnWith = null; backpack.mayDespawn = true; }
Example 2
Source File: ItemHexxitArmor.java From HexxitGear with GNU General Public License v3.0 | 5 votes |
@Override public void damageArmor(EntityLiving entity, ItemStack stack, DamageSource source, int damage, int slot) { if (entity instanceof EntityPlayer && !(((EntityPlayer) entity).capabilities.isCreativeMode)) { if (stack.getItemDamage() < stack.getMaxDamage()) { stack.setItemDamage(stack.getItemDamage() + 1); } else { // Create broken item here } } }
Example 3
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 4
Source File: ElementRenderer.java From Hyperium with GNU Lesser General Public License v3.0 | 5 votes |
public static void render(List<ItemStack> itemStacks, int x, double y, boolean showDurability) { GlStateManager.pushMatrix(); int line = 0; RenderItem renderItem = Minecraft.getMinecraft().getRenderItem(); for (ItemStack stack : itemStacks) { if (stack.getMaxDamage() == 0) continue; String dur = stack.getMaxDamage() - stack.getItemDamage() + ""; renderItem.renderItemAndEffectIntoGUI(stack, (int) (x / ElementRenderer.getCurrentScale() - (current.isRightSided() ? (showDurability ? currentScale + fontRendererObj.getStringWidth(dur) : -8) : 0)), (int) ((y + (16 * line * ElementRenderer.getCurrentScale())) / ElementRenderer.getCurrentScale())); if (showDurability) ElementRenderer.draw((int) (x + (double) 20 * currentScale), y + (16 * line) + 4, dur); line++; } GlStateManager.popMatrix(); }
Example 5
Source File: EventHandlers.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@SubscribeEvent public static void onPlayerInteraction(PlayerInteractEvent.RightClickBlock event) { ItemStack stack = event.getItemStack(); if (!stack.isEmpty() && stack.getItem() == Items.FLINT_AND_STEEL) { if (!event.getWorld().isRemote && !event.getEntityPlayer().capabilities.isCreativeMode && event.getWorld().rand.nextInt(100) >= ConfigHolder.flintChanceToCreateFire) { stack.damageItem(1, event.getEntityPlayer()); if (stack.getItemDamage() >= stack.getMaxDamage()) { stack.shrink(1); } event.setCanceled(true); } } }
Example 6
Source File: RenderUtilsLiving.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
public static void drawItem(double x, double y, double z, double offX, double offY, double scale, ItemStack item) { glSetup(x, y, z); GL11.glScaled(0.4*scale, 0.4*scale, 0); GL11.glTranslated(offX, offY, 0); if (item.getItem() instanceof BlockItem) GL11.glRotatef(180F, 1F, 180F, 10F); mc.getItemRenderer().renderItem(new ItemStack( item.getItem()), Mode.GUI, 0, 0, new MatrixStack(), mc.getBufferBuilders().getEntityVertexConsumers()); if (item.getItem() instanceof BlockItem) GL11.glRotatef(-180F, -1F, -180F, -10F); GL11.glDisable(GL11.GL_LIGHTING); GL11.glScalef(-0.05F, -0.05F, 0); if (item.getCount() > 0) { int w = mc.textRenderer.getStringWidth("x" + item.getCount()) / 2; mc.textRenderer.drawWithShadow("x" + item.getCount(), 7 - w, 5, 0xffffff); } GL11.glScalef(0.85F, 0.85F, 0.85F); int c = 0; for (Entry<Enchantment, Integer> m: EnchantmentHelper.getEnchantments(item).entrySet()) { int w1 = mc.textRenderer.getStringWidth(I18n.translate(m.getKey().getName(2).asString()).substring(0, 2) + m.getValue()) / 2; mc.textRenderer.drawWithShadow( I18n.translate(m.getKey().getName(2).asString()).substring(0, 2) + m.getValue(), -4 - w1, c*10-1, m.getKey() == Enchantments.VANISHING_CURSE || m.getKey() == Enchantments.BINDING_CURSE ? 0xff5050 : 0xffb0e0); c--; } GL11.glScalef(0.6F, 0.6F, 0.6F); String dur = item.getMaxDamage() - item.getDamage() + ""; int color = 0x000000; try{ color = MathHelper.hsvToRgb(((float) (item.getMaxDamage() - item.getDamage()) / item.getMaxDamage()) / 3.0F, 1.0F, 1.0F); } catch (Exception e) {} if (item.isDamageable()) mc.textRenderer.drawWithShadow(dur, -8 - dur.length() * 3, 15, new Color(color >> 16 & 255, color >> 8 & 255, color & 255).getRGB()); glCleanup(); }
Example 7
Source File: RenderUtilsLiving.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
public static void drawItem(double x, double y, double z, double offX, double offY, double scale, ItemStack item) { glSetup(x, y, z); GL11.glScaled(0.4*scale, 0.4*scale, 0); GL11.glTranslated(offX, offY, 0); if (item.getItem() instanceof BlockItem) GL11.glRotatef(180F, 1F, 180F, 10F); mc.getItemRenderer().renderItem(new ItemStack( item.getItem()), Mode.GUI, 0, 0, new MatrixStack(), mc.getBufferBuilders().getEntityVertexConsumers()); if (item.getItem() instanceof BlockItem) GL11.glRotatef(-180F, -1F, -180F, -10F); GL11.glDisable(GL11.GL_LIGHTING); GL11.glScalef(-0.05F, -0.05F, 0); if (item.getCount() > 0) { int w = mc.textRenderer.getWidth("x" + item.getCount()) / 2; mc.textRenderer.drawWithShadow(new MatrixStack(), "x" + item.getCount(), 7 - w, 5, 0xffffff); } GL11.glScalef(0.85F, 0.85F, 0.85F); int c = 0; for (Entry<Enchantment, Integer> m: EnchantmentHelper.get(item).entrySet()) { int w1 = mc.textRenderer.getWidth(I18n.translate(m.getKey().getName(2).asString()).substring(0, 2) + m.getValue()) / 2; mc.textRenderer.drawWithShadow(new MatrixStack(), I18n.translate(m.getKey().getName(2).asString()).substring(0, 2) + m.getValue(), -4 - w1, c*10-1, m.getKey() == Enchantments.VANISHING_CURSE || m.getKey() == Enchantments.BINDING_CURSE ? 0xff5050 : 0xffb0e0); c--; } GL11.glScalef(0.6F, 0.6F, 0.6F); String dur = item.getMaxDamage() - item.getDamage() + ""; int color = 0x000000; try{ color = MathHelper.hsvToRgb(((float) (item.getMaxDamage() - item.getDamage()) / item.getMaxDamage()) / 3.0F, 1.0F, 1.0F); } catch (Exception e) {} if (item.isDamageable()) mc.textRenderer.drawWithShadow(new MatrixStack(), dur, -8 - dur.length() * 3, 15, new Color(color >> 16 & 255, color >> 8 & 255, color & 255).getRGB()); glCleanup(); }
Example 8
Source File: EntityBas.java From ToroQuest with GNU General Public License v3.0 | 5 votes |
public void onLivingUpdate() { super.onLivingUpdate(); if (world.getTotalWorldTime() % 100 == 0) { spawnLimitedBats(); } if (this.world.isDaytime() && !this.world.isRemote) { float f = this.getBrightness(); BlockPos blockpos = this.getRidingEntity() instanceof EntityBoat ? (new BlockPos(this.posX, (double) Math.round(this.posY), this.posZ)).up() : new BlockPos(this.posX, (double) Math.round(this.posY), this.posZ); if (f > 0.5F && this.rand.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && this.world.canSeeSky(blockpos)) { boolean flag = true; ItemStack itemstack = this.getItemStackFromSlot(EntityEquipmentSlot.HEAD); if (!itemstack.isEmpty()) { if (itemstack.isItemStackDamageable()) { itemstack.setItemDamage(itemstack.getItemDamage() + this.rand.nextInt(2)); if (itemstack.getItemDamage() >= itemstack.getMaxDamage()) { this.renderBrokenItemStack(itemstack); this.setItemStackToSlot(EntityEquipmentSlot.HEAD, ItemStack.EMPTY); } } flag = false; } if (flag) { this.setFire(8); } } } }
Example 9
Source File: TileCO2Scrubber.java From AdvancedRocketry with MIT License | 5 votes |
public boolean useCharge() { ItemStack stack = getStackInSlot(0); if(stack != null && stack.getItem() == AdvancedRocketryItems.itemCarbonScrubberCartridge) { if(stack.getItemDamage() != stack.getMaxDamage()) { stack.setItemDamage(stack.getItemDamage() + 1); //this.markDirty(); return true; } } return false; }
Example 10
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 11
Source File: ItemFukumame.java From TofuCraftReload with MIT License | 5 votes |
@Override public ItemStack dispenseStack(IBlockSource source, ItemStack stack) { if (stack.getItemDamage() >= stack.getMaxDamage()) return stack; EnumFacing enumfacing = source.getBlockState().getValue(BlockDispenser.FACING); // getFacing World world = source.getWorld(); double d0 = source.getX() + (double) ((float) enumfacing.getFrontOffsetX() * 1.125F); double d1 = source.getY() + (double) ((float) enumfacing.getFrontOffsetY() * 1.125F); double d2 = source.getZ() + (double) ((float) enumfacing.getFrontOffsetZ() * 1.125F); for (int i = 0; i < 8; i++) { EntityFukumame fukumame = new EntityFukumame(world, d0, d1, d2); fukumame.shoot(enumfacing.getFrontOffsetX(), (enumfacing.getFrontOffsetY()), enumfacing.getFrontOffsetZ(), this.getProjectileVelocity(), this.getProjectileInaccuracy()); applyEffect(fukumame, stack); if (!world.isRemote) { world.spawnEntity(fukumame); } } if (stack.isItemStackDamageable()) { stack.getItem(); stack.attemptDamageItem(1, Item.itemRand, null); } source.getWorld().playEvent(1000, source.getBlockPos(), 0); return stack; }
Example 12
Source File: BatteryItem.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override @Environment(EnvType.CLIENT) public void appendTooltip(ItemStack stack, World world, List<Text> lines, TooltipContext context) { int charge = stack.getOrCreateTag().getInt("Energy"); if (stack.getMaxDamage() - stack.getDamage() < 3334) { lines.add(new TranslatableText("tooltip.galacticraft-rewoven.energy-remaining", charge).setStyle(Style.EMPTY.withColor(Formatting.DARK_RED))); } else if (stack.getMaxDamage() - stack.getDamage() < 6667) { lines.add(new TranslatableText("tooltip.galacticraft-rewoven.energy-remaining", charge).setStyle(Style.EMPTY.withColor(Formatting.GOLD))); } else { lines.add(new TranslatableText("tooltip.galacticraft-rewoven.energy-remaining", charge).setStyle(Style.EMPTY.withColor(Formatting.GREEN))); } super.appendTooltip(stack, world, lines, context); }
Example 13
Source File: AutoToolHack.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
private boolean isTooDamaged(ItemStack stack) { return stack.getMaxDamage() - stack.getDamage() <= 4; }
Example 14
Source File: ItemHexxitArmor.java From HexxitGear with GNU General Public License v3.0 | 4 votes |
@Override public ArmorProperties getProperties(EntityLiving player, ItemStack armor, DamageSource source, double damage, int slot) { return new ArmorProperties(1, damageReduceAmount / 22D, armor.getMaxDamage() + 1); }
Example 15
Source File: BlockLogNatural2.java From TFC2 with GNU General Public License v3.0 | 4 votes |
@Override public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) { if(world.isRemote) return true; //get our item parameters ItemStack stack = player.getHeldItemMainhand(); int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack); int maxCut = 0; if(stack.getItem() instanceof ItemAxe) { maxCut = ((ItemAxe)stack.getItem()).maxTreeSize; } else return false; //create the map of our tree BlockPosList tree = BlockLogNatural.getTreeForCut(world, pos); int count = tree.size(); //if the tree has too many blocks then prevent chopping if(count > maxCut) { player.sendMessage(new TextComponentTranslation(Core.translate("gui.axe.treetoobig"))); return false; } else if(count > stack.getMaxDamage() - stack.getItemDamage()) { player.sendMessage(new TextComponentTranslation(Core.translate("gui.axe.needsrepair"))); return false; } else { for(BlockPos p : tree) { IBlockState s = world.getBlockState(p); this.onBlockHarvested(world, pos, s, player); world.setBlockToAir(p); s.getBlock().dropBlockAsItem(world, p, s, fortune); } } stack.damageItem(count-1, player); return true; }
Example 16
Source File: AutoToolHack.java From ForgeWurst with GNU General Public License v3.0 | 4 votes |
private boolean isTooDamaged(ItemStack stack, boolean repairMode) { return repairMode && stack.getMaxDamage() - stack.getItemDamage() <= 4; }
Example 17
Source File: ItemFirestarter.java From TFC2 with GNU General Public License v3.0 | 4 votes |
@Override public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) { World world = player.world; int duration = getMaxItemUseDuration(stack) - count; int chance = getMaxItemUseDuration(stack) - duration; int rand = world.rand.nextInt(chance); BlockPos pos = null; RayTraceResult result = rayTrace(player, 3, 0); if(result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) { pos = result.getBlockPos(); } else return; if(!world.isRemote) { if(count < 200) return; if(count % 10 == 1) world.playSound(null, pos, TFC_Sounds.FIRESTARTER, SoundCategory.BLOCKS, 1.0f, 1.0f); if(rand < 20 && pos != null) onUse(world, player, stack, pos, count); if(stack.getItemDamage()+duration > stack.getMaxDamage()) { stack.damageItem(duration, player); player.stopActiveHand(); } } else { if(count > 0 ) world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, pos.getX()+world.rand.nextDouble(), pos.getY()+1, pos.getZ()+world.rand.nextDouble(), 0, 0.01, 0); } }
Example 18
Source File: ItemTofuForceSword.java From TofuCraftReload with MIT License | 4 votes |
public static boolean isUsable(ItemStack stack) { return stack.getItemDamage() <= stack.getMaxDamage(); }
Example 19
Source File: AdapterArcaneBore.java From OpenPeripheral-Integration with MIT License | 4 votes |
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Is the pick broken?") public boolean isPickaxeBroken(Object target) { ItemStack pick = getPick(target); return pick != null && pick.getItemDamage() + 1 == pick.getMaxDamage(); }
Example 20
Source File: EventHandler.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
@SubscribeEvent(priority = EventPriority.HIGHEST) public void playerTick(TickEvent.PlayerTickEvent event) { //Leaving the underowrld if (event.player.getEntityWorld().provider.getDimension() == Wizardry.underWorld.getId()) { if (event.player.posY < 0) { //Gets the players spwanpoint and sets the location to teleport to around that event.player.isDead = false; BlockPos spawn = event.player.isSpawnForced(0) ? event.player.getBedLocation(0) : event.player.world.getSpawnPoint().add(event.player.world.rand.nextGaussian() * 16, 0, event.player.world.rand.nextGaussian() * 16); BlockPos teleportTo = spawn.add(0, 300 - spawn.getY(), 0); //stops fall damage fallResetter.add(event.player.getUniqueID()); TeleportUtil.teleportToDimension(event.player, 0, teleportTo.getX(), teleportTo.getY(), teleportTo.getZ()); } } //adds pass to check if player on bedrock after reached velocity if (event.player.getEntityWorld().provider.getDimension() == 0 && ConfigValues.underworldFallSpeed <= 0) { if (event.player.motionY < ConfigValues.underworldFallSpeed || passmap.get(event.player.getEntityId()) != null) { passmap.put(event.player.getEntityId(), true); BlockPos location = event.player.getPosition(); BlockPos bedrock = PosUtils.checkNeighborBlocksThoroughly(event.player.getEntityWorld(), location, Blocks.BEDROCK); if (bedrock != null) { event.player.isDead = false; fallResetter.add(event.player.getUniqueID()); TeleportUtil.teleportToDimension(event.player, Wizardry.underWorld.getId(), 0, 300, 0); passmap.remove(event.player.getEntityId()); } else if (event.player.motionY > ConfigValues.underworldFallSpeed) {//resets pass if stopped falling or slowed down alot passmap.remove(event.player.getEntityId()); } } } if (!event.player.world.isRemote) { for (ItemStack stack : event.player.inventory.mainInventory) { if (stack.getItem() == ModItems.LEVITATION_ORB) { if (stack.getItemDamage() + 1 > stack.getMaxDamage()) { stack.shrink(1); continue; } if (event.player.world.getTotalWorldTime() % 10 == 0) stack.setItemDamage(stack.getItemDamage() + 1); if (!event.player.isPotionActive(ModPotions.LOW_GRAVITY)) { event.player.addPotionEffect(new PotionEffect(ModPotions.LOW_GRAVITY, 3, 3, false, false)); } break; } } } }