Search in sources :

Example 11 with ItemSword

use of net.minecraft.item.ItemSword in project Cavern2 by kegare.

the class MiningAssistEventHooks method onAttackEntity.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onAttackEntity(AttackEntityEvent event) {
    EntityPlayer player = event.getEntityPlayer();
    MiningAssist assist = MiningAssist.byPlayer(player);
    if (assist != MiningAssist.AUTO && assist != MiningAssist.AUTO_QUICK && assist != MiningAssist.AUTO_ADIT) {
        return;
    }
    ItemStack heldMain = player.getHeldItemMainhand();
    ItemStack heldOff = player.getHeldItemOffhand();
    if (heldMain.getItem() instanceof ItemSword) {
        return;
    }
    if (heldOff.getItem() instanceof ItemSword) {
        player.setHeldItem(EnumHand.OFF_HAND, heldMain);
        player.setHeldItem(EnumHand.MAIN_HAND, heldOff);
        return;
    }
    NonNullList<ItemStack> mainInventory = player.inventory.mainInventory;
    int slot = -1;
    for (int i = 0, size = mainInventory.size(); i < size; ++i) {
        if (mainInventory.get(i).getItem() instanceof ItemSword) {
            slot = i;
            break;
        }
    }
    if (slot >= 0) {
        ItemStack prev = player.inventory.getCurrentItem();
        player.inventory.setInventorySlotContents(player.inventory.currentItem, player.inventory.getStackInSlot(slot));
        player.inventory.setInventorySlotContents(slot, prev);
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) MiningAssist(cavern.miningassist.MiningAssist) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 12 with ItemSword

use of net.minecraft.item.ItemSword in project baritone by cabaletta.

the class ToolSet method getBestSlot.

public int getBestSlot(Block b, boolean preferSilkTouch, boolean pathingCalculation) {
    /*
        If we actually want know what efficiency our held item has instead of the best one
        possible, this lets us make pathing depend on the actual tool to be used (if auto tool is disabled)
        */
    if (!Baritone.settings().autoTool.value && pathingCalculation) {
        return player.inventory.currentItem;
    }
    int best = 0;
    double highestSpeed = Double.NEGATIVE_INFINITY;
    int lowestCost = Integer.MIN_VALUE;
    boolean bestSilkTouch = false;
    IBlockState blockState = b.getDefaultState();
    for (int i = 0; i < 9; i++) {
        ItemStack itemStack = player.inventory.getStackInSlot(i);
        if (!Baritone.settings().useSwordToMine.value && itemStack.getItem() instanceof ItemSword) {
            continue;
        }
        if (Baritone.settings().itemSaver.value && (itemStack.getItemDamage() + Baritone.settings().itemSaverThreshold.value) >= itemStack.getMaxDamage() && itemStack.getMaxDamage() > 1) {
            continue;
        }
        double speed = calculateSpeedVsBlock(itemStack, blockState);
        boolean silkTouch = hasSilkTouch(itemStack);
        if (speed > highestSpeed) {
            highestSpeed = speed;
            best = i;
            lowestCost = getMaterialCost(itemStack);
            bestSilkTouch = silkTouch;
        } else if (speed == highestSpeed) {
            int cost = getMaterialCost(itemStack);
            if ((cost < lowestCost && (silkTouch || !bestSilkTouch)) || (preferSilkTouch && !bestSilkTouch && silkTouch)) {
                highestSpeed = speed;
                best = i;
                lowestCost = cost;
                bestSilkTouch = silkTouch;
            }
        }
    }
    return best;
}
Also used : ItemSword(net.minecraft.item.ItemSword) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack)

Example 13 with ItemSword

use of net.minecraft.item.ItemSword in project nebula by Sxmurai.

the class AutoTotem method onTick.

