Java Code Examples for net.minecraft.entity.player.EntityPlayer#getHeldItemMainhand()

The following examples show how to use net.minecraft.entity.player.EntityPlayer#getHeldItemMainhand() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockKitunebi.java    From Sakura_mod with MIT License 6 votes vote down vote up
private void setVisibleFlg(World world, BlockPos pos,IBlockState state) {
    world.setBlockState(pos, state.withProperty(ISVISIBLE, false));
	EntityPlayer player = world.getClosestPlayer(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, 5.0D, false);
	if(player ==null){
		world.setBlockState(pos, state.withProperty(ISVISIBLE, false));
		return;
	}
    ItemStack is = player.getHeldItemMainhand();
    ItemStack offis =player.getHeldItemOffhand();
    if (!is.isEmpty()||!offis.isEmpty()) {
    	Item mainItem = is.getItem(),offItem=offis.getItem();
        if (mainItem instanceof ItemBlock||offItem instanceof ItemBlock) {
            if (Block.getBlockFromItem(mainItem) == this||Block.getBlockFromItem(offItem) == this) {
                world.setBlockState(pos, state.withProperty(ISVISIBLE, true));
            }
        }
    }
}
 
Example 2
Source File: ItemHandUpgrade.java    From Cyberware with MIT License 6 votes vote down vote up
@SubscribeEvent
public void handleMining(HarvestCheck event)
{
	EntityPlayer p = event.getEntityPlayer();
	ItemStack test = new ItemStack(this, 1, 2);
	boolean rightArm = (p.getPrimaryHand() == EnumHandSide.RIGHT ? 
			(CyberwareAPI.isCyberwareInstalled(p, new ItemStack(CyberwareContent.cyberlimbs, 1, 1))) : 
			(CyberwareAPI.isCyberwareInstalled(p, new ItemStack(CyberwareContent.cyberlimbs, 1, 0))));
	if (rightArm && CyberwareAPI.isCyberwareInstalled(p, test) && p.getHeldItemMainhand() == null)
	{
		ItemStack pick = new ItemStack(Items.STONE_PICKAXE);
		if (pick.canHarvestBlock(event.getTargetBlock()))
		{
			event.setCanHarvest(true);
		}
	}
}
 
Example 3
Source File: EntityFairy.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@NotNull
@Override
public EnumActionResult applyPlayerInteraction(EntityPlayer player, Vec3d vec, EnumHand hand) {
	ItemStack heldItem = player.getHeldItemMainhand();
	if (heldItem.getItem() == ModItems.JAR_ITEM && heldItem.getItemDamage() == 0) {
		succFairy(heldItem, player);
		return EnumActionResult.SUCCESS;
	} else if (!heldItem.isEmpty() && heldItem.getItem() != ModItems.FAIRY_BELL) {

		ResourceLocation task = FairyTaskRegistry.getAcceptableTask(heldItem, this);
		if (task != IDLE_TASK) {
			fairyTaskController.setTask(this, task);
			playSound(ModSounds.POSITIVE_LIGHT_TWINKLE, 1f, RandUtil.nextFloat());
			heldItem.shrink(1);
		} else playSound(ModSounds.NEGATIVELY_PITCHED_BREATHE_PUHH, 1, RandUtil.nextFloat());
		return EnumActionResult.SUCCESS;
	}
	return super.applyPlayerInteraction(player, vec, hand);
}
 
Example 4
Source File: IPearlStorageHolder.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Moves all pearls from the player's inv to this storage holder's inventory.
 * <p>
 * returns if any pearls were succeed in to indicate that the storage holder has been updated.
 */
default boolean succPearls(EntityPlayer player) {
	ItemStack belt = player.getHeldItemMainhand();
	if (isDisabled(belt)) return false;

	boolean changed = false;
	for (ItemStack stack : player.inventory.mainInventory)
		if (stack.getItem() == ModItems.PEARL_NACRE)
			if (NBTHelper.getBoolean(stack, "infused", false)) {
				if (getPearlCount(belt) >= ConfigValues.pearlBeltInvSize) break;

				if (addPearl(belt, stack.copy(), true)) {
					stack.shrink(1);
					changed = true;
				}
			}

	return changed;
}
 
