/** Handles a players right click */ public boolean onPlayerRightClick( EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack, int par4, int par5, int par6, int par7) { syncCurrentPlayItem(); netClientHandler.addToSendQueue( new Packet15Place(par4, par5, par6, par7, par1EntityPlayer.inventory.getCurrentItem())); int i = par2World.getBlockId(par4, par5, par6); if (i > 0 && Block.blocksList[i].blockActivated(par2World, par4, par5, par6, par1EntityPlayer)) { return true; } if (par3ItemStack == null) { return false; } if (creativeMode) { int j = par3ItemStack.getItemDamage(); int k = par3ItemStack.stackSize; boolean flag = par3ItemStack.useItem(par1EntityPlayer, par2World, par4, par5, par6, par7); par3ItemStack.setItemDamage(j); par3ItemStack.stackSize = k; return flag; } else { return par3ItemStack.useItem(par1EntityPlayer, par2World, par4, par5, par6, par7); } }
public void burn() { // Can't burn? Goodbye if (!canBurn()) { return; } ItemStack itemstack = getBurnResult(contents[0]); // Nothing in there? Then put something there. if (contents[2] == null) { contents[2] = itemstack.cloneItemStack(); } // Burn ahead else if (contents[2].doMaterialsMatch(itemstack)) { contents[2].count += itemstack.count; } // And consume the ingredient item // Goddamn, you have container functions, use them! Notch! if (contents[0].getItem().u()) // Derpnote { contents[0] = new ItemStack(contents[0].getItem().t()); // Derpnote } else { contents[0].count--; // Let 0 be null if (contents[0].count <= 0) { contents[0] = null; } } }
public float getCurrentPlayerStrVsBlock(Block par1Block, int meta) { ItemStack stack = inventory.getCurrentItem(); float var2 = (stack == null ? 1.0F : stack.getItem().getStrVsBlock(stack, par1Block, meta)); float var3 = var2; int var4 = EnchantmentHelper.getEfficiencyModifier(this.inventory); if (var4 > 0 && this.inventory.canHarvestBlock(par1Block)) { var3 = var2 + (float) (var4 * var4 + 1); } if (this.isPotionActive(Potion.digSpeed)) { var3 *= 1.0F + (float) (this.getActivePotionEffect(Potion.digSpeed).getAmplifier() + 1) * 0.2F; } if (this.isPotionActive(Potion.digSlowdown)) { var3 *= 1.0F - (float) (this.getActivePotionEffect(Potion.digSlowdown).getAmplifier() + 1) * 0.2F; } if (this.isInsideOfMaterial(Material.water) && !EnchantmentHelper.getAquaAffinityModifier(this.inventory)) { var3 /= 5.0F; } if (!this.onGround) { var3 /= 5.0F; } return var3; }
private boolean func_21137_a( InventoryCrafting p_21137_1_, int p_21137_2_, int p_21137_3_, boolean p_21137_4_) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { int k = i - p_21137_2_; int l = j - p_21137_3_; ItemStack itemstack = null; if (k >= 0 && l >= 0 && k < field_21138_b && l < field_21142_c) { if (p_21137_4_) { itemstack = field_21141_d[(field_21138_b - k - 1) + l * field_21138_b]; } else { itemstack = field_21141_d[k + l * field_21138_b]; } } ItemStack itemstack1 = p_21137_1_.func_21103_b(i, j); if (itemstack1 == null && itemstack == null) { continue; } if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null) { return false; } if (itemstack.field_1617_c != itemstack1.field_1617_c) { return false; } if (itemstack.func_21181_i() != -1 && itemstack.func_21181_i() != itemstack1.func_21181_i()) { return false; } } } return true; }
public boolean switchTools(ToolType tool) { MainPlayerEntity player = world.getBot().getPlayer(); if (player == null) return false; PlayerInventory inventory = player.getInventory(); ItemStack bestTool = null; int bestToolSlot = -1, bestToolValue = -1; for (int i = 0; i < 36; i++) { ItemStack item = inventory.getItemAt(i); if (tool == null) { if (i > 8) break; if (item == null || ToolType.getById(item.getId()) == null) { bestTool = item; bestToolSlot = i; break; } continue; } if (item == null) continue; ToolType toolType = ToolType.getById(item.getId()); if (toolType == null || toolType != tool) continue; int toolValue = getToolPriority(item.getId()); if (bestTool == null || toolValue > bestToolValue) { bestTool = item; bestToolSlot = i; bestToolValue = toolValue; } } if (bestToolSlot == -1) return false; return switchHeldItems(bestToolSlot); }
public void func_78441_a() { field_78451_d = field_78454_c; EntityClientPlayerMP entityclientplayermp = field_78455_a.field_71439_g; ItemStack itemstack = ((EntityPlayer) (entityclientplayermp)).field_71071_by.func_70448_g(); boolean flag = field_78450_g == ((EntityPlayer) (entityclientplayermp)).field_71071_by.field_70461_c && itemstack == field_78453_b; if (field_78453_b == null && itemstack == null) { flag = true; } if (itemstack != null && field_78453_b != null && itemstack != field_78453_b && itemstack.field_77993_c == field_78453_b.field_77993_c && itemstack.func_77960_j() == field_78453_b.func_77960_j()) { field_78453_b = itemstack; flag = true; } float f = 0.4F; float f1 = flag ? 1.0F : 0.0F; float f2 = f1 - field_78454_c; if (f2 < -f) { f2 = -f; } if (f2 > f) { f2 = f; } field_78454_c += f2; if (field_78454_c < 0.1F) { field_78453_b = itemstack; field_78450_g = ((EntityPlayer) (entityclientplayermp)).field_71071_by.field_70461_c; } }
public void updateEquippedItem() { this.prevEquippedProgress = this.equippedProgress; EntityPlayerSP var1 = this.mc.thePlayer; ItemStack var2 = var1.inventory.getCurrentItem(); boolean var4 = this.equippedItemSlot == var1.inventory.currentItem && var2 == this.itemToRender; if (this.itemToRender == null && var2 == null) { var4 = true; } if (var2 != null && this.itemToRender != null && var2 != this.itemToRender && var2.itemID == this.itemToRender.itemID && var2.getItemDamage() == this.itemToRender.getItemDamage()) { this.itemToRender = var2; var4 = true; } float var5 = 0.4F; float var6 = var4 ? 1.0F : 0.0F; float var7 = var6 - this.equippedProgress; if (var7 < -var5) { var7 = -var5; } if (var7 > var5) { var7 = var5; } this.equippedProgress += var7; if (this.equippedProgress < 0.1F) { this.itemToRender = var2; this.equippedItemSlot = var1.inventory.currentItem; } }
/** * Activate the clicked on block, otherwise use the held item. Args: player, world, itemStack, x, * y, z, side, xOffset, yOffset, zOffset */ public boolean activateBlockOrUseItem( EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { int var11 = par2World.getBlockId(par4, par5, par6); if (var11 > 0 && Block.blocksList[var11].onBlockActivated( par2World, par4, par5, par6, par1EntityPlayer, par7, par8, par9, par10)) { return true; } else if (par3ItemStack == null) { return false; } else if (this.isCreative()) { int var12 = par3ItemStack.getItemDamage(); int var13 = par3ItemStack.stackSize; boolean var14 = par3ItemStack.func_77943_a( par1EntityPlayer, par2World, par4, par5, par6, par7, par8, par9, par10); par3ItemStack.setItemDamage(var12); par3ItemStack.stackSize = var13; return var14; } else { return par3ItemStack.func_77943_a( par1EntityPlayer, par2World, par4, par5, par6, par7, par8, par9, par10); } }
public void dropRecord(World world, int i, int j, int k) { if (!world.isStatic) { TileEntityRecordPlayer tileentityrecordplayer = (TileEntityRecordPlayer) world.getTileEntity(i, j, k); if (tileentityrecordplayer != null) { ItemStack itemstack = tileentityrecordplayer.record; if (itemstack != null) { world.triggerEffect(1005, i, j, k, 0); world.a((String) null, i, j, k); tileentityrecordplayer.record = null; tileentityrecordplayer.update(); world.setData(i, j, k, 0); float f = 0.7F; double d0 = (double) (world.random.nextFloat() * f) + (double) (1.0F - f) * 0.5D; double d1 = (double) (world.random.nextFloat() * f) + (double) (1.0F - f) * 0.2D + 0.6D; double d2 = (double) (world.random.nextFloat() * f) + (double) (1.0F - f) * 0.5D; ItemStack itemstack1 = itemstack.cloneItemStack(); EntityItem entityitem = new EntityItem(world, (double) i + d0, (double) j + d1, (double) k + d2, itemstack1); entityitem.pickupDelay = 10; world.addEntity(entityitem); } } } }
@Override public void detectAndSendChanges() { for (int var1 = 0; var1 < this.inventorySlots.size(); ++var1) { ItemStack var2 = ((Slot) this.inventorySlots.get(var1)).getStack(); ItemStack var3 = (ItemStack) this.inventoryItemStacks.get(var1); if (!ItemStack.areItemStacksEqual(var3, var2)) { var3 = var2 == null ? null : var2.copy(); this.inventoryItemStacks.set(var1, var3); for (int var4 = 0; var4 < this.crafters.size(); ++var4) { ((ICrafting) this.crafters.get(var4)).sendSlotContents(this, var1, var3); } } } for (int var1 = 0; var1 < this.crafters.size(); ++var1) { ICrafting var2 = (ICrafting) this.crafters.get(var1); if (this.soilamt != this.sluice.soilAmount) { var2.sendProgressBarUpdate(this, 0, this.sluice.soilAmount); } if (this.progress != this.sluice.processTimeRemaining) { var2.sendProgressBarUpdate(this, 1, this.sluice.processTimeRemaining); } } soilamt = this.sluice.soilAmount; progress = this.sluice.processTimeRemaining; }
public boolean hitEntity(ItemStack itemstack, EntityLiving mob, EntityLiving entityliving1) { World world = entityliving1.worldObj; if (type1 == type2) { attacks(itemstack, world, entityliving1, mob, type1); } else { if (random.nextInt(100) + 1 <= 80) { attacks(itemstack, world, entityliving1, mob, type1); } if (random.nextInt(100) + 1 <= 20) { attacks(itemstack, world, entityliving1, mob, type2); } } int i = itemstack.getItemDamage(); if (i >= dur) { itemstack.stackSize = 0; } if (type1 == 3 || type2 == 3 || type1 == 4 || type2 == 4 || type1 == 8 || type2 == 8) { if (random.nextInt(100) + 1 <= 90) { itemstack.damageItem(1, entityliving1); } } else { itemstack.damageItem(1, entityliving1); } return true; }
public float checkTemps(IInventory inv) { float temp = 0; float[] temp1 = new float[inv.getSizeInventory()]; for (int i = 0; i < inv.getSizeInventory(); i++) { ItemStack is = inv.getStackInSlot(i); if (is != null && is.hasTagCompound() && !is.getItem().getUnlocalizedName(is).contains("Clay")) { if (is.getTagCompound().hasKey("temperature")) { temp1[i] = is.getTagCompound().getFloat("temperature"); if (temp1[i] < TFC_ItemHeat.getMeltingPoint(is)) { return (float) -1; } } else { return (float) -1; } } else if (is == null) { temp1[i] = -1; } } int temp2 = 0; for (int i = 0; i < inv.getSizeInventory(); i++) { if (temp1[i] >= 0) { temp += temp1[i]; temp2++; } } if (temp2 > 0) { temp /= temp2; } return temp; }
public void setItem(ItemStack itemstack) { itemstack = itemstack.cloneItemStack(); itemstack.count = 1; itemstack.a(this); this.getDataWatcher().watch(2, itemstack); this.getDataWatcher().h(2); }
/** * Clear this player's inventory, using the specified ID and metadata as filters or -1 for no * filter. */ public int clearInventory(int par1, int par2) { int var3 = 0; int var4; ItemStack var5; for (var4 = 0; var4 < this.mainInventory.length; ++var4) { var5 = this.mainInventory[var4]; if (var5 != null && (par1 <= -1 || var5.itemID == par1) && (par2 <= -1 || var5.getItemDamage() == par2)) { var3 += var5.stackSize; this.mainInventory[var4] = null; } } for (var4 = 0; var4 < this.armorInventory.length; ++var4) { var5 = this.armorInventory[var4]; if (var5 != null && (par1 <= -1 || var5.itemID == par1) && (par2 <= -1 || var5.getItemDamage() == par2)) { var3 += var5.stackSize; this.armorInventory[var4] = null; } } return var3; }
/** Set the specified armor model as the player model. Args: player, armorSlot, partialTick */ protected int setArmorModel(EntityPlayer par1EntityPlayer, int par2, float par3) { ItemStack itemstack = par1EntityPlayer.inventory.armorItemInSlot(3 - par2); if (itemstack != null) { Item item = itemstack.getItem(); if (item instanceof ItemArmor) { ItemArmor itemarmor = (ItemArmor) item; loadTexture( (new StringBuilder()) .append("/armor/") .append(armorFilenamePrefix[itemarmor.renderIndex]) .append("_") .append(par2 != 2 ? 1 : 2) .append(".png") .toString()); ModelBiped modelbiped = par2 != 2 ? modelArmorChestplate : modelArmor; modelbiped.bipedHead.showModel = par2 == 0; modelbiped.bipedHeadwear.showModel = par2 == 0; modelbiped.bipedBody.showModel = par2 == 1 || par2 == 2; modelbiped.bipedRightArm.showModel = par2 == 1; modelbiped.bipedLeftArm.showModel = par2 == 1; modelbiped.bipedRightLeg.showModel = par2 == 2 || par2 == 3; modelbiped.bipedLeftLeg.showModel = par2 == 2 || par2 == 3; setRenderPassModel(modelbiped); return !itemstack.isItemEnchanted() ? 1 : 15; } } return -1; }
/** Called when the player picks up an item from an inventory slot */ public void onPickupFromSlot(ItemStack par1ItemStack) { ModLoader.takenFromCrafting(this.thePlayer, par1ItemStack, this.craftMatrix); // ForgeHooks.onTakenFromCrafting(thePlayer, par1ItemStack, craftMatrix); TODO this.func_48434_c(par1ItemStack); for (int var2 = 0; var2 < this.craftMatrix.getSizeInventory(); ++var2) { ItemStack var3 = this.craftMatrix.getStackInSlot(var2); if (var3 != null) { this.craftMatrix.decrStackSize(var2, 1); if (var3.getItem().hasContainerItem()) { ItemStack var4 = new ItemStack(var3.getItem().getContainerItem()); if (!var3.getItem().doesContainerItemLeaveCraftingGrid(var3) || !this.thePlayer.inventory.addItemStackToInventory(var4)) { if (this.craftMatrix.getStackInSlot(var2) == null) { this.craftMatrix.setInventorySlotContents(var2, var4); } else { this.thePlayer.dropPlayerItem(var4); } } } } } }
/** Ejects the current record inside of the jukebox. */ public void ejectRecord(World par1World, int par2, int par3, int par4) { if (!par1World.isRemote) { TileEntityRecordPlayer var5 = (TileEntityRecordPlayer) par1World.getBlockTileEntity(par2, par3, par4); if (var5 != null) { ItemStack var6 = var5.func_96097_a(); if (var6 != null) { par1World.playAuxSFX(1005, par2, par3, par4, 0); par1World.playRecord((String) null, par2, par3, par4); var5.func_96098_a((ItemStack) null); par1World.setBlockMetadataWithNotify(par2, par3, par4, 0, 2); float var7 = 0.7F; double var8 = (double) (par1World.rand.nextFloat() * var7) + (double) (1.0F - var7) * 0.5D; double var10 = (double) (par1World.rand.nextFloat() * var7) + (double) (1.0F - var7) * 0.2D + 0.6D; double var12 = (double) (par1World.rand.nextFloat() * var7) + (double) (1.0F - var7) * 0.5D; ItemStack var14 = var6.copy(); EntityItem var15 = new EntityItem( par1World, (double) par2 + var8, (double) par3 + var10, (double) par4 + var12, var14); var15.delayBeforeCanPickup = 10; par1World.spawnEntityInWorld(var15); } } } }
/** * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a * pig. */ public boolean interact(EntityPlayer par1EntityPlayer) { ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem(); if (var2 != null && var2.itemID == Item.shears.itemID && !this.getSheared() && !this.isChild()) { if (!this.worldObj.isRemote) { this.setSheared(true); int var3 = 1 + this.rand.nextInt(3); for (int var4 = 0; var4 < var3; ++var4) { EntityItem var5 = this.entityDropItem( new ItemStack(Block.cloth.blockID, 1, this.getFleeceColor()), 1.0F); var5.motionY += (double) (this.rand.nextFloat() * 0.05F); var5.motionX += (double) ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.1F); var5.motionZ += (double) ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.1F); } } var2.damageItem(1, par1EntityPlayer); this.playSound("mob.sheep.shear", 1.0F, 1.0F); } return super.interact(par1EntityPlayer); }
/** Called to transfer a stack from one inventory to the other eg. when shift clicking. */ public ItemStack transferStackInSlot(int par1) { ItemStack var2 = null; Slot var3 = (Slot) this.inventorySlots.get(par1); if (var3 != null && var3.getHasStack()) { ItemStack var4 = var3.getStack(); var2 = var4.copy(); if (par1 < this.numRows * 9) { if (!this.mergeItemStack(var4, this.numRows * 9, this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(var4, 0, this.numRows * 9, false)) { return null; } if (var4.stackSize == 0) { var3.putStack((ItemStack) null); } else { var3.onSlotChanged(); } } return var2; }
private boolean func_21137_a(InventoryCrafting inventorycrafting, int i, int j, boolean flag) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { int i1 = k - i; int j1 = l - j; ItemStack itemstack = null; if (i1 >= 0 && j1 >= 0 && i1 < recipeWidth && j1 < recipeHeight) { if (flag) { itemstack = recipeItems[(recipeWidth - i1 - 1) + j1 * recipeWidth]; } else { itemstack = recipeItems[i1 + j1 * recipeWidth]; } } ItemStack itemstack1 = inventorycrafting.func_21103_b(k, l); if (itemstack1 == null && itemstack == null) { continue; } if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null) { return false; } if (itemstack.itemID != itemstack1.itemID) { return false; } if (itemstack.getItemDamage() != -1 && itemstack.getItemDamage() != itemstack1.getItemDamage()) { return false; } } } return true; }
public boolean a(EntityHuman entityhuman) { ItemStack itemstack = entityhuman.inventory.getItemInHand(); if (itemstack != null && itemstack.getItem() == Items.BOWL && this.getAge() >= 0) { if (itemstack.count == 1) { entityhuman.inventory.setItem( entityhuman.inventory.itemInHandIndex, new ItemStack(Items.MUSHROOM_STEW)); return true; } if (entityhuman.inventory.pickup(new ItemStack(Items.MUSHROOM_STEW)) && !entityhuman.abilities.canInstantlyBuild) { entityhuman.inventory.splitStack(entityhuman.inventory.itemInHandIndex, 1); return true; } } if (itemstack != null && itemstack.getItem() == Items.SHEARS && this.getAge() >= 0) { this.die(); this.world.addParticle( EnumParticle.EXPLOSION_LARGE, this.locX, this.locY + (double) (this.length / 2.0F), this.locZ, 0.0D, 0.0D, 0.0D, new int[0]); if (!this.world.isClientSide) { EntityCow entitycow = new EntityCow(this.world); entitycow.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, this.pitch); entitycow.setHealth(this.getHealth()); entitycow.aI = this.aI; if (this.hasCustomName()) { entitycow.setCustomName(this.getCustomName()); } this.world.addEntity(entitycow); for (int i = 0; i < 5; ++i) { this.world.addEntity( new EntityItem( this.world, this.locX, this.locY + (double) this.length, this.locZ, new ItemStack(Blocks.RED_MUSHROOM))); } itemstack.damage(1, entityhuman); this.makeSound("mob.sheep.shear", 1.0F, 1.0F); } return true; } else { return super.a(entityhuman); } }
/** * Returns whether the current item (tool) can harvest from the specified block (actually get a * result). */ public boolean canHarvestBlock(Block par1Block) { if (par1Block.blockMaterial.isToolNotRequired()) { return true; } else { ItemStack var2 = this.getStackInSlot(this.currentItem); return var2 != null ? var2.canHarvestBlock(par1Block) : false; } }
public int getDamageVsEntity(Entity entity) { ItemStack itemstack = getStackInSlot(currentItem); if (itemstack != null) { return itemstack.getDamageVsEntity(entity); } else { return 1; } }
/** * This function stores as many items of an ItemStack as possible in a matching slot and returns * the quantity of left over items. */ private int storePartialItemStack(ItemStack par1ItemStack) { int var2 = par1ItemStack.itemID; int var3 = par1ItemStack.stackSize; int var4; if (par1ItemStack.getMaxStackSize() == 1) { var4 = this.getFirstEmptyStack(); if (var4 < 0) { return var3; } else { if (this.mainInventory[var4] == null) { this.mainInventory[var4] = ItemStack.copyItemStack(par1ItemStack); } return 0; } } else { var4 = this.storeItemStack(par1ItemStack); if (var4 < 0) { var4 = this.getFirstEmptyStack(); } if (var4 < 0) { return var3; } else { if (this.mainInventory[var4] == null) { this.mainInventory[var4] = new ItemStack(var2, 0, par1ItemStack.getItemDamage()); if (par1ItemStack.hasTagCompound()) { this.mainInventory[var4].setTagCompound( (NBTTagCompound) par1ItemStack.getTagCompound().copy()); } } int var5 = var3; if (var3 > this.mainInventory[var4].getMaxStackSize() - this.mainInventory[var4].stackSize) { var5 = this.mainInventory[var4].getMaxStackSize() - this.mainInventory[var4].stackSize; } if (var5 > this.getInventoryStackLimit() - this.mainInventory[var4].stackSize) { var5 = this.getInventoryStackLimit() - this.mainInventory[var4].stackSize; } if (var5 == 0) { return var3; } else { var3 -= var5; this.mainInventory[var4].stackSize += var5; this.mainInventory[var4].animationsToGo = 5; return var3; } } } }
/** Return whether the specified armor ItemStack has a color. */ public boolean hasColor(ItemStack par1ItemStack) { return this.material != EnumArmorMaterial.CLOTH ? false : (!par1ItemStack.hasTagCompound() ? false : (!par1ItemStack.getTagCompound().hasKey("display") ? false : par1ItemStack.getTagCompound().getCompoundTag("display").hasKey("color"))); }
public boolean a(ItemStack var1) { return var1 == null ? false : (var1.getItem() instanceof ItemArmor ? ((ItemArmor) var1.getItem()).b == this.a : (var1.getItem() != Item.getItemOf(Blocks.PUMPKIN) && var1.getItem() != Items.SKULL ? false : this.a == 0)); }
public Packet104WindowItems(int par1, List par2List) { this.windowId = par1; this.itemStack = new ItemStack[par2List.size()]; for (int var3 = 0; var3 < this.itemStack.length; ++var3) { ItemStack var4 = (ItemStack) par2List.get(var3); this.itemStack[var3] = var4 == null ? null : var4.copy(); } }
public boolean onBlockDestroyed( ItemStack itemstack, int i, int j, int k, int l, EntityLiving entityliving) { int i1 = itemstack.getItemDamage(); if (i1 >= dur) { itemstack.stackSize = 0; } itemstack.damageItem(2, entityliving); return true; }
public boolean c_(ItemStack itemstack) { return this.p != EnumArmorMaterial.CLOTH ? false : (!itemstack.hasTag() ? false : (!itemstack.getTag().hasKeyOfType("display", 10) ? false : itemstack.getTag().getCompound("display").hasKeyOfType("color", 3))); }
public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) { if (player != null) { item = item.copy(); if (item.stackSize == 0) { item.stackSize = 1; } countItems(player, item); } }