@Override
public void onTick() {
    if (!taskHandler.execute(delay.getValue() * 50L, await.getValue())) {
        return;
    } else {
        item = null;
    }
    if (willDieUponFall() || EntityUtil.getHealth(mc.player) <= health.getValue()) {
        item = Items.TOTEM_OF_UNDYING;
    } else {
        if (InventoryUtil.getHeld(EnumHand.MAIN_HAND).getItem() instanceof ItemSword && gap.getValue() && mc.gameSettings.keyBindUseItem.isKeyDown()) {
            item = Items.GOLDEN_APPLE;
        } else {
            item = mode.getValue().item;
        }
    }
    if (InventoryUtil.getHeld(EnumHand.OFF_HAND).getItem().equals(item)) {
        return;
    }
    int slot = InventoryUtil.getSlot(InventorySpace.BOTH, (s) -> !s.isEmpty() && s.getItem().equals(item));
    if (slot != -1) {
        int packetSlotId = InventoryUtil.toPacketSlot(slot);
        taskHandler.addTask(new InventoryTask(packetSlotId, ClickType.PICKUP));
        taskHandler.addTask(new InventoryTask(InventoryUtil.OFFHAND_SLOT, ClickType.PICKUP));
        if (!InventoryUtil.getHeld(EnumHand.OFF_HAND).isEmpty()) {
            taskHandler.addTask(new InventoryTask(packetSlotId, ClickType.PICKUP));
        }
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) InventoryTask(cope.nebula.util.world.entity.player.inventory.task.InventoryTask)

Example 14 with ItemSword

use of net.minecraft.item.ItemSword in project BetterRain by OreCruncher.

the class EnvironStateHandler method onItemUse.

@SubscribeEvent
public void onItemUse(final AttackEntityEvent event) {
    if (SWORD == null || event.entityPlayer == null || event.entityPlayer.worldObj == null)
        return;
    if (event.entityPlayer.worldObj.isRemote && EnvironState.isPlayer(event.entityPlayer)) {
        final ItemStack currentItem = event.entityPlayer.getCurrentEquippedItem();
        if (currentItem != null) {
            SoundEffect sound = null;
            final Item item = currentItem.getItem();
            if (item instanceof ItemSword)
                sound = SWORD;
            else if (item instanceof ItemAxe)
                sound = AXE;
            if (sound != null)
                SoundManager.playSoundAtPlayer(EnvironState.getPlayer(), sound);
        }
    }
}
Also used : SoundEffect(org.blockartistry.mod.DynSurround.client.sound.SoundEffect) ItemSword(net.minecraft.item.ItemSword) Item(net.minecraft.item.Item) ItemAxe(net.minecraft.item.ItemAxe) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 15 with ItemSword

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

the class PlayerControllerMP method onPlayerDestroyBlock.

/**
 * Called when a player completes the destruction of a block
 */
public boolean onPlayerDestroyBlock(BlockPos pos, EnumFacing side) {
    if (this.currentGameType.isAdventure()) {
        if (this.currentGameType == WorldSettings.GameType.SPECTATOR) {
            return false;
        }
        if (!this.mc.thePlayer.isAllowEdit()) {
            Block block = this.mc.theWorld.getBlockState(pos).getBlock();
            ItemStack itemstack = this.mc.thePlayer.getCurrentEquippedItem();
            if (itemstack == null) {
                return false;
            }
            if (!itemstack.canDestroy(block)) {
                return false;
            }
        }
    }
    if (this.currentGameType.isCreative() && this.mc.thePlayer.getHeldItem() != null && this.mc.thePlayer.getHeldItem().getItem() instanceof ItemSword) {
        return false;
    } else {
        World world = this.mc.theWorld;
        IBlockState iblockstate = world.getBlockState(pos);
        Block block1 = iblockstate.getBlock();
        if (block1.getMaterial() == Material.air) {
            return false;
        } else {
            world.playAuxSFX(2001, pos, Block.getStateId(iblockstate));
            boolean flag = world.setBlockToAir(pos);
            if (flag) {
                block1.onBlockDestroyedByPlayer(world, pos, iblockstate);
            }
            this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
            if (!this.currentGameType.isCreative()) {
                ItemStack itemstack1 = this.mc.thePlayer.getCurrentEquippedItem();
                if (itemstack1 != null) {
                    itemstack1.onBlockDestroyed(world, block1, pos, this.mc.thePlayer);
                    if (itemstack1.stackSize == 0) {
                        this.mc.thePlayer.destroyCurrentEquippedItem();
                    }
                }
            }
            return flag;
        }
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World)

Aggregations

ItemSword (net.minecraft.item.ItemSword)63 ItemStack (net.minecraft.item.ItemStack)41 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 Entity (net.minecraft.entity.Entity)12 IBlockState (net.minecraft.block.state.IBlockState)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