Example 5
Source File: RenderEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void renderPlacementPropertiesHud(EntityPlayer player)
{
    ItemStack stack = player.getHeldItemMainhand();

    if (stack.isEmpty() || (stack.getItem() instanceof ItemBlockEnderUtilities) == false)
    {
        stack = player.getHeldItemOffhand();
    }

    if (stack.isEmpty() == false && stack.getItem() instanceof ItemBlockPlacementProperty)
    {
        ItemBlockPlacementProperty item = (ItemBlockPlacementProperty) stack.getItem();

        if (item.hasPlacementProperty(stack))
        {
            renderText(this.getPlacementPropertiesText(item, stack, player), 4, 0, HudAlignment.BOTTOM_LEFT, true, true, this.mc);
        }
    }
}
 
Example 6
Source File: GTItemSprayCan.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer playerIn, World world, BlockPos pos, EnumFacing side,
		float hitX, float hitY, float hitZ, EnumHand handIn) {
	if (!playerIn.isSneaking() && handIn == EnumHand.MAIN_HAND) {
		ItemStack playerStack = playerIn.getHeldItemMainhand();
		NBTTagCompound nbt = StackUtil.getNbtData(playerStack);
		if (nbt.hasKey(COLOR)) {
			EnumDyeColor dye = EnumDyeColor.byDyeDamage(nbt.getInteger(COLOR));
			if (colorBlock(world.getBlockState(pos), world, pos, null, dye)) {
				if (playerStack.getItemDamage() < playerStack.getMaxDamage()) {
					playerStack.damageItem(1, playerIn);
					if (!IC2.platform.isSimulating()) {
						IC2.audioManager.playOnce(playerIn, Ic2Sounds.painterUse);
					}
				} else {
					playerIn.setHeldItem(handIn, GTMaterialGen.get(GTItems.sprayCanEmpty));
					if (!IC2.platform.isSimulating()) {
						playerIn.playSound(SoundEvents.ENTITY_ITEM_BREAK, 1.0F, 1.0F);
					}
				}
				return EnumActionResult.SUCCESS;
			}
		}
	}
	return EnumActionResult.PASS;
}
 
Example 7
Source File: PipeBasic.java    From Logistics-Pipes-2 with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
		EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY) {
	super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY);
	if(playerIn.getHeldItemMainhand()==null) {
		TileEntity target = worldIn.getTileEntity(pos);
		if(target instanceof TileBasicPipe) {
			if(((TileBasicPipe) target).hasNetwork()) {
				//Add Debug routing on Activation
				return true;
			}
		}
	}
	
	return false;
}
 
Example 8
Source File: DataHelper.java    From GokiStats with MIT License 6 votes vote down vote up
public static float getDamageDealt(EntityPlayer player, Entity target, DamageSource source) {
    float damage = (float) player.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
    float bonusDamage = 0.0F;
    boolean targetIsLiving = target instanceof EntityLivingBase;
    boolean critical;
    ItemStack stack = player.getHeldItemMainhand();
    if (targetIsLiving) {
        bonusDamage = EnchantmentHelper.getModifierForCreature(stack, ((EntityLivingBase) target).getCreatureAttribute());
    }
    if ((damage > 0.0F) || (bonusDamage > 0.0F)) {
        critical = (player.fallDistance > 0.0F) && (!player.onGround) && (!player.isOnLadder()) && (!player.isInWater()) && (!player.isPotionActive(Potion.getPotionFromResourceLocation("blindness"))) && (player.getRidingEntity() == null) && (targetIsLiving);
        if ((critical) && (damage > 0.0F)) {
            damage *= 1.5F;
        }
        damage += bonusDamage;
    }
    return damage;
}
 
