I was hoping I could get some assistance with some coding.
I'm trying to get tools and weapons to consume XP when they are used. Every time a block is broken, the tool uses the player's XP instead of durability. then if there is no XP, the tool will use durability.
I managed to make swords work the way I want with this code placed in my sword class:
EntityPlayer extends EntityLivingBase, as do many other mobs. The EntityLivingBase parameter that is passed to onBlockDestroyed() is whatever entity happened to destroy that block in question, which in 99% of cases will be a player. You can simply cast that argument to an EntityPlayer instance by using:
if(entityLiving != null && entityLiving instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entityLiving;
// Your code here...
}
Hello,
I was hoping I could get some assistance with some coding.
I'm trying to get tools and weapons to consume XP when they are used. Every time a block is broken, the tool uses the player's XP instead of durability. then if there is no XP, the tool will use durability.
I managed to make swords work the way I want with this code placed in my sword class:
This works because the supplied code for onLeftClickEntity accepts EntityPlayer in it's arguments.
So I looked into doing the same for tools but the method for block breaking:
does not have an argument for EntityPlayer.
anyone have any ideas on how I can get this to work?
EntityPlayer extends EntityLivingBase, as do many other mobs. The EntityLivingBase parameter that is passed to onBlockDestroyed() is whatever entity happened to destroy that block in question, which in 99% of cases will be a player. You can simply cast that argument to an EntityPlayer instance by using:
Mapping and Modding rules | Global rules