Jump to content

Recommended Posts

Posted

Here is my item code:

import mods.giantnuker.backslash.item.ItemBasicArmor;
import mods.giantnuker.backslash.item.ItemData;
import mods.giantnuker.javautil.Pair;
import mods.giantnuker.javautil.PairList;
import mods.giantnuker.modifiablearmorredone.modifiers.ArmorModifier;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.EnumHelper;

public class ItemModableArmor extends ItemBasicArmor {

	public ItemModableArmor(EntityEquipmentSlot slot) {	
		super(ModArmor.MODID, "modifiablearmor." + slot.toString(), ArmorMaterial.LEATHER, slot, true);
		this.setMaxDamage(1);
	}
	public PairList<ArmorModifier, NBTTagCompound> getModifiers(NBTTagList modList) {
		if (modList == null) return new PairList();
		PairList<ArmorModifier, NBTTagCompound> modifiers = new PairList();
		for (NBTBase nbt1 : modList) {
			if (!(nbt1 instanceof NBTTagCompound)) continue;
			NBTTagCompound nbt2 = (NBTTagCompound) nbt1;
			ResourceLocation id = new ResourceLocation(nbt2.getString("id"));
			if (!ArmorModifier.MAP.containsKey(id)) continue;
			NBTTagCompound nbt3 = nbt2.getCompoundTag("data");
			if (nbt3 == null) nbt3 = new NBTTagCompound();
			modifiers.add(ArmorModifier.MAP.get(id), nbt3);
		}
		return modifiers;
	}
	public void setupMods(ItemStack stack) {
		NBTTagCompound nbt = (NBTTagCompound) ItemData.getStackNBTTag(stack, "itemData", new NBTTagCompound());
		PairList<ArmorModifier, NBTTagCompound> modifiers = getModifiers((NBTTagList) nbt.getTag("modifiers"));
		nbt.setInteger("reduction", this.damageReduceAmount);
		nbt.setFloat("toughness", this.toughness);
		nbt.setInteger("maxDamage", MAConfig.maxDamage);
		for (Pair<ArmorModifier, NBTTagCompound> modifier : modifiers) {
			modifier.getA().apply(modifier.getB(), this.armorType, stack);
		}
		ItemData.setStackNBTTag(stack, "itemData", nbt);
		stack.getMaxDamage();
	}
	
	public void addModifier(ItemStack stack, ArmorModifier modifier, NBTTagCompound nbt) {
		NBTTagCompound nbtI = (NBTTagCompound) ItemData.getStackNBTTag(stack, "itemData", new NBTTagCompound());
		NBTTagList mods = (NBTTagList) nbt.getTag("modifiers");
		if (mods == null) mods = new NBTTagList();
		NBTTagCompound nbtM = new NBTTagCompound();
		nbtM.setString("id", modifier.toString());
		nbtM.setTag("data", nbt);
		mods.appendTag(nbtM);
		nbtI.setTag("modifiers", mods);
		ItemData.setStackNBTTag(stack, "itemData", nbtI);
	}
	public void initNBT(ItemStack stack) {
		NBTTagCompound nbt = (NBTTagCompound) ItemData.getStackNBTTag(stack, "itemData", new NBTTagCompound());
		if (nbt.getInteger("reduction") == 0) nbt.setInteger("reduction", this.damageReduceAmount);
		if (nbt.getInteger("toughness") == 0) nbt.setFloat("toughness", this.toughness);
		if (nbt.getInteger("maxDamage") == 0) nbt.setInteger("maxDamage", MAConfig.maxDamage);
		ItemData.setStackNBTTag(stack, "itemData", nbt);
	}
	@Override
	public int getMaxDamage(ItemStack stack) {
		initNBT(stack);
		NBTTagCompound nbt = (NBTTagCompound) ItemData.getStackNBTTag(stack, "itemData", new NBTTagCompound());
		if (stack.getItemDamage() != -1)return nbt.getInteger("maxDamage");
		else return 0;
		
	}
	@Override
	public int getDamage(ItemStack stack) {
		initNBT(stack);
		NBTTagCompound nbt = (NBTTagCompound) ItemData.getStackNBTTag(stack, "itemData", new NBTTagCompound());
		if (super.getDamage(stack) >= nbt.getInteger("maxDamage")) {
			this.setDamage(stack, nbt.getInteger("maxDamage"));
			return -1;
		}
		return super.getDamage(stack);
	}
}

I want to know why this thing cannot get damaged.

This item is supposed to be unbreakable. If it gets broken, it goes into an unuseable state(not yet coded).

Note: getDamage has never returned -1.

Note2: No modifiers, so maxDamage is always 500.

Posted

Set breakpoints and run/step some damage cases in the debugger. Tell us what you learn.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted (edited)
16 hours ago, GiantNuker said:

INFO GATHERED:

  • Even if it is predamaged, it still cannot take damage.
  • Changing maxStackSize does nothing.
  • returning true in isDamageable() does nothing.

NEW INFO: I put it on a zombie, and it got damaged! Now any idea?

EDIT: one time occurance, the armor was already damaged... Sorry.

Edited by GiantNuker
Posted

Tell us about your experience in the debugger. Which methods did you step through? Did you set a breakpoint inside the method that calculates and applies damage to armor? What happened?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted
1 hour ago, jeffryfisher said:

Tell us about your experience in the debugger. Which methods did you step through? Did you set a breakpoint inside the method that calculates and applies damage to armor? What happened?

I do not know where that is. I ave been using attribute modifiers.

Posted (edited)
3 hours ago, Differentiation said:

I think it's better if you extend the class to ItemSpecialArmor.

What is ItemSpeccialArmor?

ItemBasicArmor extends ItemArmor.

Edited by GiantNuker
Posted
19 hours ago, GiantNuker said:

I do not know where that is.

Then I give up. Until you can describe an experience in the debugger, I can't help you (and I'm traveling for the next week, so I won't be able to check again for a while). Good luck!

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.