Example 9
Source File: ItemHandUpgrade.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleMineSpeed(BreakSpeed event)
{
	EntityPlayer p = event.getEntityPlayer();
	ItemStack test = new ItemStack(this, 1, 2);
	boolean rightArm = (p.getPrimaryHand() == EnumHandSide.RIGHT ? 
					(CyberwareAPI.isCyberwareInstalled(p, new ItemStack(CyberwareContent.cyberlimbs, 1, 1))) : 
					(CyberwareAPI.isCyberwareInstalled(p, new ItemStack(CyberwareContent.cyberlimbs, 1, 0))));
	if (rightArm && CyberwareAPI.isCyberwareInstalled(p, test) && p.getHeldItemMainhand() == null)
	{
		ItemStack pick = new ItemStack(Items.STONE_PICKAXE);
		event.setNewSpeed(event.getNewSpeed() * pick.getStrVsBlock(p.worldObj.getBlockState(event.getPos())));
	}
}
 
Example 10
Source File: PeekCommand.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
private ItemStack getHeldShulker(EntityPlayer entity) {
    if(entity.getHeldItemMainhand() != null && entity.getHeldItemMainhand().getItem() instanceof ItemShulkerBox) {
        return entity.getHeldItemMainhand();
    }
    if(entity.getHeldItemOffhand() != null && entity.getHeldItemOffhand().getItem() instanceof ItemShulkerBox) {
        return entity.getHeldItemOffhand();
    }
    return null;
}
 
Example 11
Source File: DataManager.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void setHeldItemAsTool()
{
    EntityPlayer player = Minecraft.getMinecraft().player;

    if (player != null)
    {
        ItemStack stack = player.getHeldItemMainhand();
        toolItem = stack.isEmpty() ? ItemStack.EMPTY : stack.copy();
        String cfgStr = "";

        if (stack.isEmpty() == false)
        {
            cfgStr = Item.REGISTRY.getNameForObject(stack.getItem()).toString();
            NBTTagCompound nbt = stack.getTagCompound();

            if (stack.isItemStackDamageable() == false || nbt != null)
            {
                cfgStr += "@" + stack.getMetadata();

                if (nbt != null)
                {
                    cfgStr += nbt.toString();
                }
            }
        }

        Configs.Generic.TOOL_ITEM.setValueFromString(cfgStr);
        InfoUtils.printActionbarMessage("litematica.message.set_currently_held_item_as_tool");
    }
}
 
Example 12
Source File: GuiHandler.java    From AgriCraft with MIT License 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public Gui getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
    switch (ID) {
        case (ANALYZER_GUI_ID):
            if (te instanceof TileEntitySeedAnalyzer) {
                return new AgriGuiWrapper(new GuiSeedAnalyzer(player.inventory, (TileEntitySeedAnalyzer) te));
            }
        case (JOURNAL_GUI_ID):
            if (StackHelper.isValid(player.getHeldItemMainhand(), ItemJournal.class)) {
                return new AgriGuiWrapper(new GuiJournal(player.getHeldItemMainhand()));
            }
        case (SEED_STORAGE_GUI_ID):
            if (te instanceof TileEntitySeedStorage) {
                return new AgriGuiWrapper(new GuiSeedStorage(player.inventory, (TileEntitySeedStorage) te));
            }
        case (SEED_CONTROLLER_GUI_ID):
            if (te instanceof TileEntitySeedStorageController) {
                return new AgriGuiWrapper(new GuiSeedStorageController(player.inventory, (TileEntitySeedStorageController) te));
            }
        case (PERIPHERAL_GUI_ID):
            if (te instanceof TileEntityPeripheral) {
                return new GuiPeripheral(player.inventory, (TileEntityPeripheral) te);
            }
        default:
            return null;
    }
}
 
Example 13
Source File: PacketKeyMessageHandler.java    From Sakura_mod with MIT License 5 votes vote down vote up
public boolean isPlayerHoldingSheath(EntityPlayer player) {

		if (!(!player.getHeldItemMainhand().isEmpty() || !player.getHeldItemOffhand().isEmpty())) {
			return false;
		}
		ItemStack heldItem = player.getHeldItemMainhand();
		if (heldItem.getItem() instanceof ItemSheath) {
			return true;
		}
		heldItem = player.getHeldItemOffhand();
		return heldItem.getItem() instanceof ItemSheath;
	}
 
