Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.