Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.6.4][SOLVED]Armor not giving player wearing it potion effects


Recommended Posts

When I equip the armor, it doesn't apply potion effects. I know it is probably being caused by something simple, but I can't figure out what. Here's my code:

Armor File:

 

package firearmor.armor;

import java.io.Console;

import firearmor.FireArmorBaseFile;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;

public class FireArmor extends ItemArmor
{
    public FireArmor(int par1, EnumArmorMaterial par2EnumArmorMaterial,
                     int par3, int par4, String armornamePrefix)
    {
        super(par1, par2EnumArmorMaterial, par3, par4);
        this.material = par2EnumArmorMaterial;
        par2EnumArmorMaterial.getDamageReductionAmount(par4);
        this.setMaxDamage(par2EnumArmorMaterial.getDurability(par4));
        this.maxStackSize = 1;
        armorNamePrefix = armornamePrefix;
    }
    public String armorNamePrefix;
    public EnumArmorMaterial material;
    @Override
    public boolean getIsRepairable(ItemStack tool, ItemStack material) {
    	return material.itemID == FireArmorBaseFile.fireCore.itemID;
    }
    public String getArmorTexture(ItemStack stack, Entity entity, int slot, int layer)
    {
        if (stack.toString().contains("leggings"))
        {
            return "firearmor:textures/models/armor/fire2.png";
        }

        if (stack.toString().contains("Leggings")) if (itemID == FireArmorBaseFile.FireLeggings.itemID)
            {
                return "firearmor:textures/models/armor/fire2.png";
            }

        return "firearmor:textures/models/armor/fire1.png";
    }
    public void registerIcons(IconRegister par1iconRegister)
    {
        if (itemID == FireArmorBaseFile.FireHelmet.itemID)
        {
            itemIcon = par1iconRegister.registerIcon("firearmor:FireHelmet");
        }

        if (itemID == FireArmorBaseFile.FireChestplate.itemID)
        {
            itemIcon = par1iconRegister.registerIcon("firearmor:FireChestplate");
        }

        if (itemID == FireArmorBaseFile.FireLeggings.itemID)
        {
            itemIcon = par1iconRegister.registerIcon("firearmor:FireLeggings");
        }

        if (itemID == FireArmorBaseFile.FireBoots.itemID)
        {
            itemIcon = par1iconRegister.registerIcon("firearmor:FireBoots");
        }
    }
    @Override
    public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemStack) {
    	if (player.getCurrentArmor(0) != null && player.getCurrentArmor(1) != null && player.getCurrentArmor(2) != null && player.getCurrentArmor(3) != null) {
		ItemStack helmet = player.getCurrentArmor(0);
		ItemStack plate = player.getCurrentArmor(1);
		ItemStack legs = player.getCurrentArmor(2);
		ItemStack boots = player.getCurrentArmor(3); 

		if (helmet.getItem() == FireArmorBaseFile.FireHelmet && plate.getItem() == FireArmorBaseFile.FireChestplate && legs.getItem() == FireArmorBaseFile.FireLeggings && boots.getItem() == FireArmorBaseFile.FireBoots) {
			player.addPotionEffect((new PotionEffect(Potion.fireResistance.getId(), 400, 0)));
		}
		if (helmet.getItem() == FireArmorBaseFile.FireHelmet) {
			player.addPotionEffect((new PotionEffect(Potion.nightVision.getId(), 400, 0)));
		}
		if (legs.getItem() == FireArmorBaseFile.FireLeggings) {
			player.addPotionEffect((new PotionEffect(Potion.moveSpeed.getId(), 400, 0)));
		}
	}
    }

}

 

Base File:

 

package firearmor;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.EnumHelper;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
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;
import firearmor.util.CommonProxy;
import firearmor.items.*;
import firearmor.armor.*;
import firearmor.tabs.TabFireArmor;

@Mod(modid="firearmor", name="Fire's Armors", version="0.1.0")
@NetworkMod(clientSideRequired=true)
public class FireArmorBaseFile {

        @Instance(value = "firearmor")
        public static FireArmorBaseFile instance;
        //Creative Tab Registry
        public static CreativeTabs TabFireArmor = new TabFireArmor(CreativeTabs.getNextID(), "Fire's Armors");
        //Armor Materials
        public static EnumArmorMaterial armorFire = EnumHelper.addArmorMaterial("FIRE", 15, new int[]{3, 7, 5, 3}, 45);
        //Item Registry
        public static Item fireCore = new fireCore(11255).setCreativeTab(TabFireArmor).setUnlocalizedName("fireCore").setCreativeTab(TabFireArmor);
        public static Item FireHelmet = new FireArmor(11256, armorFire, 0, 0, "FIRE").setUnlocalizedName("FireHelmet").setCreativeTab(TabFireArmor);
        public static Item FireChestplate = new FireArmor(11257, armorFire, 0, 1, "FIRE").setUnlocalizedName("FireChestplate").setCreativeTab(TabFireArmor);
        public static Item FireLeggings = new FireArmor(11258, armorFire, 0, 2, "FIRE").setUnlocalizedName("FireLeggings").setCreativeTab(TabFireArmor);
        public static Item FireBoots = new FireArmor(11259, armorFire, 0, 3, "FIRE").setUnlocalizedName("FireBoots").setCreativeTab(TabFireArmor);
        
        @SidedProxy(clientSide="firearmor.util.ClientProxy", serverSide="firearmor.util.CommonProxy")
        public static CommonProxy proxy;
        
        @EventHandler
        public void preInit(FMLPreInitializationEvent event) {
        }
        
