Java Code Examples for net.minecraft.item.ItemStack#getDamage()

The following examples show how to use net.minecraft.item.ItemStack#getDamage() . 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: BatteryItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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 2
Source File: RenderUtilsLiving.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
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()), Type.GUI);
    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 3
Source File: RenderUtilsLiving.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
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 4
Source File: RenderUtilsLiving.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
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 5
Source File: InventoryUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean areStacksIdentical(@Nonnull ItemStack stack1, @Nonnull ItemStack stack2) {
    if (stack1.isEmpty() || stack2.isEmpty()) {
        return stack1 == stack2;
    }

    return stack1.getItem() == stack2.getItem() && stack1.getDamage() == stack2.getDamage() && stack1.getCount() == stack2.getCount() && Objects.equal(stack1.getTag(), stack2.getTag());
}
 
Example 6
Source File: AutoToolHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private boolean isTooDamaged(ItemStack stack)
{
	return stack.getMaxDamage() - stack.getDamage() <= 4;
}
 
Example 7
Source File: InventoryUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static boolean canStack(@Nonnull ItemStack stack1, @Nonnull ItemStack stack2) {
    return stack1.isEmpty() || stack2.isEmpty() || (stack1.getItem() == stack2.getItem() && (stack2.getDamage() == stack1.getDamage()) && ItemStack.areItemStackTagsEqual(stack2, stack1)) && stack1.isStackable();
}
 
Example 8
Source File: IForgeItem.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Queries the percentage of the 'Durability' bar that should be drawn.
 *
 * @param stack The current ItemStack
 * @return 0.0 for 100% (no damage / full bar), 1.0 for 0% (fully damaged /
 * empty bar)
 */
default double getDurabilityForDisplay(ItemStack stack) {
	return (double) stack.getDamage() / (double) stack.getMaxDamage();
}
 
Example 9
Source File: IForgeItem.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Return if this itemstack is damaged. Note only called if
 * {@link Item#isDamageable()} is true.
 *
 * @param stack the stack
 * @return if the stack is damaged
 */
default boolean isDamaged(ItemStack stack) {
	return stack.getDamage() > 0;
}
 
Example 10
Source File: IForgeItem.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Called when the player is mining a block and the item in his hand changes.
 * Allows to not reset block breaking if only NBT or similar changes.
 *
 * @param oldStack The old stack that was used for mining. Item in players main
 *                 hand
 * @param newStack The new stack
 * @return True to reset block break progress
 */
default boolean shouldCauseBlockBreakReset(ItemStack oldStack, ItemStack newStack) {
	return !(newStack.getItem() == oldStack.getItem() && ItemStack.areTagsEqual(newStack, oldStack)
		&& (newStack.isDamageable() || newStack.getDamage() == oldStack.getDamage()));
}
 
Example 11
Source File: ItemUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Compares an ItemStack, Useful for comparators.
 *
 * @param stack1 First Stack.
 * @param stack2 Second Stack.
 * @return Returns the difference.
 */
public static int compareItemStack(@Nonnull ItemStack stack1, @Nonnull ItemStack stack2) {
    int itemStack1ID = Item.getIdFromItem(stack1.getItem());
    int itemStack2ID = Item.getIdFromItem(stack1.getItem());
    return itemStack1ID != itemStack2ID ? itemStack1ID - itemStack2ID : (stack1.getDamage() == stack2.getDamage() ? 0 : stack1.getDamage() - stack2.getDamage());
}
 
Example 12
Source File: ItemUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * @param stack1 The {@link ItemStack} being compared.
 * @param stack2 The {@link ItemStack} to compare to.
 * @return whether the two items are the same in terms of damage and itemID.
 */
public static boolean areStacksSameType(@Nonnull ItemStack stack1, @Nonnull ItemStack stack2) {
    return !stack1.isEmpty() && !stack2.isEmpty() && (stack1.getItem() == stack2.getItem() && (stack2.getDamage() == stack1.getDamage()) && ItemStack.areItemStackTagsEqual(stack2, stack1));
}