Example 14
Source File: EntityEndermanFighter.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean isPlayerHoldingSummonItem(EntityPlayer player)
{
    ItemStack stack = player.getHeldItemMainhand();

    return stack.isEmpty() == false &&
           stack.getItem() == EnderUtilitiesItems.ENDER_SWORD &&
           ItemEnderSword.SwordMode.fromStack(stack) == ItemEnderSword.SwordMode.SUMMON;
}
 
Example 15
Source File: PacketUpdateTicket.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleServerSide(EntityPlayer player){
    ItemStack stack = player.getHeldItemMainhand();
    if(stack.getItem() == ModItems.TICKET) {
        CapabilityMinecartDestination cap = stack.getCapability(CapabilityMinecartDestination.INSTANCE, null);
        if(cap != null) {
            cap.setText(0, destinations);
            ItemTicket.writeNBTFromCap(stack);
            if(!"".equals(itemName)) stack.setStackDisplayName(itemName);
        }
    }
}
 
Example 16
Source File: Hydroponic.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
        EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {

    if (worldIn.isRemote) {
        return true;
    }

    HydroponicTileEntity tileEntity = (HydroponicTileEntity) worldIn.getTileEntity(pos);
    ItemStack itemStackHeld = playerIn.getHeldItemMainhand();
    Item itemHeld = itemStackHeld.getItem();

    if (itemHeld == Items.WATER_BUCKET || itemHeld == Items.LAVA_BUCKET) {

        Fluid fluid = itemHeld == Items.WATER_BUCKET ? FluidRegistry.WATER : FluidRegistry.LAVA;

        int waterFilled = tileEntity.fluidHandler.fill(new FluidStack(fluid, 1000), true);
        
        if (waterFilled > 0 && !playerIn.isCreative()) {
            playerIn.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.BUCKET));
        }

    } else if (itemHeld instanceof UniversalBucket) {

        UniversalBucket bucket = (UniversalBucket) itemHeld;
        FluidStack fluidStack = bucket.getFluid(itemStackHeld);

        if (tileEntity.fluidHandler.canFillFluidType(fluidStack)) {
            tileEntity.fluidHandler.fill(fluidStack, true);
            playerIn.setHeldItem(EnumHand.MAIN_HAND, bucket.getEmpty());
        }

    } else if (HydroponicHelper.isItemStackValid(itemStackHeld) && tileEntity.itemHandler.getStackInSlot(0).isEmpty()) {

        ItemStack remainder = tileEntity.itemHandler.insertItem(0, itemStackHeld.copy(), false);

        if (!playerIn.isCreative()) {
            playerIn.setHeldItem(EnumHand.MAIN_HAND, remainder);
        }

        return true;

    } else if (PlantHelper.isPlantItem(itemHeld) && facing == EnumFacing.UP) {

        return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);

        // Otherwise open the gui
    } else {
        playerIn.openGui(EmergingTechnology.instance, Reference.GUI_HYDROPONIC, worldIn, pos.getX(), pos.getY(),
                pos.getZ());
        return true;
    }

    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
 
Example 17
Source File: PlayerEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event)
{
    EntityPlayer player = event.getEntityPlayer();
    // You can only left click with the main hand, so this is fine here
    ItemStack stack = player.getHeldItemMainhand();
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    EnumFacing face = event.getFace();

    if (stack.isEmpty() == false)
    {
        if (stack.getItem() == EnderUtilitiesItems.BUILDERS_WAND)
        {
            ((ItemBuildersWand) stack.getItem()).onLeftClickBlock(player, world, stack, pos, world.provider.getDimension(), face);
            event.setCanceled(true);
            return;
        }
        else if (stack.getItem() == EnderUtilitiesItems.RULER)
        {
            ((ItemRuler) stack.getItem()).onLeftClickBlock(player, world, stack, pos, world.provider.getDimension(), face);
            event.setCanceled(true);
            return;
        }
        else if (player.capabilities.isCreativeMode == false && stack.getItem() == EnderUtilitiesItems.ENDER_TOOL)
        {
            if (player.getCooldownTracker().hasCooldown(stack.getItem()))
            {
                event.setCanceled(true);
                return;
            }
        }
    }

    if (world.getBlockState(pos).getBlock() == EnderUtilitiesBlocks.BARREL)
    {
        boolean takeItems = stack.isEmpty() || stack.getItem().getToolClasses(stack).contains("pickaxe") == false;

        if (player.capabilities.isCreativeMode)
        {
            TileEntityBarrel te = BlockEnderUtilities.getTileEntitySafely(world, pos, TileEntityBarrel.class);

            if (te == null || te.getLabeledFaces().contains(face) == false)
            {
                takeItems = false;
            }
        }

        if (takeItems)
        {
            if (world.isRemote)
            {
                int dim = world.provider.getDimension();
                int guiId = ReferenceGuiIds.GUI_ID_TILE_ENTITY_GENERIC;
                int fullStacks = Configs.barrelInversedSneak == player.isSneaking() ? 1 : 0;

                PacketHandler.INSTANCE.sendToServer(new MessageGuiAction(dim, pos, guiId, TileEntityBarrel.GUI_ACTION_TAKE_ITEMS, fullStacks));
            }

            event.setCanceled(true);
        }
    }
}
 
