use of net.minecraft.item.ItemSword in project PhoBOSS-1.9.1-public by somesadkidontop.
the class Offhand method doSwitch.
public void doSwitch() {
if (this.autoGapple.getValue().booleanValue()) {
if (Offhand.mc.gameSettings.keyBindUseItem.isKeyDown()) {
if (Offhand.mc.player.getHeldItemMainhand().getItem() instanceof ItemSword && (!this.onlyWTotem.getValue().booleanValue() || Offhand.mc.player.getHeldItemOffhand().getItem() == Items.TOTEM_OF_UNDYING)) {
this.setMode(Mode.GAPPLES);
this.autoGappleSwitch = true;
}
} else if (this.autoGappleSwitch) {
this.setMode(Mode2.TOTEMS);
this.autoGappleSwitch = false;
}
}
if (this.currentMode == Mode2.GAPPLES && ((!EntityUtil.isSafe(Offhand.mc.player) || this.bedPlaceable()) && EntityUtil.getHealth(Offhand.mc.player, this.absorption.getValue()) <= this.gappleHealth.getValue().floatValue() || EntityUtil.getHealth(Offhand.mc.player, this.absorption.getValue()) <= this.gappleHoleHealth.getValue().floatValue()) || this.currentMode == Mode2.CRYSTALS && ((!EntityUtil.isSafe(Offhand.mc.player) || this.bedPlaceable()) && EntityUtil.getHealth(Offhand.mc.player, this.absorption.getValue()) <= this.crystalHealth.getValue().floatValue() || EntityUtil.getHealth(Offhand.mc.player, this.absorption.getValue()) <= this.crystalHoleHealth.getValue().floatValue()) || this.currentMode == Mode2.OBSIDIAN && ((!EntityUtil.isSafe(Offhand.mc.player) || this.bedPlaceable()) && EntityUtil.getHealth(Offhand.mc.player, this.absorption.getValue()) <= this.obsidianHealth.getValue().floatValue() || EntityUtil.getHealth(Offhand.mc.player, this.absorption.getValue()) <= this.obsidianHoleHealth.getValue().floatValue()) || this.currentMode == Mode2.WEBS && ((!EntityUtil.isSafe(Offhand.mc.player) || this.bedPlaceable()) && EntityUtil.getHealth(Offhand.mc.player, this.absorption.getValue()) <= this.webHealth.getValue().floatValue() || EntityUtil.getHealth(Offhand.mc.player, this.absorption.getValue()) <= this.webHoleHealth.getValue().floatValue())) {
if (this.returnToCrystal.getValue().booleanValue() && this.currentMode == Mode2.CRYSTALS) {
this.switchedForHealthReason = true;
}
this.setMode(Mode2.TOTEMS);
}
if (this.switchedForHealthReason && (EntityUtil.isSafe(Offhand.mc.player) && !this.bedPlaceable() && EntityUtil.getHealth(Offhand.mc.player, this.absorption.getValue()) > this.crystalHoleHealth.getValue().floatValue() || EntityUtil.getHealth(Offhand.mc.player, this.absorption.getValue()) > this.crystalHealth.getValue().floatValue())) {
this.setMode(Mode2.CRYSTALS);
this.switchedForHealthReason = false;
}
if (Offhand.mc.currentScreen instanceof GuiContainer && !this.guis.getValue().booleanValue() && !(Offhand.mc.currentScreen instanceof GuiInventory)) {
return;
}
Item currentOffhandItem = Offhand.mc.player.getHeldItemOffhand().getItem();
switch(this.currentMode) {
case TOTEMS:
{
if (this.totems <= 0 || this.holdingTotem)
break;
this.lastTotemSlot = InventoryUtil.findItemInventorySlot(Items.TOTEM_OF_UNDYING, false);
int lastSlot = this.getLastSlot(currentOffhandItem, this.lastTotemSlot);
this.putItemInOffhand(this.lastTotemSlot, lastSlot);
break;
}
case GAPPLES:
{
if (this.gapples <= 0 || this.holdingGapple)
break;
this.lastGappleSlot = InventoryUtil.findItemInventorySlot(Items.GOLDEN_APPLE, false);
int lastSlot = this.getLastSlot(currentOffhandItem, this.lastGappleSlot);
this.putItemInOffhand(this.lastGappleSlot, lastSlot);
break;
}
case WEBS:
{
if (this.webs <= 0 || this.holdingWeb)
break;
this.lastWebSlot = InventoryUtil.findInventoryBlock(BlockWeb.class, false);
int lastSlot = this.getLastSlot(currentOffhandItem, this.lastWebSlot);
this.putItemInOffhand(this.lastWebSlot, lastSlot);
break;
}
case OBSIDIAN:
{
if (this.obby <= 0 || this.holdingObby)
break;
this.lastObbySlot = InventoryUtil.findInventoryBlock(BlockObsidian.class, false);
int lastSlot = this.getLastSlot(currentOffhandItem, this.lastObbySlot);
this.putItemInOffhand(this.lastObbySlot, lastSlot);
break;
}
default:
{
if (this.crystals <= 0 || this.holdingCrystal)
break;
this.lastCrystalSlot = InventoryUtil.findItemInventorySlot(Items.END_CRYSTAL, false);
int lastSlot = this.getLastSlot(currentOffhandItem, this.lastCrystalSlot);
this.putItemInOffhand(this.lastCrystalSlot, lastSlot);
}
}
for (int i = 0; i < this.actions.getValue(); ++i) {
InventoryUtil.Task task = this.taskList.poll();
if (task == null)
continue;
task.run();
if (!task.isSwitching())
continue;
this.didSwitchThisTick = true;
}
}
use of net.minecraft.item.ItemSword in project PhoBOSS-1.9.1-public by somesadkidontop.
the class BlockTweaks method equipBestWeapon.
public void equipBestWeapon(Entity entity) {
int bestSlot = -1;
double maxDamage = 0.0;
EnumCreatureAttribute creatureAttribute = EnumCreatureAttribute.UNDEFINED;
if (EntityUtil.isLiving(entity)) {
EntityLivingBase base = (EntityLivingBase) entity;
creatureAttribute = base.getCreatureAttribute();
}
for (int i = 0; i < 9; ++i) {
double damage;
ItemStack stack = BlockTweaks.mc.player.inventory.getStackInSlot(i);
if (stack.isEmpty)
continue;
if (stack.getItem() instanceof ItemTool) {
damage = (double) ((ItemTool) stack.getItem()).attackDamage + (double) EnchantmentHelper.getModifierForCreature(stack, creatureAttribute);
if (!(damage > maxDamage))
continue;
maxDamage = damage;
bestSlot = i;
continue;
}
if (!(stack.getItem() instanceof ItemSword) || !((damage = (double) ((ItemSword) stack.getItem()).getAttackDamage() + (double) EnchantmentHelper.getModifierForCreature(stack, creatureAttribute)) > maxDamage))
continue;
maxDamage = damage;
bestSlot = i;
}
this.equip(bestSlot, true);
}
use of net.minecraft.item.ItemSword in project kull by Sxmurai.
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;
}
}
}
use of net.minecraft.item.ItemSword in project kull by Sxmurai.
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();
}
}
}
use of net.minecraft.item.ItemSword in project clientcommands by Earthcomputer.
the class ToolDamageManager method getDestroyBlockDamage.
private static int getDestroyBlockDamage(World world, BlockPos pos, EntityPlayer player) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
ItemStack stack = player.getHeldItemMainhand();
Minecraft mc = Minecraft.getMinecraft();
// perform necessary extra checks
if (mc.playerController.getCurrentGameType().hasLimitedInteractions()) {
if (mc.playerController.getCurrentGameType() == GameType.SPECTATOR) {
return 0;
}
if (!player.isAllowEdit()) {
if (stack.isEmpty()) {
return 0;
}
if (!stack.canDestroy(block)) {
return 0;
}
}
}
if (block instanceof BlockCommandBlock || block instanceof BlockStructure) {
return 0;
}
if (state.getMaterial() == Material.AIR) {
return 0;
}
// perform the item use check on the item if necessary
if (!stack.isEmpty()) {
Item item = stack.getItem();
if (item instanceof ItemShears) {
return 1;
} else if (item instanceof ItemSword || item instanceof ItemTool) {
if (world.getBlockState(pos).getBlockHardness(world, pos) != 0) {
return item instanceof ItemSword ? 2 : 1;
}
}
}
return 0;
}
Aggregations