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

The following examples show how to use net.minecraft.item.ItemStack#setDamage() . 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: RepairCmd.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void call(String[] args) throws CmdException
{
	if(args.length > 0)
		throw new CmdSyntaxError();
	
	ClientPlayerEntity player = MC.player;
	
	if(!player.abilities.creativeMode)
		throw new CmdError("Creative mode only.");
	
	ItemStack stack = getHeldStack(player);
	stack.setDamage(0);
	MC.player.networkHandler
		.sendPacket(new CreativeInventoryActionC2SPacket(
			36 + player.inventory.selectedSlot, stack));
	
	ChatUtils.message("Item repaired.");
}
 
Example 2
Source File: OxygenTankItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private ItemStack applyDefaultTags(ItemStack item, int currentOxy) {
    CompoundTag tag = item.getOrCreateTag();
    tag.putInt(MAX_OXYGEN_NBT_KEY, this.maxOxygen);
    tag.putInt(OXYGEN_NBT_KEY, currentOxy);
    item.setDamage(getMaxDamage() - currentOxy);

    return item;
}
 
Example 3
Source File: BatteryItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> groupStacks) {
    if (this.isIn(group)) {
        ItemStack charged = new ItemStack(this);
        GalacticraftEnergy.setEnergy(charged, MAX_ENERGY);
        groupStacks.add(charged);

        ItemStack depleted = new ItemStack(this);
        GalacticraftEnergy.setEnergy(depleted, 0);
        depleted.setDamage(depleted.getMaxDamage() - 1);
        groupStacks.add(depleted);
    }
}
 
Example 4
Source File: BatteryItem.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public void onCraft(ItemStack battery, World world_1, PlayerEntity playerEntity_1) {
    CompoundTag batteryTag = battery.getOrCreateTag();
    battery.setDamage(BatteryItem.MAX_ENERGY);
    battery.setTag(batteryTag);
}