Jump to content

Recommended Posts

Posted

Well, the shield I made is functional. It blocks arrows and in 3rd person plays the correct animation. My model also loads fine. I'm having 2 issues:

1) when right-clicking, the first person animation doesn't play (just does a similar animation to what happens when you right-click an empty bucket on a block in creative)

2) the shield doesn't take damage when hit

 

I've tried adding "textures" and "elements" to p455w0rdshield_blocking.json and this had no effect.

I thought maybe I needed a custom IItemPropertyGetter as you do with ItemBow, but ItemShield doesn't check for an instanceof ItemShield

 

ItemPShield.java

public class ItemPShield extends ItemShield
{
private final String name = "p455w0rdshield";

    public ItemPShield()
    {
    	setRegistryName(this.name);
setUnlocalizedName(this.name);
GameRegistry.register(this);
        this.setMaxStackSize(1);
        this.setMaxDamage(336);
        this.setCreativeTab(CreativeTabs.tabCombat);
        this.setCreativeTab(CommonProxy.creativeTab);
        this.addPropertyOverride(new ResourceLocation(Globals.MODID, "blocking"), new IItemPropertyGetter()
        {
            @SideOnly(Side.CLIENT)
            public float apply(ItemStack stack, World worldIn, EntityLivingBase entityIn)
            {
                return entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack ? 1.0F : 0.0F;
            }
        });
    }
    
    @SideOnly(Side.CLIENT)
    public void initModel() {
    	ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(this.getRegistryName(), "inventory"));
    }

    @Override
    public String getItemStackDisplayName(ItemStack stack)
    {
        return LocaleHandler.p455w0rdshield.getLocal();
    }

    /**
     * allows items to add custom lines of information to the mouseover description
     */
    @SideOnly(Side.CLIENT)
    @Override
    public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
    {
        //ItemBanner.func_185054_a(stack, tooltip);
    	tooltip.add("Tooltip");
    }

}

 

models/item/p455w0rdshield.json

