Posted September 6, 201411 yr Ok, i have a problem, i need to make an item that prevents death from any source. except, it dosent work, i just die while its in my inventory when its supposed to disappear while regenerating me. This is my code for the main file: package org.lvivtotoro.sus; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingDeathEvent; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.eventhandler.EventBus; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid = Suj.MODID, name = "Sylvestr's Useless Junk", version = Suj.VERSION) public class Suj { public static final String MODID = "suj"; public static final String VERSION = "0.2dev"; public static Block cookieB = new CookieBlock(Material.cloth).setBlockName( "cookieblock").setBlockTextureName("suj:cookieblock"); public static Item undeadprotectionI = new ItemUndeadProtection() .setUnlocalizedName("medicitem").setTextureName( "suj:undeadprotection"); @EventHandler public void init(FMLPreInitializationEvent event) { event.getModMetadata().authorList.add("BadBoy6767"); event.getModMetadata().description = "Does what the title is about."; MinecraftForge.EVENT_BUS.register(this); GameRegistry.registerBlock(cookieB, "cookieblocksuj"); LanguageRegistry.addName(cookieB, "Cookie Block"); GameRegistry.registerItem(undeadprotectionI, "undeadprotectionsuj"); LanguageRegistry.addName(undeadprotectionI, "Undead Protector"); cookieB.setCreativeTab(CreativeTabs.tabFood); undeadprotectionI.setCreativeTab(CreativeTabs.tabCombat); CraftingManager.getInstance().addRecipe(new ItemStack(cookieB, 1), new Object[] { "ZZZ", "ZZZ", "ZZZ", 'Z', Items.cookie }); } public void removeItem(EntityPlayer ep, ItemStack removeitem) { IInventory inv = ep.inventory; for (int i = 0; i < inv.getSizeInventory(); i++) { if (inv.getStackInSlot(i) != null) { ItemStack j = inv.getStackInSlot(i); if (j.getItem() != null && j.getItem() == removeitem.getItem()) { inv.setInventorySlotContents(i, null); } } } } @EventHandler public void onDeath(LivingDeathEvent e) { if(e.entityLiving instanceof EntityPlayer && !e.entityLiving.worldObj.isRemote) { EntityPlayerMP pmp = (EntityPlayerMP) e.entityLiving; if(pmp.inventory.hasItem(undeadprotectionI)) { removeItem(pmp, new ItemStack(undeadprotectionI, 1)); e.setCanceled(true); } } } } And this is my item class: package org.lvivtotoro.sus; import net.minecraft.item.Item; public class ItemUndeadProtection extends Item { } What should i do?
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.