Example 18
Source File: AutoToolHack.java    From ForgeWurst with GNU General Public License v3.0 4 votes vote down vote up
public void equipBestTool(BlockPos pos, boolean useSwords, boolean useHands,
	boolean repairMode)
{
	EntityPlayer player = WMinecraft.getPlayer();
	if(player.capabilities.isCreativeMode)
		return;
	
	IBlockState state = BlockUtils.getState(pos);
	
	ItemStack heldItem = player.getHeldItemMainhand();
	float bestSpeed = getDestroySpeed(heldItem, state);
	int bestSlot = -1;
	
	int fallbackSlot = -1;
	InventoryPlayer inventory = player.inventory;
	
	for(int slot = 0; slot < 9; slot++)
	{
		if(slot == inventory.currentItem)
			continue;
		
		ItemStack stack = inventory.getStackInSlot(slot);
		
		if(fallbackSlot == -1 && !isDamageable(stack))
			fallbackSlot = slot;
		
		float speed = getDestroySpeed(stack, state);
		if(speed <= bestSpeed)
			continue;
		
		if(!useSwords && stack.getItem() instanceof ItemSword)
			continue;
		
		if(isTooDamaged(stack, repairMode))
			continue;
		
		bestSpeed = speed;
		bestSlot = slot;
	}
	
	boolean useFallback =
		isDamageable(heldItem) && (isTooDamaged(heldItem, repairMode)
			|| useHands && getDestroySpeed(heldItem, state) <= 1);
	
	if(bestSlot != -1)
	{
		inventory.currentItem = bestSlot;
		return;
	}
	
	if(!useFallback)
		return;
	
	if(fallbackSlot != -1)
	{
		inventory.currentItem = fallbackSlot;
		return;
	}
	
	if(isTooDamaged(heldItem, repairMode))
		if(inventory.currentItem == 8)
			inventory.currentItem = 0;
		else
			inventory.currentItem++;
}
 
Example 19
Source File: GuiPearlSwap.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void mouseClicked(int x, int y, int mouseButton) throws IOException {
	super.mouseClicked(x, y, mouseButton);

	if (mouseButton != 0 || lock) return;

	EntityPlayer player = Minecraft.getMinecraft().player;
	ItemStack heldItem = player.getHeldItemMainhand();

	ItemStack stack = getStorageHolderStack();
	if (stack.isEmpty()) return;
	IPearlStorageHolder holder = (IPearlStorageHolder) stack.getItem();

	IItemHandler handler = holder.getPearls(stack);
	if (handler == null) return;


	double mouseX = Mouse.getEventX() - mc.displayWidth / 2.0;
	double mouseY = (Mouse.getEventY() - mc.displayHeight / 2.0) * -1;

	Vec2d vec = new Vec2d(mouseX, mouseY);
	if (vec.length() <= componentCentralCircle.getSize().getX() * new ScaledResolution(Minecraft.getMinecraft()).getScaleFactor()) {

		if (heldItem.getItem() instanceof IPearlStorageHolder) {
			succPearlsToBelt();
		}

		return;
	}

	double relativeMX = (Mouse.getEventX() / (double) this.mc.displayWidth) / 0.5 - 1;
	double relativeMY = ((Mouse.getEventY() / (double) this.mc.displayHeight) / 0.5 - 1) * -1;
	if (mc.displayWidth > mc.displayHeight) {
		relativeMY *= this.mc.displayHeight / (double) this.mc.displayWidth;
	} else if (mc.displayHeight > mc.displayWidth) {
		relativeMX *= mc.displayWidth / (double) mc.displayHeight;
	}
	double pointerAngle = (Math.atan2(relativeMY, relativeMX) + (PI * 2)) % (PI * 2.0);

	int pearlCount = Math.max(holder.getPearlCount(stack), 0);
	if (pearlCount != 0) {

		double anglePerColor = 2.0 * PI / (double) pearlCount;
		int pointerIndex = (int) (pointerAngle / anglePerColor);

		if (heldItem.getItem() instanceof IPearlStorageHolder) {
			popPearlFromBelt(pointerIndex);
		} else if (heldItem.getItem() instanceof IPearlSwappable) {
			swapPearl(pointerIndex);
		}
	}
}
 
