Search in sources :

Example 21 with ItemSword

use of net.minecraft.item.ItemSword in project WizClient-1.8.9-Version by WizClient.

the class EntityLiving method updateEquipmentIfNeeded.

/**
 * Tests if this entity should pickup a weapon or an armor. Entity drops current weapon or armor if the new one is
 * better.
 */
protected void updateEquipmentIfNeeded(EntityItem itemEntity) {
    ItemStack itemstack = itemEntity.getEntityItem();
    int i = getArmorPosition(itemstack);
    if (i > -1) {
        boolean flag = true;
        ItemStack itemstack1 = this.getEquipmentInSlot(i);
        if (itemstack1 != null) {
            if (i == 0) {
                if (itemstack.getItem() instanceof ItemSword && !(itemstack1.getItem() instanceof ItemSword)) {
                    flag = true;
                } else if (itemstack.getItem() instanceof ItemSword && itemstack1.getItem() instanceof ItemSword) {
                    ItemSword itemsword = (ItemSword) itemstack.getItem();
                    ItemSword itemsword1 = (ItemSword) itemstack1.getItem();
                    if (itemsword.getDamageVsEntity() != itemsword1.getDamageVsEntity()) {
                        flag = itemsword.getDamageVsEntity() > itemsword1.getDamageVsEntity();
                    } else {
                        flag = itemstack.getMetadata() > itemstack1.getMetadata() || itemstack.hasTagCompound() && !itemstack1.hasTagCompound();
                    }
                } else if (itemstack.getItem() instanceof ItemBow && itemstack1.getItem() instanceof ItemBow) {
                    flag = itemstack.hasTagCompound() && !itemstack1.hasTagCompound();
                } else {
                    flag = false;
                }
            } else if (itemstack.getItem() instanceof ItemArmor && !(itemstack1.getItem() instanceof ItemArmor)) {
                flag = true;
            } else if (itemstack.getItem() instanceof ItemArmor && itemstack1.getItem() instanceof ItemArmor) {
                ItemArmor itemarmor = (ItemArmor) itemstack.getItem();
                ItemArmor itemarmor1 = (ItemArmor) itemstack1.getItem();
                if (itemarmor.damageReduceAmount != itemarmor1.damageReduceAmount) {
                    flag = itemarmor.damageReduceAmount > itemarmor1.damageReduceAmount;
                } else {
                    flag = itemstack.getMetadata() > itemstack1.getMetadata() || itemstack.hasTagCompound() && !itemstack1.hasTagCompound();
                }
            } else {
                flag = false;
            }
        }
        if (flag && this.func_175448_a(itemstack)) {
            if (itemstack1 != null && this.rand.nextFloat() - 0.1F < this.equipmentDropChances[i]) {
                this.entityDropItem(itemstack1, 0.0F);
            }
            if (itemstack.getItem() == Items.diamond && itemEntity.getThrower() != null) {
                EntityPlayer entityplayer = this.worldObj.getPlayerEntityByName(itemEntity.getThrower());
                if (entityplayer != null) {
                    entityplayer.triggerAchievement(AchievementList.diamondsToYou);
                }
            }
            this.setCurrentItemOrArmor(i, itemstack);
            this.equipmentDropChances[i] = 2.0F;
            this.persistenceRequired = true;
            this.onItemPickup(itemEntity, 1);
            itemEntity.setDead();
        }
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) ItemArmor(net.minecraft.item.ItemArmor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ItemBow(net.minecraft.item.ItemBow)

Example 22 with ItemSword

use of net.minecraft.item.ItemSword in project PickleTweaks by BlakeBr0.

the class ReinforcementHandler method onBreakBlock.

@SubscribeEvent
public void onBreakBlock(BlockEvent.BreakEvent event) {
    if (event.getPlayer() == null)
        return;
    ItemStack stack = event.getPlayer().getHeldItemMainhand();
    if (stack.isEmpty())
        return;
    if (!blockBreakTool(stack.getItem()))
        return;
    if (!isBlockHardEnough(event.getState(), event.getWorld(), event.getPos()))
        return;
    if (ReinforcementHelper.isReinforced(stack) && stack.isItemDamaged()) {
        int extra = ReinforcementHelper.useReinforcement(stack, stack.getItem() instanceof ItemSword ? 2 : 1);
        stack.setItemDamage(ReinforcementHelper.getDurability(stack) + extra);
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 23 with ItemSword

use of net.minecraft.item.ItemSword in project PickleTweaks by BlakeBr0.

the class ReinforcementRecipe method getReinforcementOutput.

public ItemStack getReinforcementOutput(InventoryCrafting inv) {
    ItemStack tool = ItemStack.EMPTY;
    boolean foundTool = false;
    NonNullList<ItemStack> inputs = NonNullList.<ItemStack>create();
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack slotStack = inv.getStackInSlot(i);
        if (slotStack.isEmpty()) {
            continue;
        }
        ItemStack newSlotStack = slotStack.copy();
        newSlotStack.setCount(1);
        if (!foundTool && newSlotStack.isItemStackDamageable()) {
            tool = newSlotStack;
            foundTool = true;
            continue;
        } else {
            inputs.add(newSlotStack);
        }
    }
    if (tool.isEmpty()) {
        return ItemStack.EMPTY;
    }
    if (inputs.isEmpty()) {
        return ItemStack.EMPTY;
    }
    if (tool.getItem().hasContainerItem(tool)) {
        return ItemStack.EMPTY;
    }
    if (ModConfig.confBrokenTools && TweakToolBreaking.isBroken(tool, tool.getItem() instanceof ItemSword ? 1 : 0)) {
        return ItemStack.EMPTY;
    }
    if (ReinforcementBlacklist.isBlacklisted(tool.getItem())) {
        return ItemStack.EMPTY;
    }
    int reeCount = 0;
    boolean maxed = false;
    int currentCount = ReinforcementHelper.getReinforcement(tool);
    for (ItemStack mat : inputs) {
        if (maxed)
            return ItemStack.EMPTY;
        if (ReinforcementHelper.isReinforcement(mat)) {
            reeCount += ReinforcementHelper.getReinforcementValue(mat);
            if ((reeCount + currentCount) > ModConfig.confMaxReinforcement) {
                maxed = true;
            }
        } else {
            return ItemStack.EMPTY;
        }
    }
    if (reeCount == 0) {
        return ItemStack.EMPTY;
    }
    ReinforcementHelper.reinforce(tool, reeCount);
    return tool;
}
Also used : ItemSword(net.minecraft.item.ItemSword) ItemStack(net.minecraft.item.ItemStack)

Example 24 with ItemSword

use of net.minecraft.item.ItemSword in project PickleTweaks by BlakeBr0.

the class FeatureSwordInfo method onEntityKilled.

@SubscribeEvent
public void onEntityKilled(LivingDeathEvent event) {
    if (!ModConfig.confSwordInfoTooltip) {
        return;
    }
    DamageSource source = event.getSource();
    Entity entity = source.getTrueSource();
    if (entity != null && entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        ItemStack stack = player.getHeldItemMainhand();
        if (!stack.isEmpty() && stack.getItem() instanceof ItemSword) {
            NBTTagCompound tag = stack.getOrCreateSubCompound(PickleTweaks.MOD_ID);
            tag.setInteger("EnemiesKilled", tag.getInteger("EnemiesKilled") + 1);
        }
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) Entity(net.minecraft.entity.Entity) DamageSource(net.minecraft.util.DamageSource) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 25 with ItemSword

use of net.minecraft.item.ItemSword in project MinecraftForge by MinecraftForge.

the class ForgeHooks method onBlockBreakEvent.

public static int onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, BlockPos pos) {
    // Logic from tryHarvestBlock for pre-canceling the event
    boolean preCancelEvent = false;
    if (gameType.isCreative() && !entityPlayer.getHeldItemMainhand().isEmpty() && entityPlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
        preCancelEvent = true;
    if (gameType.isAdventure()) {
        if (gameType == GameType.SPECTATOR)
            preCancelEvent = true;
        if (!entityPlayer.isAllowEdit()) {
            ItemStack itemstack = entityPlayer.getHeldItemMainhand();
            if (itemstack.isEmpty() || !itemstack.canDestroy(world.getBlockState(pos).getBlock()))
                preCancelEvent = true;
        }
    }
    // Tell client the block is gone immediately then process events
    if (world.getTileEntity(pos) == null) {
        SPacketBlockChange packet = new SPacketBlockChange(world, pos);
        packet.blockState = Blocks.AIR.getDefaultState();
        entityPlayer.connection.sendPacket(packet);
    }
    // Post the block break event
    IBlockState state = world.getBlockState(pos);
    BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, entityPlayer);
    event.setCanceled(preCancelEvent);
    MinecraftForge.EVENT_BUS.post(event);
    // Handle if the event is canceled
    if (event.isCanceled()) {
        // Let the client know the block still exists
        entityPlayer.connection.sendPacket(new SPacketBlockChange(world, pos));
        // Update any tile entity data for this block
        TileEntity tileentity = world.getTileEntity(pos);
        if (tileentity != null) {
            Packet<?> pkt = tileentity.getUpdatePacket();
            if (pkt != null) {
                entityPlayer.connection.sendPacket(pkt);
            }
        }
    }
    return event.isCanceled() ? -1 : event.getExpToDrop();
}
Also used : ItemSword(net.minecraft.item.ItemSword) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) NoteBlockEvent(net.minecraftforge.event.world.NoteBlockEvent) BlockEvent(net.minecraftforge.event.world.BlockEvent) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange)

Aggregations

ItemSword (net.minecraft.item.ItemSword)76 ItemStack (net.minecraft.item.ItemStack)53 Item (net.minecraft.item.Item)25 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)23 EntityPlayer (net.minecraft.entity.player.EntityPlayer)22 ItemTool (net.minecraft.item.ItemTool)21 ItemHoe (net.minecraft.item.ItemHoe)18 IBlockState (net.minecraft.block.state.IBlockState)17 ItemBow (net.minecraft.item.ItemBow)15 Entity (net.minecraft.entity.Entity)13 Block (net.minecraft.block.Block)9 EntityLivingBase (net.minecraft.entity.EntityLivingBase)8 ItemAxe (net.minecraft.item.ItemAxe)8 ItemBlock (net.minecraft.item.ItemBlock)8 World (net.minecraft.world.World)7 ItemArmor (net.minecraft.item.ItemArmor)6 ItemFishingRod (net.minecraft.item.ItemFishingRod)6 DamageSource (net.minecraft.util.DamageSource)6 ItemDoor (net.minecraft.item.ItemDoor)5 ItemShield (net.minecraft.item.ItemShield)5