public static ItemStack getSmelt(ItemStack smelt, ItemStack itemStack) { if (!itemStack.hasTagCompound() || !itemStack.getTagCompound().getBoolean("Smelt")) return smelt; NBTTagList items = itemStack.getTagCompound().getTagList("ItemsSmelt", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < items.tagCount(); ++i) { NBTTagCompound item = /*(NBTTagCompound)*/ items.getCompoundTagAt(i); byte slot = item.getByte("Slot"); // Just double-checking that the saved slot index is within our inventory array bounds if (slot >= 0 && slot < 9) { if (!itemStack.getTagCompound().getBoolean("Invert") && ItemStack.loadItemStackFromNBT(item).isItemEqual(smelt)) return FurnaceRecipes.smelting().getSmeltingResult(smelt) != null ? getOneSmelt(smelt) : smelt; else if (itemStack.getTagCompound().getBoolean("Invert") && !ItemStack.loadItemStackFromNBT(item).isItemEqual(smelt)) return FurnaceRecipes.smelting().getSmeltingResult(smelt) != null ? getOneSmelt(smelt) : smelt; } } return smelt; }
private static void registerVanillaImprovements() { FurnaceRecipes.smelting() .addSmelting( MineFactoryReloadedCore.rawRubberItem.itemID, 0, new ItemStack(MineFactoryReloadedCore.rubberBarItem), 0.1F); FurnaceRecipes.smelting() .addSmelting( MineFactoryReloadedCore.rubberWoodBlock.blockID, 0, new ItemStack(Item.coal, 1, 1), 0.1F); GameRegistry.addShapelessRecipe( new ItemStack(Block.planks, 3, 3), new ItemStack(MineFactoryReloadedCore.rubberWoodBlock)); GameRegistry.addRecipe( new ItemStack(Block.torchWood, 4), new Object[] { "R", "S", Character.valueOf('R'), MineFactoryReloadedCore.rawRubberItem, Character.valueOf('S'), Item.stick }); GameRegistry.addRecipe( new ItemStack(Block.pistonStickyBase), new Object[] { "R", "P", Character.valueOf('R'), MineFactoryReloadedCore.rawRubberItem, Character.valueOf('P'), Block.pistonBase }); if (MineFactoryReloadedCore.vanillaOverrideIce.getBoolean(true)) { GameRegistry.addShapelessRecipe( new ItemStack(Block.ice, 1, 1), new ItemStack(Block.ice, 1, 0), new ItemStack(MineFactoryReloadedCore.rawPlasticItem, 1)); } if (MineFactoryReloadedCore.enableMossyCobbleRecipe.getBoolean(true)) { GameRegistry.addShapelessRecipe( new ItemStack(Block.cobblestoneMossy), new Object[] {Block.cobblestone, Item.bucketWater, Item.wheat}); } GameRegistry.addShapelessRecipe( new ItemStack(MineFactoryReloadedCore.milkBottleItem), new Object[] {Item.bucketMilk, Item.glassBottle}); }
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) { ItemStack result = null; Slot slot = getSlot(slotIndex); if (slot != null && slot.getHasStack()) { ItemStack stack = slot.getStack(); result = stack.copy(); if (slotIndex == 1) { if (!mergeItemStack(stack, 2, 38, true)) return null; slot.onSlotChange(stack, result); } else if (slotIndex != 0) { if (FurnaceRecipes.smelting().getSmeltingResult(stack) != null) { if (!this.mergeItemStack(stack, 0, 1, false)) return null; } else if (slotIndex >= 2 && slotIndex < 29) { if (!this.mergeItemStack(stack, 29, 38, false)) return null; } else if (slotIndex >= 29 && slotIndex < 38) { if (!this.mergeItemStack(stack, 2, 29, false)) return null; } } else if (!this.mergeItemStack(stack, 2, 38, false)) return null; if (stack.stackSize <= 0) slot.putStack(null); else slot.onSlotChanged(); if (stack.stackSize == result.stackSize) return null; slot.onPickupFromSlot(player, stack); } return result; }
@Override public void onPoweredCycleEnd() { ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this._inventories[0]); if (destroyInputs(this.xCoord, this.yCoord, this.zCoord, this.worldObj)) { consumeInputs(); } else if (Utils.isChestAvailable( this.xCoord, this.yCoord, this.zCoord, this.worldObj, itemstack)) { consumeInputs(); } else if (_inventories[1] != null) { if (consumeInputs()) { _inventories[1].stackSize += itemstack.stackSize; } } else { if (consumeInputs()) { _inventories[1] = itemstack.copy(); _inventories[1].stackSize = itemstack.stackSize; } } active = 0; markDirty(); }
/** * Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't * full, etc. */ private boolean canSmelt() { if (furnaceItemStacks[0] == null) { return false; } ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(furnaceItemStacks[0].getItem().itemID); if (itemstack == null) { return false; } if (furnaceItemStacks[2] == null) { return true; } if (!furnaceItemStacks[2].isItemEqual(itemstack)) { return false; } if (furnaceItemStacks[2].stackSize < getInventoryStackLimit() && furnaceItemStacks[2].stackSize < furnaceItemStacks[2].getMaxStackSize()) { return true; } else { return furnaceItemStacks[2].stackSize < itemstack.getMaxStackSize(); } }
/** Philosopher's stone smelting recipes, EE3 style */ public static void registerPhiloStoneSmelting() { for (Entry<ItemStack, ItemStack> entry : (((HashMap<ItemStack, ItemStack>) FurnaceRecipes.smelting().getSmeltingList()) .entrySet())) { if (entry.getKey() == null || entry.getValue() == null) { continue; } ItemStack input = entry.getKey(); ItemStack output = entry.getValue().copy(); output.stackSize *= 7; GameRegistry.addShapelessRecipe( output, philosStone, input, input, input, input, input, input, input, new ItemStack(Items.coal, 1, OreDictionary.WILDCARD_VALUE)); } }
@Override public boolean isItemValidForSlot(int i, ItemStack itemstack) { if (itemstack != null && FurnaceRecipes.smelting().getSmeltingResult(itemstack) != null && i == 0) return true; return false; }
public static void initBlockSmelting() { FurnaceRecipes furnaceRecipes = FurnaceRecipes.smelting(); /* Harmonon Ore Smelting. */ furnaceRecipes.addSmelting( ModBlocks.HarmonionOre.blockID, new ItemStack(ModItems.Refinedsoundstone), 5.0F); }
@Override public float getExperienceForOutput(ItemStack output) { if (output == null) { return 0; } float result = FurnaceRecipes.smelting().func_151398_b(output); return result * output.stackSize; }
private ItemStack getInputForOutput(ItemStack output) { for (Object o : FurnaceRecipes.smelting().getSmeltingList().entrySet()) { ItemStack stack = (ItemStack) ((Map.Entry) o).getValue(); if (stack.isItemEqual(output)) { return (ItemStack) ((Map.Entry) o).getKey(); } } return null; }
private boolean smeltBlock(Coord4D block) { ItemStack stack = block.getStack(worldObj); if (stack == null) { return false; } ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(block.getStack(worldObj)); if (result != null) { if (!worldObj.isRemote) { Block b = block.getBlock(worldObj); int meta = block.getMetadata(worldObj); if (Block.getBlockFromItem(result.getItem()) != Blocks.air) { worldObj.setBlock( block.xCoord, block.yCoord, block.zCoord, Block.getBlockFromItem(result.getItem()), result.getItemDamage(), 3); } else { worldObj.setBlockToAir(block.xCoord, block.yCoord, block.zCoord); EntityItem item = new EntityItem( worldObj, block.xCoord + 0.5, block.yCoord + 0.5, block.zCoord + 0.5, result.copy()); item.motionX = 0; item.motionY = 0; item.motionZ = 0; worldObj.spawnEntityInWorld(item); } worldObj.playAuxSFXAtEntity( null, 2001, block.xCoord, block.yCoord, block.zCoord, Block.getIdFromBlock(b) + (meta << 12)); } spawnParticlesAt(new Pos3D(block).translate(0.5, 0.5, 0.5)); return true; } return false; }
private boolean canSmelt() { if (this.inventory[0] == null) { return false; } else { ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.inventory[0]); if (itemstack == null) return false; if (this.inventory[1] == null) return true; if (!this.inventory[1].isItemEqual(itemstack)) return false; int result = inventory[1].stackSize + itemstack.stackSize; return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize()); } }
private boolean canSmelt() { if (contents[0] == null) { return false; } else { ItemStack stack = FurnaceRecipes.smelting().getSmeltingResult(contents[0]); if (stack == null) return false; if (contents[2] == null) return true; if (!contents[2].isItemEqual(stack)) return false; int result = contents[2].stackSize + stack.stackSize; return result <= getInventoryStackLimit() && result <= contents[2].getMaxStackSize(); } }
private boolean canSmelt() { if (this.furnaceItemStacks[INPUT] == null || this.waterLevel == 0) { return false; } else { ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.furnaceItemStacks[INPUT]); if (itemstack == null) return false; if (this.furnaceItemStacks[OUTPUT] == null) return true; if (!this.furnaceItemStacks[OUTPUT].isItemEqual(itemstack)) return false; int result = furnaceItemStacks[OUTPUT].stackSize + itemstack.stackSize; return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize()); } }
@SubscribeEvent public void modifyDrops(LivingDropsEvent event) { if (event.source == STEAM) for (EntityItem entityItem : event.drops) { ItemStack drop = entityItem.getEntityItem(); ItemStack cooked = FurnaceRecipes.smelting().getSmeltingResult(drop); if (cooked != null && MiscTools.RANDOM.nextDouble() < 0.5) { cooked = cooked.copy(); cooked.stackSize = drop.stackSize; entityItem.setEntityItemStack(cooked); } } }
@Override public boolean isRecipe(MachineRecipeInput... inputs) { if (!enabled) { return false; } ItemStack output = null; for (MachineRecipeInput ri : inputs) { if (ri != null && ri.item != null && !isExcluded(ri.item)) { if (output == null) { output = FurnaceRecipes.smelting().getSmeltingResult(ri.item); if (output == null) { return false; } } else { ItemStack newOutput = FurnaceRecipes.smelting().getSmeltingResult(ri.item); if (newOutput == null || !newOutput.isItemEqual(output)) { return false; } } } } return output != null; }
/** Called to transfer a stack from one inventory to the other eg. when shift clicking. */ @Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1) { ItemStack var2 = null; final Slot var3 = (Slot) inventorySlots.get(par1); if (var3 != null && var3.getHasStack()) { final ItemStack var4 = var3.getStack(); var2 = var4.copy(); if (par1 == 1) { if (!mergeItemStack(var4, 2, 38, true)) { return null; } var3.onSlotChange(var4, var2); } else if (par1 != 1 && par1 != 0) { if (FurnaceRecipes.smelting().getSmeltingResult(var4) != null) { if (!mergeItemStack(var4, 0, 1, false)) { return null; } } else if (TileEntityFurnace.isItemFuel(var4)) { if (!mergeItemStack(var4, 0, 1, false)) { return null; } } else if (par1 >= 2 && par1 < 29) { if (!mergeItemStack(var4, 29, 38, false)) { return null; } } else if (par1 >= 29 && par1 < 38 && !mergeItemStack(var4, 2, 29, false)) { return null; } } else if (!mergeItemStack(var4, 2, 38, false)) { return null; } if (var4.stackSize == 0) { var3.putStack((ItemStack) null); } else { var3.onSlotChanged(); } if (var4.stackSize == var2.stackSize) { return null; } var3.onPickupFromSlot(par1EntityPlayer, var4); } return var2; }
@Override public boolean isItemValidForSlot(int slot, ItemStack stack) { if (stack == null) { return false; } if (slot == 0) { return TileEntityFurnace.isItemFuel(stack) || stack.getItem() == ObjHandler.kleinStars; } else if (slot >= 1 && slot <= 13) { return FurnaceRecipes.smelting().getSmeltingResult(stack) != null; } return false; }
@Override public boolean canBeginCycle() { if (_inventories[0] != null && _inventories[0].stackSize >= 1) { if (_inventories[1] != null && _inventories[1].stackSize >= getInventoryStackLimit()) { return false; } if (FurnaceRecipes.smelting().getSmeltingResult(this._inventories[0]) != null) return true; } return false; }
public void smeltItem() { if (this.canSmelt()) { ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.inventory[0]); if (this.inventory[1] == null) { this.inventory[1] = itemstack.copy(); } else if (this.inventory[1].isItemEqual(itemstack)) { inventory[1].stackSize += itemstack.stackSize; } --this.inventory[0].stackSize; if (this.inventory[0].stackSize <= 0) { this.inventory[0] = null; } } }
@Override public boolean isValidInput(MachineRecipeInput input) { if (!enabled) { return false; } if (input == null || input.item == null) { return false; } if (isExcluded(input.item)) { return false; } ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(input.item); return itemstack != null; }
public static void smeltBlockInWorld(World world, int posX, int posY, int posZ) { FurnaceRecipes recipes = FurnaceRecipes.smelting(); Block block = Block.blocksList[world.getBlockId(posX, posY, posZ)]; if (block == null) { return; } int meta = world.getBlockMetadata(posX, posY, posZ); ItemStack smeltedStack = recipes.getSmeltingResult(new ItemStack(block, 1, meta)); if (smeltedStack != null && smeltedStack.getItem() instanceof ItemBlock) { world.setBlock(posX, posY, posZ, smeltedStack.itemID, smeltedStack.getItemDamage(), 3); } }
/** * Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't * full, etc. */ private boolean canSmelt() { if (this.furnaceItemStacks[0] == null) { return false; } else { ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.furnaceItemStacks[0]); if (itemstack == null) return false; if (this.furnaceItemStacks[2] == null) return true; if (!this.furnaceItemStacks[2].isItemEqual(itemstack)) return false; int result = furnaceItemStacks[2].stackSize + itemstack.stackSize; return result <= getInventoryStackLimit() && result <= this.furnaceItemStacks[2] .getMaxStackSize(); // Forge BugFix: Make it respect stack sizes properly. } }
private boolean smeltItem(EntityItem item) { ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(item.getEntityItem()); if (result != null) { item.setEntityItemStack(StackUtils.size(result, item.getEntityItem().stackSize)); item.ticksExisted = 0; spawnParticlesAt(new Pos3D(item)); worldObj.playSoundAtEntity(item, "random.fizz", 1.0F, 1.0F); return true; } return false; }
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slotID) { ItemStack stack = null; Slot currentSlot = (Slot) inventorySlots.get(slotID); if (currentSlot != null && currentSlot.getHasStack()) { ItemStack slotStack = currentSlot.getStack(); stack = slotStack.copy(); if (slotID == 2) { if (!mergeItemStack(slotStack, 3, 39, true)) { return null; } } else if (slotID != 1 && slotID != 0) { if (FurnaceRecipes.smelting().getSmeltingResult(slotStack) != null) { if (!mergeItemStack(slotStack, 0, 1, false)) { return null; } } else if (TileEntityFurnace.isItemFuel(slotStack)) { if (!mergeItemStack(slotStack, 1, 2, false)) { return null; } } else if (slotID >= 3 && slotID < 30) { if (!mergeItemStack(slotStack, 30, 39, false)) { return null; } } else if (slotID >= 30 && slotID < 39 && !mergeItemStack(slotStack, 3, 30, false)) { return null; } } else if (!mergeItemStack(slotStack, 3, 39, false)) { return null; } if (slotStack.stackSize == 0) { currentSlot.putStack((ItemStack) null); } else { currentSlot.onSlotChanged(); } if (slotStack.stackSize == stack.stackSize) { return null; } currentSlot.onPickupFromSlot(player, slotStack); } return stack; }
@Override protected void onCrafting(ItemStack par1ItemStack) { par1ItemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.field_75228_b); if (!this.thePlayer.worldObj.isRemote) { int i = this.field_75228_b; // 経験値なぁ…うーん float f = FurnaceRecipes.smelting().func_151398_b(par1ItemStack); int j; if (f == 0.0F) { i = 0; } else if (f < 1.0F) { j = MathHelper.floor_float((float) i * f); if (j < MathHelper.ceiling_float_int((float) i * f) && (float) Math.random() < (float) i * f - (float) j) { ++j; } i = j; } while (i > 0) { j = EntityXPOrb.getXPSplit(i); i -= j; this.thePlayer.worldObj.spawnEntityInWorld( new EntityXPOrb( this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, j)); } } this.field_75228_b = 0; FMLCommonHandler.instance().firePlayerSmeltedEvent(thePlayer, par1ItemStack); if (par1ItemStack.getItem() == Items.iron_ingot) { this.thePlayer.addStat(AchievementList.acquireIron, 1); } if (par1ItemStack.getItem() == Items.cooked_fished) { this.thePlayer.addStat(AchievementList.cookFish, 1); } }
private void smeltItem() { ItemStack toSmelt = inventory[1]; ItemStack smeltResult = FurnaceRecipes.smelting().getSmeltingResult(toSmelt).copy(); ItemStack currentSmelted = getStackInSlot(outputSlot); if (Utils.getOreDictionaryName(toSmelt).startsWith("ore")) { smeltResult.stackSize *= 2; } if (currentSmelted == null) { setInventorySlotContents(outputSlot, smeltResult); } else { currentSmelted.stackSize += smeltResult.stackSize; } decrStackSize(1, 1); }
@Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { ItemStack itemstack = null; Slot slot = (Slot) this.inventorySlots.get(par2); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (par2 == 1) { if (!this.mergeItemStack(itemstack1, 2, 38, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if (par2 != 0) { if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null) { if (!this.mergeItemStack(itemstack1, 0, 1, false)) { return null; } } else if (par2 >= 2 && par2 < 29) { if (!this.mergeItemStack(itemstack1, 29, 38, false)) { return null; } } else if (par2 >= 29 && par2 < 38 && !this.mergeItemStack(itemstack1, 2, 29, false)) { return null; } } else if (!this.mergeItemStack(itemstack1, 2, 38, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack) null); } else { slot.onSlotChanged(); } if (itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(par1EntityPlayer, itemstack1); } return itemstack; }
public void smeltItem() { if (canSmelt()) { ItemStack stack = FurnaceRecipes.smelting().getSmeltingResult(contents[0]); if (contents[2] == null) { contents[2] = stack.copy(); } else if (contents[2].getItem() == stack.getItem()) { contents[2].stackSize += stack.stackSize; } contents[0].stackSize--; if (contents[0].stackSize <= 0) { contents[0] = null; } } }
/** the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. */ protected void onCrafting(ItemStack par1ItemStack) { par1ItemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.field_75228_b); if (!this.thePlayer.worldObj.isRemote) { int i = this.field_75228_b; float f = FurnaceRecipes.smelting().getExperience(par1ItemStack); int j; if (f == 0.0F) { i = 0; } else if (f < 1.0F) { j = MathHelper.floor_float((float) i * f); if (j < MathHelper.ceiling_float_int((float) i * f) && (float) Math.random() < (float) i * f - (float) j) { ++j; } i = j; } while (i > 0) { j = EntityXPOrb.getXPSplit(i); i -= j; this.thePlayer.worldObj.spawnEntityInWorld( new EntityXPOrb( this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, j)); } } this.field_75228_b = 0; GameRegistry.onItemSmelted(thePlayer, par1ItemStack); if (par1ItemStack.itemID == Item.ingotIron.itemID) { this.thePlayer.addStat(AchievementList.acquireIron, 1); } if (par1ItemStack.itemID == Item.fishCooked.itemID) { this.thePlayer.addStat(AchievementList.cookFish, 1); } }