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);
}
}
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;
}
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));
}
}
}
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);
}
}
}
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;
}
}
}
Aggregations