use of com.mcmoddev.lib.item.ItemMMDShield in project BaseMetals by MinecraftModDevelopmentMods.
the class EventHandler method attackEvent.
/**
* @param event
*/
@SubscribeEvent
public static void attackEvent(final LivingAttackEvent event) {
final float damage = event.getAmount();
if (!(event.getEntityLiving() instanceof EntityPlayer)) {
return;
}
final EntityPlayer player = (EntityPlayer) event.getEntityLiving();
final ItemStack activeItemStack = player.getActiveItemStack();
if (activeItemStack.isEmpty()) {
return;
}
if ((damage > 0.0F) && (activeItemStack.getItem() instanceof ItemMMDShield)) {
final int i = 1 + MathHelper.floor(damage);
activeItemStack.damageItem(i, player);
if (activeItemStack.getCount() <= 0) {
final EnumHand enumhand = player.getActiveHand();
ForgeEventFactory.onPlayerDestroyItem(player, activeItemStack, enumhand);
if (enumhand == EnumHand.MAIN_HAND) {
player.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
} else {
player.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, ItemStack.EMPTY);
}
if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
player.playSound(SoundEvents.BLOCK_ANVIL_BREAK, 0.8F, 0.8F + (player.world.rand.nextFloat() * 0.4F));
}
}
}
}
Aggregations