Search in sources :

Example 16 with ItemSword

use of net.minecraft.item.ItemSword in project UtilityClient2 by Utility-Client.

the class ItemInWorldManager method tryHarvestBlock.

/**
 * Attempts to harvest a block
 */
public boolean tryHarvestBlock(BlockPos pos) {
    if (this.gameType.isCreative() && this.thisPlayerMP.getHeldItem() != null && this.thisPlayerMP.getHeldItem().getItem() instanceof ItemSword) {
        return false;
    } else {
        IBlockState iblockstate = this.theWorld.getBlockState(pos);
        TileEntity tileentity = this.theWorld.getTileEntity(pos);
        if (this.gameType.isAdventure()) {
            if (this.gameType == WorldSettings.GameType.SPECTATOR) {
                return false;
            }
            if (!this.thisPlayerMP.isAllowEdit()) {
                ItemStack itemstack = this.thisPlayerMP.getCurrentEquippedItem();
                if (itemstack == null) {
                    return false;
                }
                if (!itemstack.canDestroy(iblockstate.getBlock())) {
                    return false;
                }
            }
        }
        this.theWorld.playAuxSFXAtEntity(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate));
        boolean flag1 = this.removeBlock(pos);
        if (this.isCreative()) {
            this.thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(this.theWorld, pos));
        } else {
            ItemStack itemstack1 = this.thisPlayerMP.getCurrentEquippedItem();
            boolean flag = this.thisPlayerMP.canHarvestBlock(iblockstate.getBlock());
            if (itemstack1 != null) {
                itemstack1.onBlockDestroyed(this.theWorld, iblockstate.getBlock(), pos, this.thisPlayerMP);
                if (itemstack1.stackSize == 0) {
                    this.thisPlayerMP.destroyCurrentEquippedItem();
                }
            }
            if (flag1 && flag) {
                iblockstate.getBlock().harvestBlock(this.theWorld, this.thisPlayerMP, pos, iblockstate, tileentity);
            }
        }
        return flag1;
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) TileEntity(net.minecraft.tileentity.TileEntity) S23PacketBlockChange(net.minecraft.network.play.server.S23PacketBlockChange) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack)

Example 17 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 18 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 19 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 20 with ItemSword

use of net.minecraft.item.ItemSword in project BapeClient by BapeDeveloperTeam.

the class Killaura method onTick.

@SubscribeEvent
public void onTick(TickEvent.PlayerTickEvent event) {
    float delays = new Random().nextInt(this.cps.getValue().intValue()) + 5;
    if (timer.delay(delays * 10)) {
        if (Client.nullCheck())
            return;
        for (Entity object : getEntityList()) {
            EntityLivingBase entity;
            if (!(object instanceof EntityLivingBase) || !this.check(entity = (EntityLivingBase) object))
                continue;
            target = entity;
        }
        if (target == null)
            return;
        if (AntiBot.isServerBot(target))
            return;
        if (Teams.isOnSameTeam(target))
            return;
        // return;
        if (target.getHealth() == 0)
            return;
        assistFaceEntity(target, this.yaw.getValue().floatValue(), this.pitch.getValue().floatValue());
        Object[] objects = mc.theWorld.loadedEntityList.stream().filter(entity -> entity instanceof EntityLivingBase && entity != mc.thePlayer && ((EntityLivingBase) entity).getHealth() > 0F && entity.getDistanceToEntity(mc.thePlayer) <= rangeValue.getValue()).sorted(Comparator.comparingDouble(entity -> entity.getDistanceToEntity(mc.thePlayer))).toArray();
        if (objects.length > 0)
            target = (EntityLivingBase) objects[0];
        if (ModuleManager.getModule("Criticals").getState() && Criticals.canJump() && mc.thePlayer.onGround)
            mc.thePlayer.jump();
        if (this.swing.getValue()) {
            mc.thePlayer.swingItem();
        }
        if (!target.isDead || target.getHealth() <= 0) {
            mc.getNetHandler().addToSendQueue(new C02PacketUseEntity(target, C02PacketUseEntity.Action.ATTACK));
        }
        if ((Boolean) this.autoblock.getValue()) {
            if (mc.thePlayer.getCurrentEquippedItem() == null) {
                return;
            }
            if (!(mc.thePlayer.getCurrentEquippedItem().getItem() instanceof ItemSword)) {
                return;
            }
            if (this.autoblock.getValue() && mc.objectMouseOver.entityHit != null && mc.objectMouseOver.entityHit.isEntityAlive()) {
                if (mc.thePlayer.getCurrentEquippedItem().getItem() instanceof ItemSword && timer.delay(100)) {
                    mc.thePlayer.getCurrentEquippedItem().useItemRightClick(mc.theWorld, mc.thePlayer);
                    timer.reset();
                }
            }
        }
        target = null;
        timer.reset();
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) C02PacketUseEntity(net.minecraft.network.play.client.C02PacketUseEntity) Entity(net.minecraft.entity.Entity) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) EntityLivingBase(net.minecraft.entity.EntityLivingBase) C02PacketUseEntity(net.minecraft.network.play.client.C02PacketUseEntity) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ItemSword (net.minecraft.item.ItemSword)60 ItemStack (net.minecraft.item.ItemStack)40 Item (net.minecraft.item.Item)23 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)23 EntityPlayer (net.minecraft.entity.player.EntityPlayer)20 ItemTool (net.minecraft.item.ItemTool)19 ItemHoe (net.minecraft.item.ItemHoe)17 IBlockState (net.minecraft.block.state.IBlockState)11 Entity (net.minecraft.entity.Entity)11 ItemBow (net.minecraft.item.ItemBow)11 ItemAxe (net.minecraft.item.ItemAxe)8 ItemFishingRod (net.minecraft.item.ItemFishingRod)6 DamageSource (net.minecraft.util.DamageSource)6 Block (net.minecraft.block.Block)5 EntityLivingBase (net.minecraft.entity.EntityLivingBase)5 ItemShield (net.minecraft.item.ItemShield)5 ItemSpade (net.minecraft.item.ItemSpade)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 EntityItem (net.minecraft.entity.item.EntityItem)4 ItemFlintAndSteel (net.minecraft.item.ItemFlintAndSteel)4