{
"textures": {
        "0": "minecraft:blocks/diamond_block",
        "1": "minecraft:blocks/iron_block"
    },
    "elements": [
        {
            "name": "Cube",
            "from": [ 6.0, 0.0, 8.0 ], 
            "to": [ 10.0, 1.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 6.0, 14.0, 10.0, 15.0 ] },
                "east": { "texture": "#0", "uv": [ 10.0, 14.0, 11.0, 15.0 ] },
                "south": { "texture": "#0", "uv": [ 6.0, 14.0, 10.0, 15.0 ] },
                "west": { "texture": "#0", "uv": [ 5.0, 14.0, 6.0, 15.0 ] },
                "up": { "texture": "#-1", "uv": [ 1.0, 2.0, 5.0, 3.0 ] },
                "down": { "texture": "#0", "uv": [ 6.0, 14.0, 10.0, 15.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 5.0, 1.0, 8.0 ], 
            "to": [ 11.0, 2.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 5.0, 13.0, 11.0, 14.0 ] },
                "east": { "texture": "#0", "uv": [ 11.0, 13.0, 12.0, 14.0 ] },
                "south": { "texture": "#0", "uv": [ 5.0, 13.0, 11.0, 14.0 ] },
                "west": { "texture": "#0", "uv": [ 4.0, 13.0, 5.0, 14.0 ] },
                "up": { "texture": "#-1", "uv": [ 0.0, 0.0, 6.0, 1.0 ] },
                "down": { "texture": "#0", "uv": [ 5.0, 13.0, 11.0, 14.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 3.0, 2.0, 8.0 ], 
            "to": [ 13.0, 3.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 3.0, 12.0, 13.0, 13.0 ] },
                "east": { "texture": "#0", "uv": [ 13.0, 12.0, 14.0, 13.0 ] },
                "south": { "texture": "#0", "uv": [ 3.0, 12.0, 13.0, 13.0 ] },
                "west": { "texture": "#0", "uv": [ 2.0, 12.0, 3.0, 13.0 ] },
                "up": { "texture": "#-1", "uv": [ 0.0, 0.0, 10.0, 1.0 ] },
                "down": { "texture": "#0", "uv": [ 3.0, 12.0, 13.0, 13.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 2.0, 3.0, 8.0 ], 
            "to": [ 14.0, 4.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 2.0, 11.0, 14.0, 12.0 ] },
                "east": { "texture": "#0", "uv": [ 14.0, 11.0, 15.0, 12.0 ] },
                "south": { "texture": "#0", "uv": [ 2.0, 11.0, 14.0, 12.0 ] },
                "west": { "texture": "#0", "uv": [ 1.0, 11.0, 2.0, 12.0 ] },
                "up": { "texture": "#-1", "uv": [ 0.0, 0.0, 12.0, 1.0 ] },
                "down": { "texture": "#0", "uv": [ 2.0, 11.0, 14.0, 12.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 1.0, 4.0, 8.0 ], 
            "to": [ 15.0, 14.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 1.0, 1.0, 15.0, 11.0 ] },
                "east": { "texture": "#0", "uv": [ 14.0, 2.0, 15.0, 12.0 ] },
                "south": { "texture": "#0", "uv": [ 1.0, 1.0, 15.0, 11.0 ] },
                "west": { "texture": "#0", "uv": [ 1.0, 12.0, 2.0, 2.0 ] },
                "up": { "texture": "#0", "uv": [ 2.0, 2.0, 15.0, 1.0 ] },
                "down": { "texture": "#0", "uv": [ 1.0, 11.0, 15.0, 12.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 2.0, 14.0, 8.0 ], 
            "to": [ 14.0, 15.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 2.0, 1.0, 14.0, 2.0 ] },
                "east": { "texture": "#0", "uv": [ 14.0, 1.0, 15.0, 2.0 ] },
                "south": { "texture": "#0", "uv": [ 2.0, 1.0, 14.0, 2.0 ] },
                "west": { "texture": "#0", "uv": [ 1.0, 1.0, 2.0, 2.0 ] },
                "up": { "texture": "#0", "uv": [ 2.0, 1.0, 14.0, 2.0 ] },
                "down": { "texture": "#-1", "uv": [ 0.0, 0.0, 12.0, 1.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 7.0, 6.0, 4.0 ], 
            "to": [ 9.0, 7.0, 8.0 ], 
            "faces": {
                "north": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 1.0 ] },
                "east": { "texture": "#1", "uv": [ 1.0, 14.0, 5.0, 15.0 ] },
                "south": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 1.0 ] },
                "west": { "texture": "#1", "uv": [ 1.0, 14.0, 5.0, 15.0 ] },
                "up": { "texture": "#1", "uv": [ 1.0, 1.0, 3.0, 5.0 ] },
                "down": { "texture": "#1", "uv": [ 1.0, 1.0, 3.0, 5.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 7.0, 11.0, 4.0 ], 
            "to": [ 9.0, 12.0, 8.0 ], 
            "faces": {
                "north": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 1.0 ] },
                "east": { "texture": "#1", "uv": [ 1.0, 11.0, 5.0, 12.0 ] },
                "south": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 1.0 ] },
                "west": { "texture": "#1", "uv": [ 1.0, 11.0, 5.0, 12.0 ] },
                "up": { "texture": "#1", "uv": [ 2.0, 2.0, 4.0, 6.0 ] },
                "down": { "texture": "#1", "uv": [ 1.0, 1.0, 3.0, 5.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 7.0, 6.0, 3.0 ], 
            "to": [ 9.0, 12.0, 4.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 1.0, 11.0, 3.0, 17.0 ] },
                "east": { "texture": "#1", "uv": [ 3.0, 11.0, 4.0, 17.0 ] },
                "south": { "texture": "#1", "uv": [ 1.0, 2.0, 3.0, 8.0 ] },
                "west": { "texture": "#1", "uv": [ 3.0, 11.0, 4.0, 17.0 ] },
                "up": { "texture": "#1", "uv": [ 2.0, 1.0, 4.0, 2.0 ] },
                "down": { "texture": "#1", "uv": [ 1.0, 1.0, 3.0, 2.0 ] }
            }
        }
    ],
    "display": {
        "thirdperson_righthand": {
            "rotation": [ 0, 90, 0 ],
            "translation": [ 2, -3, 3 ],
            "scale": [ 1, 1, 1 ]
        },
        "thirdperson_lefthand": {
            "rotation": [ 0, 90, 0 ],
            "translation": [ 2, -3, 3 ],
            "scale": [ 1, 1, 1 ]
        },
        "firstperson_righthand": {
            "rotation": [ 0, 180, 5 ],
            "translation": [ -4, -1, 6 ],
            "scale": [ 1, 1, 1 ]
        },
        "firstperson_lefthand": {
            "rotation": [ 0, 180, 5 ],
            "translation": [ -2, -2, 6 ],
            "scale": [ 1.25, 1.25, 1.25 ]
        },
        "gui": {
            "rotation": [ 15, -25, -5 ],
            "translation": [ 2, 1, 0 ],
            "scale": [ 1, 1, 1 ]
        },
        "fixed": {
            "rotation": [ 0, 180, 0 ],
            "translation": [ 0, 0, -2],
            "scale":[ 1, 1, 1]
        },
        "ground": {
            "rotation": [ 0, 0, 0 ],
            "translation": [ 0, 5, 0],
            "scale":[ 0.5, 0.5, 0.5]
        }
    },
    "overrides": [
        {
            "predicate": {
                "blocking": 1
            },
            "model": "p455w0rdsthings:item/p455w0rdshield_blocking"
        }
    ]
}

 

