Jump to content

Recommended Posts

Posted

Hello everybody!

 

I created an Item which gets damage from a handler, which works. But if the Item gets the last bit of Damage which should destroy it, it doesn't and another Item appears there instead which has zero Damage.

Have i missed anything in my Item class? It looks very short, I think..

 

package mod.classes.items;

import java.util.List;

import mod.Main;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;

public class ItemTool extends ModItem {

public ItemTool(int ID) {
	super(ID);
	this.setMaxStackSize(1);
        this.setMaxDamage(128);
        this.setCreativeTab(Main.modBasic);
}	
}

 

The Damage is dealt with this Method:

player.inventory.getStackInSlot(InventoryController.getSlot(Element.get(elementID))).damageItem(1, player);

 

Hope anybody sees my Mistake..

 

  • 2 weeks later...
Posted

Hi

 

Look in ItemStack.damageItem()

--->EntityPlayer.destroyCurrentEquippedItem

-->

 

        this.inventory.setInventorySlotContents(this.inventory.currentItem, (ItemStack)null);

 

I think this might be what you are after?

 

-TGG

 

Posted

@Override

public void onUpdate(ItemStack stack, World world, Entity entity, int n, boolean b)

{

if (stack.getItemDamage() >= stack.getMaxDamage())

stack.stackSize -= 1; //if this is reduced to 0, it is automatically "destroyed"

}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Even this doesn't work.

I think the problem is, that the Item I want to damage is not the currently selected Item. It can be any Item in the Inventory... I don't understand, why it doesn't break..

 

Note: The Item, which you get instead of the old one can't be throwed out of the Inventory. If you press Q the game crashes with the following crash report:

  Reveal hidden contents

 

Posted

Now it works!

I changed my damage-method to the following:

player.inventory.getStackInSlot(InventoryController.getSlot(Element.get(elementID))).setItemDamage(player.inventory.getStackInSlot(InventoryController.getSlot(Element.get(elementID))).getItemDamage() + 1);
                    		if (player.inventory.getStackInSlot(InventoryController.getSlot(Element.get(elementID))).getItemDamage() >= player.inventory.getStackInSlot(InventoryController.getSlot(Element.get(elementID))).getMaxDamage())
                    			player.inventory.setInventorySlotContents(InventoryController.getSlot(Element.get(elementID)), null);

 

Thanks to all of you!

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.