Jump to content

[1.7.2] Damage an ItemStack properly


Bedrock_Miner

Recommended Posts

Hey Guys!

 

I wanted to create a crafting table which uses a special item to craft. The item has a durability of 64. One damage point should be added on crafting. The problem is that this doesn't work.

 

Code:

 

Item:

 

package com.bedrockminer.magicum.item;

import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.Item;
import net.minecraft.util.IIcon;

import com.bedrockminer.magicum.Main;
import com.bedrockminer.magicum.creative.Tabs;
import com.bedrockminer.magicum.element.Elements;

public class ItemEssence extends Item {

private final Elements element;
private IIcon iconDamage1;
private IIcon iconDamage2;

public ItemEssence(String unlocalizedName, Elements element) {
	super();
	this.setUnlocalizedName(unlocalizedName);
	this.setTextureName(Main.MODID + ":" + unlocalizedName);
	this.setCreativeTab(Tabs.essences);
	this.setMaxDamage(64);
	this.setMaxStackSize(1);
	this.element = element;
}

public Elements getElement() {
	return this.element;
}

@Override
public IIcon getIconFromDamage(int damage) {
	if (damage > 2 * this.getMaxDamage() / 3)
		return this.iconDamage2;
	if (damage > this.getMaxDamage() / 3)
		return this.iconDamage1;
	return this.itemIcon;
}

@Override
public void registerIcons(IIconRegister reg) {
	this.itemIcon = reg.registerIcon(this.getIconString() + "_stage_0");
	this.iconDamage1 = reg.registerIcon(this.getIconString() + "_stage_1");
	this.iconDamage2 = reg.registerIcon(this.getIconString() + "_stage_2");
}
}

 

 

onCrafting:

 

public void onPlayerCrafting(EntityPlayer player, ItemStack stack) {
	for (int i = 9; i < 12; i ++) {
		Main.log("loop");
		Elements element = Elements.None;
	   	if (i - 9 < this.neededElements.size())
	   		element = this.neededElements.get(i - 9);

	   	if (element != Elements.None) {
	   		this.te.getStackInSlot(i).damageItem(1, player);
	   		Main.log("damage");
	   	}
	}
}

 

The log "damage" is written in the console.

The method is called from onSlotChange of the corresponding slot.

@Override
public void onSlotChanged() {
	super.onSlotChanged();
	this.owner.onCraftMatrixChanged(this.inventory);
}

 

 

I hope someone understands the problem...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.