models/item/p455w0rdshield_blocking.json

{
    "display": {
        "thirdperson_righthand": {
            "rotation": [ 45, 135, 0 ],
            "translation": [ 3.51, 11, -2 ],
            "scale": [ 1, 1, 1 ]
        },
        "thirdperson_lefthand": {
            "rotation": [ 45, 135, 0 ],
            "translation": [ 13.51, 3, 5 ],
            "scale": [ 1, 1, 1 ]
        },
        "firstperson_righthand": {
            "rotation": [ 0, 180, -5 ],
            "translation": [ -15, 5, -11 ],
            "scale": [ 1.25, 1.25, 1.25 ]
        },
        "firstperson_lefthand": {
            "rotation": [ 0, 180, -5 ],
            "translation": [ 5, 5, -11 ],
            "scale": [ 1.25, 1.25, 1.25 ]
        },
        "gui": {
            "rotation": [ 15, -25, -5 ],
            "translation": [ 2, 3, 0 ],
            "scale": [ 0.65, 0.65, 0.65 ]
        }
    }
}

 

More possibly relevant info:

Item is registered in commonproxy on preinit

Custom model is loaded via ModelLoader.setCustomModelResourceLocation in clientproxy on preinit

Any help/guidence is greatly appreciated =]

 

============================

Okay, so I figured out why the shield isn't taking damage. It's tracked in EntityPlayer and doesn't check for instanceof, rather it checks for Items.shield. I'm now going to work on figuring out which event bus I should use to do the detection and will post back if/when I figure it out for anyone else who might have this same question.

Posted

Figured I'd post my success thus far. I've solved the shield damage issue. As I stated in the edit of the OP, the shield damage is handled in EntityPlayer, so therefore an event handler must be used to calculate it for our custom shield. The event handler needed in this case is LivingAttackEvent. Here is my resulting code in which the shield takes damage. Feel free to criticize/inform me of better ways of doing this or if I have done something in error.

 

@SubscribeEvent
public void attackEvent(LivingAttackEvent e) {
	float damage = e.getAmount();
	ItemStack activeItemStack;
	EntityPlayer player;
	if (!(e.getEntityLiving() instanceof EntityPlayer)) {
		return;
	}
	player = (EntityPlayer) e.getEntityLiving();
	if (player.getActiveItemStack() == null) {
		return;
	}
	activeItemStack = player.getActiveItemStack();

	if (damage > 0.0F && activeItemStack != null && activeItemStack.getItem() == ModItems.ItemShield) {
		int i = 1 + MathHelper.floor_float(damage);
		activeItemStack.damageItem(i, player);

		if (activeItemStack.stackSize <= 0) {
			EnumHand enumhand = player.getActiveHand();
			net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, activeItemStack, enumhand);

			if (enumhand == EnumHand.MAIN_HAND) {
				player.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, (ItemStack) null);
			}
			else {
				player.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, (ItemStack) null);
			}

			activeItemStack = null;
			if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
				player.playSound(SoundEvents.item_shield_break, 0.8F, 0.8F + player.worldObj.rand.nextFloat() * 0.4F);
			}
		}
	}
}

 

Replace ModItems.ItemShield with your mod's item.

Something else I've discovered worth mentioning: There is now a single forge event bus! FMLCommonHandler's bus is now deprecated, so use MinecraftForge.EVENT_BUS from here forward =]

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.