Posted July 17, 201312 yr I'm trying to make a check to see if the player has my sword in his/her hands. It doesn't print anything in the console when I start the client. mod_deathman12e3 (It's in the postInit) package deathman12e3; import java.util.Arrays; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.EnumArmorMaterial; import net.minecraft.item.EnumToolMaterial; import net.minecraft.item.Item; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemAxe; import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemSpade; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraftforge.common.Configuration; import net.minecraftforge.common.EnumHelper; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.PostInit; import cpw.mods.fml.common.Mod.PreInit; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid = "TrifectaOres", name = "Trifecta Ores", version = "1.0") @NetworkMod(clientSideRequired = true, serverSideRequired = false) public class mod_deathman12e3 { @Instance("mod_deathman12e3") public static mod_deathman12e3 instance; @SidedProxy(clientSide = "deathman12e3.ClientProxy", serverSide = "deathman12e3.CommonProxy") public static CommonProxy proxy; @PreInit public void preInit(FMLPreInitializationEvent event) { System.out.println("***************************************************************"); System.out.println("Loading 12e3Ores..."); System.out.println("***************************************************************"); ModMetadata modmeta = event.getModMetadata(); modmeta.authorList = Arrays.asList(new String [] { "deathman12e3" }); modmeta.autogenerated = false; modmeta.credits = ""; modmeta.description = "Trifecta Ores adds Hellstone to the nether, Adamantite to the end, and Cobalt to the overworld."; Configuration config = new Configuration(event.getSuggestedConfigurationFile()); config.load(); //HELLSTONE-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- hellstoneOreID = config.get("Blocks", "Hellstone Ore", 3000).getInt(); hellstoneCompactID = config.get("Blocks", "Hellstone Compact", 3001).getInt(); hellstoneIngotID = config.get("Items", "Hellstone Ingot", 8000).getInt(); hellstoneSwordID = config.get("Items", "Hellstone Sword", 8001).getInt(); hellstonePickaxeID = config.get("Items", "Hellstone Pickaxe", 8002).getInt(); //HELLSTONE-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- config.save(); } @Init public void Init(FMLInitializationEvent event) { //HELLSTONE-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- hellstoneOre = (BlockHellstoneOre) new BlockHellstoneOre(hellstoneOreID, Material.rock).setUnlocalizedName("hellstoneOre"); hellstoneCompact = (BlockCompact12e3) new BlockCompact12e3(hellstoneCompactID, Material.iron).setUnlocalizedName("hellstoneCompact"); hellstoneIngot = (Item) new Item(hellstoneIngotID).setUnlocalizedName("hellstoneIngot"); hellstoneSword = (ItemSword12e3) new ItemSword12e3(hellstoneSwordID, HELLSTONE).setUnlocalizedName("hellstoneSword"); hellstonePickaxe = (ItemPickaxe12e3) new ItemPickaxe12e3(hellstonePickaxeID, HELLSTONE).setUnlocalizedName("hellstonePickaxe"); GameRegistry.addSmelting(hellstoneOre.blockID, new ItemStack(hellstoneIngot, 1), 1.0F); GameRegistry.addShapelessRecipe(new ItemStack(hellstoneCompact, 1), hellstoneIngot, hellstoneIngot, hellstoneIngot, hellstoneIngot, hellstoneIngot, hellstoneIngot, hellstoneIngot, hellstoneIngot, hellstoneIngot); GameRegistry.addShapedRecipe(new ItemStack(hellstoneSword, 1), " I ", " I ", " S ", 'I', hellstoneIngot, 'S', Item.stick); GameRegistry.addShapedRecipe(new ItemStack(hellstonePickaxe, 1), "III", " S ", " S ", 'I', hellstoneIngot, 'S', Item.stick); //HELLSTONE-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- } @PostInit public void postInit(FMLPostInitializationEvent event) { proxy.registerServerTickHandler(); //HELLSTONE-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GameRegistry.registerBlock(hellstoneOre, "hellstoneOre"); GameRegistry.registerBlock(hellstoneCompact, "hellstoneCompact"); LanguageRegistry.addName(hellstoneOre, "Hellstone Ore"); LanguageRegistry.addName(hellstoneCompact, "Hellstone Compact"); MinecraftForge.setBlockHarvestLevel(hellstoneOre, "pickaxe", 3); MinecraftForge.setBlockHarvestLevel(hellstoneCompact, "pickaxe", 3); LanguageRegistry.addName(hellstoneIngot, "Hellstone Ingot"); LanguageRegistry.addName(hellstoneSword, "Hellstone Sword"); LanguageRegistry.addName(hellstonePickaxe, "Hellstone Pickaxe"); //HELLSTONE-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- System.out.println("***************************************************************"); System.out.println("Finished loading 12e3Ores!"); System.out.println("***************************************************************"); } //HELLSTONE-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- public static EnumToolMaterial HELLSTONE = EnumHelper.addToolMaterial("HELLSTONE", 4, 2048, 8, 3, 5); public static BlockHellstoneOre hellstoneOre; public static BlockCompact12e3 hellstoneCompact; public static Item hellstoneIngot; public static ItemSword12e3 hellstoneSword; public static ItemPickaxe12e3 hellstonePickaxe; public static int hellstoneOreID = 3000; public static int hellstoneCompactID = 3001; public static int hellstoneIngotID = 8000; public static int hellstoneSwordID = 8001; public static int hellstonePickaxeID = 8002; //HELLSTONE-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- } CommonProxy package deathman12e3; import cpw.mods.fml.common.registry.TickRegistry; import cpw.mods.fml.relauncher.Side; public class CommonProxy { public void registerRenderers() { } public int addArmor(String string) { return 0; } public void registerServerTickHandler() { TickRegistry.registerTickHandler(new ServerTickHandler12e3(), Side.SERVER); } } ServerTickHandler12e3 package deathman12e3; import java.util.EnumSet; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class ServerTickHandler12e3 implements ITickHandler { @Override public void tickStart(EnumSet<TickType> type, Object... tickData) { // TODO Auto-generated method stub } @Override public void tickEnd(EnumSet<TickType> type, Object... tickData) { // TODO Auto-generated method stub } @Override public EnumSet<TickType> ticks() { // TODO Auto-generated method stub return null; } @Override public String getLabel() { // TODO Auto-generated method stub return null; } private void onPlayerTick(EntityPlayer player) { if(player.getCurrentItemOrArmor(0) != null) { ItemStack hand = player.getCurrentItemOrArmor(0); if(hand.getItem() == mod_deathman12e3.hellstoneSword) { //player.addPotionEffect((new PotionEffect(Potion.nightVision.id, 100, 0))); System.out.println("HI"); } } } } Kain
July 17, 201312 yr With getCurrentItemOrArmor you're checking the four armor slots. To get the current held item, it's getCurrentEquippedItem which returns an itemstack.
July 17, 201312 yr Author Ok, I changed my method to this one. private void onPlayerTick(EntityPlayer player) { if(player.getCurrentEquippedItem() != null) { ItemStack hand = player.getCurrentEquippedItem(); if(hand == new ItemStack(mod_deathman12e3.hellstoneSword, 1)) { //player.addPotionEffect((new PotionEffect(Potion.nightVision.id, 100, 0))); System.out.println("HI"); } } } It still doesn't print anything :I Kain
July 17, 201312 yr Author I tweaked my code to check for the item ID. But I don't really know anything about item meta data values. Sorry I'm a bit of a newb at Java. private void onPlayerTick(EntityPlayer player) { if(player.getCurrentEquippedItem() != null) { ItemStack hand = player.getCurrentEquippedItem(); if(hand.getItem().itemID == mod_deathman12e3.hellstoneSword.itemID) { //player.addPotionEffect((new PotionEffect(Potion.nightVision.id, 100, 0))); System.out.println("HI"); } } } Kain
July 17, 201312 yr It may be your tick handler, then. Make sure it implements ITickHandler and it's server side, then use ModLoader.getMinecraftInstance.thePlayer for the player.
July 17, 201312 yr Author Figured it out. I never called the onPlayer method. I'll put my ServerTickHandler right here for anyone having the same problem. ServerTickHandler12e3 package deathman12e3; import java.util.EnumSet; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.src.ModLoader; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class ServerTickHandler12e3 implements ITickHandler { @Override public void tickStart(EnumSet<TickType> type, Object... tickData) { if (type.equals(EnumSet.of(TickType.PLAYER))) { playerTick((EntityPlayer)tickData[0]); } } @Override public void tickEnd(EnumSet<TickType> type, Object... tickData) { // TODO Auto-generated method stub } @Override public EnumSet<TickType> ticks() { return EnumSet.of(TickType.PLAYER, TickType.SERVER); } @Override public String getLabel() { // TODO Auto-generated method stub return null; } private void playerTick(EntityPlayer player) { if(player.getCurrentEquippedItem() != null) { ItemStack hand = player.getCurrentEquippedItem(); if(hand.getItem().itemID == mod_deathman12e3.hellstoneSword.itemID) { //player.addPotionEffect((new PotionEffect(Potion.nightVision.id, 100, 0))); System.out.println("HI"); } } } } Kain
July 17, 201312 yr Author But that check's if it's anywhere in the inventory. I'm only checking if it's in hand. Kain
July 18, 201312 yr par5 boolean is what you need to check if item is held if(par5 && (entity instanceof EntityPlayer)) { EntityPlayer player = (EntityPlayer)entity; if (!world.isRemote && !player.capabilities.isCreativeMode) { if (player.getFoodStats().getFoodLevel() >= 0) { player.getFoodStats().setFoodLevel(player.getFoodStats().getFoodLevel()-1); player.getFoodStats().setFoodSaturationLevel(0); } } } my hunger item code
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.