Jump to content

Recommended Posts

Posted

Hi everyone! This is my first post, so go easy on me, also i'd like to apologise in advance about my english, that not that good but i'm sure you all will understand.

 

I'm a beginner em "progamming" ( the quotes are cuz i'm not that good ), so, of course before i decide to make this post, i searched into the deeps of the internet for the answer but i don't even get close what i did wrong.

 

I was doing a easy task, this worked, but with a bug, the item last forever!

 

The item takes damage, but when it goes to 0(zero) this wont break, it still taking damage over damage but still there.

 

This is the event code:

 

package com.electroink.main;

import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;

public class MyMod {

@SubscribeEvent
public void onCrafting(PlayerEvent.ItemCraftedEvent e) {

	for(int i=0; i < e.craftMatrix.getSizeInventory(); i++)
	  {         
	      if(e.craftMatrix.getStackInSlot(i) != null)
	      {
	       ItemStack j = e.craftMatrix.getStackInSlot(i);
	       if(j.getItem() != null && j.getItem() == DamagedItem)
	       {
	        ItemStack k = new ItemStack(DamagedItem, 2, (j.getItemDamage() + 1 ));
	        e.craftMatrix.setInventorySlotContents(i, k);
	       }
	      }
	  }
}
}

 

The FML stuff:

@EventHandler
public static void PreLoad(FMLPreInitializationEvent PreEvent){
	FMLCommonHandler.instance().bus().register(new MyMod());	
}

 

And the recipe:

GameRegistry.addShapelessRecipe(new ItemStack(crafteditem, 1, 0), new ItemStack(useditem1), new ItemStack(willgetdamageitem, 1, OreDictionary.WILDCARD_VALUE));

 

I'd like to thanks the attention.

 

Best regrats, Necrolytie.

Posted

Sorry, forgeted this part.

The register:

:myitem= new Item().setUnlocalizedName("myitem").setCreativeTab(MyCreativeTab).setTextureName(Strings.MODID + ":" + "myitem").setMaxStackSize(1).setMaxDamage(25).setNoRepair();
    	GameRegistry.registerItem(ironhammer, "myitem");

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.