Example 20
Source File: ItemMuscleUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent
public void handleHurt(LivingHurtEvent event)
{
	EntityLivingBase e = event.getEntityLiving();

	ItemStack test = new ItemStack(this, 1, 0);
	int rank = CyberwareAPI.getCyberwareRank(e, test);
	if (!event.isCanceled() && e instanceof EntityPlayer && (rank > 1) && EnableDisableHelper.isEnabled(CyberwareAPI.getCyberware(e, test)) && getLastBoostSpeed(e))
	{
		EntityPlayer p = (EntityPlayer) e;
		if (event.getSource() instanceof EntityDamageSource && !(event.getSource() instanceof EntityDamageSourceIndirect))
		{
			EntityDamageSource source = (EntityDamageSource) event.getSource();
			Entity attacker = source.getEntity();
			int lastAttacked = ReflectionHelper.getPrivateValue(CombatTracker.class, p.getCombatTracker(), 2);
			
			if (p.ticksExisted - lastAttacked > 120)
			{
				ItemStack weapon = p.getHeldItemMainhand();
				int loc = -1;
				if (weapon != null)
				{
					if (p.getItemInUseCount() > 0 || weapon.getItem() instanceof ItemSword || weapon.getItem().getAttributeModifiers(EntityEquipmentSlot.MAINHAND, weapon).containsKey(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName()))
					{
						loc = p.inventory.currentItem;
					}
				}
				
				if (loc == -1)
				{
					double mostDamage = 0F;
					
					for (int i = 0; i < 10; i++)
					{
						if (i != p.inventory.currentItem)
						{
							ItemStack potentialWeapon = p.inventory.mainInventory[i];
							if (potentialWeapon != null)
							{
								Multimap<String, AttributeModifier> modifiers = potentialWeapon.getItem().getAttributeModifiers(EntityEquipmentSlot.MAINHAND, potentialWeapon);
								if (modifiers.containsKey(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName()))
								{
									double damage = modifiers.get(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName()).iterator().next().getAmount();
									
									if (damage > mostDamage || loc == -1)
									{
										mostDamage = damage;
										loc = i;
									}
								}
							}
						}
					}
				}
				
				if (loc != -1)
				{
					//System.out.println("LOC " + loc);

					p.inventory.currentItem = loc;

		
					CyberwarePacketHandler.INSTANCE.sendTo(new SwitchHeldItemAndRotationPacket(loc, p.getEntityId(), rank > 2 ? attacker.getEntityId() : -1), (EntityPlayerMP) p);
					
					WorldServer world = (WorldServer) p.worldObj;
					
					for (EntityPlayer trackingPlayer : world.getEntityTracker().getTrackingPlayers(p))
					{
						CyberwarePacketHandler.INSTANCE.sendTo(new SwitchHeldItemAndRotationPacket(loc, p.getEntityId(), rank > 2 ? attacker.getEntityId() : -1), (EntityPlayerMP) trackingPlayer);
					}
					
				}
			}

		}

	}
}