        @EventHandler
        public void load(FMLInitializationEvent event) {
                proxy.registerRenderers();
                //Visible Name Registry
                LanguageRegistry.addName(FireHelmet, "The_Fireplace Helmet");
                LanguageRegistry.addName(FireChestplate, "The_Fireplace Chestplate");
                LanguageRegistry.addName(FireLeggings, "The_Fireplace Greaves");
                LanguageRegistry.addName(FireBoots, "The_Fireplace Boots");
                LanguageRegistry.addName(fireCore, "The_Fireplace Core");
                //ItemStacks
                ItemStack fireCoreStack = new ItemStack(fireCore);
                ItemStack enderPearlStack = new ItemStack(Item.enderPearl);
                ItemStack lavaStack = new ItemStack(Item.bucketLava);
                ItemStack blazePowderStack = new ItemStack(Item.blazePowder);
                ItemStack orangeDyeStack = new ItemStack(Item.dyePowder, 1, 14);
                ItemStack fireHelmStack = new ItemStack(FireHelmet);
                ItemStack fireChestStack = new ItemStack(FireChestplate);
                ItemStack fireBootsStack = new ItemStack(FireBoots);
                ItemStack fireLegsStack = new ItemStack(FireLeggings);
                ItemStack ObsidianStack = new ItemStack(Block.obsidian);
                ItemStack NetherrackStack = new ItemStack(Block.netherrack);
                ItemStack GlowstoneStack = new ItemStack(Block.glowStone);
                //Recipes
                GameRegistry.addRecipe(fireCoreStack, "xyx", "yzy", "xyx",
                		'x', lavaStack, 'y', blazePowderStack, 'z', enderPearlStack);
                GameRegistry.addRecipe(fireHelmStack, "ooo", "oco", "nen",
                		'o', ObsidianStack, 'c', fireCoreStack, 'n', GlowstoneStack, 'e', enderPearlStack);
                GameRegistry.addRecipe(fireChestStack, "oeo", "ncn", "oeo",
                		'o', ObsidianStack, 'c', fireCoreStack, 'n', GlowstoneStack, 'e', enderPearlStack);
                GameRegistry.addRecipe(fireLegsStack, "oeo", "n n", "e e",
                		'o', ObsidianStack, 'c', fireCoreStack, 'n', GlowstoneStack, 'e', enderPearlStack);
                GameRegistry.addRecipe(fireBootsStack, "d d", "oeo", "n n",
                		'o', ObsidianStack, 'd', orangeDyeStack, 'n', GlowstoneStack, 'e', enderPearlStack);
        }
        
        @EventHandler
        public void postInit(FMLPostInitializationEvent event) {
        }
}

 

Let me know if I left anything out of the post, and I will edit it in.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to post
Share on other sites

UPDATE:

I have narrowed it down to the following section of code:

 

if (helmet.getItem() == FireArmorBaseFile.FireHelmet && plate.getItem() == FireArmorBaseFile.FireChestplate && legs.getItem() == FireArmorBaseFile.FireLeggings && boots.getItem() == FireArmorBaseFile.FireBoots) {
player.addPotionEffect((new PotionEffect(Potion.fireResistance.getId(), 400, 0)));
}
if (helmet.getItem() == FireArmorBaseFile.FireHelmet) {
player.addPotionEffect((new PotionEffect(Potion.nightVision.getId(), 400, 0)));
}
if (legs.getItem() == FireArmorBaseFile.FireLeggings) {
player.addPotionEffect((new PotionEffect(Potion.moveSpeed.getId(), 400, 0)));
}

 

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to post
Share on other sites

And this is where we do things like

 

System.out.println(helmet.getItem() == FireArmorBaseFile.FireHelmet)

 

And see what its doing.

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.

Link to post
Share on other sites

Ok, but that doesn't tell us what's failing.

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.

Link to post
Share on other sites

That section of code that I narrowed it down to is failing to activate, so the Potion Effects aren't being applied to the player while the armor is worn, which is the goal. That's why I asked, is to see if anyone could figure out why it isn't activating.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to post
Share on other sites

Hi

 

if (helmet.getItem() == FireArmorBaseFile.FireHelmet) {
  player.addPotionEffect((new PotionEffect(Potion.nightVision.getId(), 400, 0)));
}

 

So you say that this line is being executed

if (helmet.getItem() == FireArmorBaseFile.FireHelmet

but it is never true, even when you think the helmet is being worn

 

Depending on how you've coded FireHelmet, this might work instead

if (helmet.getItem().itemID == FireArmorBaseFile.FireHelmet.itemID)

 

BTW that should probably be FireArmorBaseFile.fireHelmet ?

 

If that doesn't work, show us your FireArmorBaseFile.java?

 

-TGG

 

 

Link to post
Share on other sites

So just to clarify, what do the if statements return that are checking whether or not the player is wearing the armor? We really don't know what the exact problem is...

If you really want help, give that modder a thank you.

 

Modders LOVE thank yous.

Link to post
Share on other sites

I'm pretty sure you've got the armor slots backwards; the vanilla java docs on this are very confusing, but this is what I've come up with after testing quite a bit:

 

// this is what the java docs will tell you, but it's for rendering position only:

Armor types as used in armor class: 0 helm, 1 chest, 2 legs, 3 boots

 

// this is what is actually used for storing the positions in the player inventory:

Armor types as used on player: 0 boots, 1 legs, 2 chest, 3 helm

 

Use the second set of values with getCurrentArmor or add one for getCurrentItemOrArmor

Link to post
Share on other sites
Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.