I'm trying to implement a rifle, which model depends on if it has a magazine inserted or no.
So, I'm doing the following:
Rifle class:
private static final String MAGAZINE_KEY = "has_magazine";
public ItemRifle () {
super("rifle");
setMaxStackSize(1);
addPropertyOverride(new ResourceLocation(Reference.MODID, "empty"),
new IItemPropertyGetter() {
@Override
public float apply (ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) {
return ItemRifle.getPropertyEmpty (stack, entityIn);
}
});
}
public static float getPropertyEmpty (ItemStack stack, @Nullable EntityLivingBase entityIn) {
if (entityIn == null) return 0.f;
ItemStack activeItemStack = entityIn.getActiveItemStack();
if (!activeItemStack.isEmpty() && activeItemStack.getItem() instanceof ItemRifle)
return ItemRifle.hasMagazine(stack) ? 0.f : 1.f; // 0 - not empty
return 0.f;
}
public static boolean hasMagazine (ItemStack stack) {
if (stack.hasTagCompound()) {
NBTTagCompound nbt = stack.getTagCompound();
return nbt.hasKey(MAGAZINE_KEY) && nbt.getBoolean(MAGAZINE_KEY);
}
return false;
}
Model of a rifle with magazine (model/item/rifle.json):
{
"parent": "item/handheld",
"textures": {"layer0": "ic2guns:items/rifle"},
"overrides": [
{"predicate": {"ic2guns:empty": 1}, "model": "ic2guns:item/rifle_empty"}
]
}
Model of an empty rifle (model/item/rifle_empty.json):
{
"parent": "ic2guns:item/rifle",
"textures": {
"layer0": "ic2guns:items/rifle_empty"
}
}
At this moment I literally have no code which would set any NBT tag to rifle, so it should use the texture of an empty rifle.
However, the base one (rifle with magazine) is rendered.
Have I forgotten to register anything, or I'm doing it in a totally wrong way?