Search in sources :

Example 1 with ItemMMDShield

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));
            }
        }
    }
}
Also used : EnumHand(net.minecraft.util.EnumHand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemMMDShield(com.mcmoddev.lib.item.ItemMMDShield) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ItemMMDShield (com.mcmoddev.lib.item.ItemMMDShield)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 EnumHand (net.minecraft.util.EnumHand)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1