Jump to content

Recommended Posts

Posted

Im trying to make this fryer sort of thing this is how it works

FryerGUI.png

you put oil in 1 and coal in 2 then you put raw meat to get cooked in 3 and the out put would be 4

i have make a fryer without the oil and only 3 slots. i tried adding a 4 slot but it crashed when i opened the gui. can you give source code too

package net.minecraft.src;

 

import java.util.Iterator;

import java.util.List;

 

public class ContainerFryer extends Container

{

    private TileEntityFryer Fryer;

    private int lastFryerCookTime;

    private int lastFryerBurnTime;

    private int lastFryerItemBurnTime;

 

    public ContainerFryer(InventoryPlayer par1InventoryPlayer, TileEntityFryer par2TileEntityFryer)

    {

        lastFryerCookTime = 0;

        lastFryerBurnTime = 0;

        lastFryerItemBurnTime = 0;

        Fryer = par2TileEntityFryer;

        addSlotToContainer(new Slot(par2TileEntityFryer, 3, 15, 17));

        addSlotToContainer(new Slot(par2TileEntityFryer, 0, 15, 56));

        addSlotToContainer(new Slot(par2TileEntityFryer, 2, 64, 35));

        addSlotToContainer(new SlotFryer(par1InventoryPlayer.player, par2TileEntityFryer, 1, 115, 34));

 

        for (int i = 0; i < 3; i++)

        {

            for (int k = 0; k < 9; k++)

            {

                addSlotToContainer(new Slot(par1InventoryPlayer, k + i * 9 + 9, 8 + k * 18, 84 + i * 18));

            }

        }

 

        for (int j = 0; j < 9; j++)

        {

            addSlotToContainer(new Slot(par1InventoryPlayer, j, 8 + j * 18, 142));

        }

       

    }

 

    /**

    * Updates crafting matrix; called from onCraftMatrixChanged. Args: none

    */

    public void updateCraftingResults()

    {

        super.updateCraftingResults();

        Iterator var1 = this.crafters.iterator();

 

        while (var1.hasNext())

        {

            ICrafting var2 = (ICrafting)var1.next();

 

            if (this.lastFryerCookTime != this.Fryer.goldCookTime)

            {

                var2.updateCraftingInventoryInfo(this, 0, this.Fryer.goldCookTime);

            }

 

            if (this.lastFryerBurnTime != this.Fryer.goldBurnTime)

            {

                var2.updateCraftingInventoryInfo(this, 1, this.Fryer.goldBurnTime);

            }

 

            if (this.lastFryerItemBurnTime != this.Fryer.goldItemBurnTime)

            {

                var2.updateCraftingInventoryInfo(this, 2, this.Fryer.goldItemBurnTime);

            }

        }

 

        this.lastFryerCookTime = this.Fryer.goldCookTime;

        this.lastFryerBurnTime = this.Fryer.goldBurnTime;

        this.lastFryerItemBurnTime = this.Fryer.goldItemBurnTime;

    }

   

    public void updateProgressBar(int par1, int par2)

    {

        if (par1 == 0)

        {

            Fryer.goldCookTime = par2;

        }

 

        if (par1 == 1)

        {

            Fryer.goldBurnTime = par2;

        }

 

        if (par1 == 2)

        {

            Fryer.goldItemBurnTime = par2;

        }

    }

 

    public boolean canInteractWith(EntityPlayer par1EntityPlayer)

    {

        return Fryer.isUseableByPlayer(par1EntityPlayer);

    }

 

    /**

    * Called to transfer a stack from one inventory to the other eg. when shift clicking.

    */

    public ItemStack transferStackInSlot(int par1)

    {

        ItemStack itemstack = null;

        Slot slot = (Slot)inventorySlots.get(par1);

 

        if (slot != null && slot.getHasStack())

        {

            ItemStack itemstack1 = slot.getStack();

            itemstack = itemstack1.copy();

 

            if (par1 == 2)

            {

                if (!mergeItemStack(itemstack1, 3, 39, true))

                {

                    return null;

                }

 

                slot.onSlotChange(itemstack1, itemstack);

            }

            else if (par1 == 1 || par1 == 0)

            {

                if (!mergeItemStack(itemstack1, 3, 39, false))

                {

                    return null;

                }

            }

            else if (RecipesFryer.smelting().getSmeltingResult(itemstack1.getItem().shiftedIndex) != null)

            {

                if (!mergeItemStack(itemstack1, 0, 1, false))

                {

                    return null;

                }

            }

            else if (TileEntityFryer.isItemFuel(itemstack1))

            {

                if (!mergeItemStack(itemstack1, 1, 2, false))

                {

                    return null;

                }

            }

            else if (par1 >= 3 && par1 < 30)

            {

                if (!mergeItemStack(itemstack1, 30, 39, false))

                {

                    return null;

                }

            }

            else if (par1 >= 30 && par1 < 39 && !mergeItemStack(itemstack1, 3, 30, false))

            {

                return null;

            }

 

            if (itemstack1.stackSize == 0)

            {

                slot.putStack(null);

            }

            else

            {

                slot.onSlotChanged();

            }

 

            if (itemstack1.stackSize != itemstack.stackSize)

            {

                slot.onPickupFromSlot(itemstack1);

            }

            else

            {

                return null;

            }

        }

 

        return itemstack;

    }

}


 


package net.minecraft.src;

 

public class TileEntityFryer extends TileEntity implements IInventory

{

    private ItemStack goldItemStacks[];

 

    /** The number of ticks that the furnace will keep burning */

    public int goldBurnTime;

 

    private boolean isActive;

   

    /**

    * The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for

    */

    public int goldItemBurnTime;

 

    /** The number of ticks that the current item has been cooking for */

    public int goldCookTime;

 

    public int front;

   

    public TileEntityFryer()

    {

        goldItemStacks = new ItemStack[3];

        goldBurnTime = 0;

        goldItemBurnTime = 0;

        goldCookTime = 0;

    }

   

    public void setFrontDirection(int f)

    {

        this.front = f;

    }

   

    public int getFrontDirection()

    {

        return this.front;

    }

 

    /**

    * Returns the number of slots in the inventory.

    */

    public int getSizeInventory()

    {

        return goldItemStacks.length;

    }

 

    /**

    * Returns the stack in slot i

    */

    public ItemStack getStackInSlot(int par1)

    {

        return goldItemStacks[par1];

    }

 

    /**

    * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new

    * stack.

    */

    public ItemStack decrStackSize(int par1, int par2)

    {

        if (goldItemStacks[par1] != null)

        {

            if (goldItemStacks[par1].stackSize <= par2)

            {

                ItemStack itemstack = goldItemStacks[par1];

                goldItemStacks[par1] = null;

                return itemstack;

            }

 

            ItemStack itemstack1 = goldItemStacks[par1].splitStack(par2);

 

            if (goldItemStacks[par1].stackSize == 0)

            {

                goldItemStacks[par1] = null;

            }

 

            return itemstack1;

        }

        else

        {

            return null;

        }

    }

 

    /**

    * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -

    * like when you close a workbench GUI.

    */

    public ItemStack getStackInSlotOnClosing(int par1)

    {

        if (goldItemStacks[par1] != null)

        {

            ItemStack itemstack = goldItemStacks[par1];

            goldItemStacks[par1] = null;

            return itemstack;

        }

        else

        {

            return null;

        }

    }

 

    /**

    * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).

    */

    public void setInventorySlotContents(int par1, ItemStack par2ItemStack)

    {

        goldItemStacks[par1] = par2ItemStack;

 

        if (par2ItemStack != null && par2ItemStack.stackSize > getInventoryStackLimit())

        {

            par2ItemStack.stackSize = getInventoryStackLimit();

        }

    }

 

    /**

    * Returns the name of the inventory.

    */

    public String getInvName()

    {

        return "container.Fryer";

    }

 

    /**

    * Reads a tile entity from NBT.

    */

    public void readFromNBT(NBTTagCompound par1NBTTagCompound)

    {

        super.readFromNBT(par1NBTTagCompound);

        NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items");

        goldItemStacks = new ItemStack[getSizeInventory()];

 

        for (int i = 0; i < nbttaglist.tagCount(); i++)

        {

            NBTTagCompound nbttagcompound = (NBTTagCompound)nbttaglist.tagAt(i);

            byte byte0 = nbttagcompound.getByte("Slot");

 

            if (byte0 >= 0 && byte0 < goldItemStacks.length)

            {

                goldItemStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound);

            }

        }

        front = par1NBTTagCompound.getInteger("FrontDirection");

        goldBurnTime = par1NBTTagCompound.getShort("BurnTime");

        goldCookTime = par1NBTTagCompound.getShort("CookTime");

        goldItemBurnTime = getItemBurnTime(goldItemStacks[1]);

       

        System.out.println("front:" + front);

    }

 

    /**

    * Writes a tile entity to NBT.

    */

    public void writeToNBT(NBTTagCompound par1NBTTagCompound)

    {

        super.writeToNBT(par1NBTTagCompound);

        par1NBTTagCompound.setInteger("FrontDirection", (int)front);

        par1NBTTagCompound.setShort("BurnTime", (short)goldBurnTime);

        par1NBTTagCompound.setShort("CookTime", (short)goldCookTime);

        NBTTagList nbttaglist = new NBTTagList();

 

        for (int i = 0; i < goldItemStacks.length; i++)

        {

            if (goldItemStacks[i] != null)

            {

                NBTTagCompound nbttagcompound = new NBTTagCompound();

                nbttagcompound.setByte("Slot", (byte)i);

                goldItemStacks[i].writeToNBT(nbttagcompound);

                nbttaglist.appendTag(nbttagcompound);

            }

        }

 

        par1NBTTagCompound.setTag("Items", nbttaglist);

        System.out.println("write:" + front);

        System.out.println("burn:" + goldBurnTime);

    }

 

    /**

    * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't

    * this more of a set than a get?*

    */

    public int getInventoryStackLimit()

    {

        return 64;

    }

 

    /**

    * Returns an integer between 0 and the passed value representing how close the current item is to being completely

    * cooked

    */

    public int getCookProgressScaled(int par1)

    {

        return (goldCookTime * par1) / 200;

    }

 

    /**

    * Returns an integer between 0 and the passed value representing how much burn time is left on the current fuel

    * item, where 0 means that the item is exhausted and the passed value means that the item is fresh

    */

    public int getBurnTimeRemainingScaled(int par1)

    {

        if (goldItemBurnTime == 0)

        {

            goldItemBurnTime = 200;

        }

 

        return (goldBurnTime * par1) / goldItemBurnTime;

    }

 

    /**

    * Returns true if the furnace is currently burning

    */

    public boolean isBurning()

    {

        return goldBurnTime > 0;

    }

 

    /**

    * Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses this to count

    * ticks and creates a new spawn inside its implementation.

    */

    public void updateEntity()

    {

        boolean var1 = this.goldBurnTime > 0;

        boolean var2 = false;

 

        if (this.goldBurnTime > 0)

        {

            --this.goldBurnTime;

        }

 

        if (!this.worldObj.isRemote)

        {

            if (this.goldBurnTime == 0 && this.canSmelt())

            {

                this.goldItemBurnTime = this.goldBurnTime = getItemBurnTime(this.goldItemStacks[1]);

 

                if (this.goldBurnTime > 0)

                {

                    var2 = true;

 

                    if (this.goldItemStacks[1] != null)

                    {

                        --this.goldItemStacks[1].stackSize;

 

                        if (this.goldItemStacks[1].stackSize == 0)

                        {

                            Item var3 = this.goldItemStacks[1].getItem().getContainerItem();

                            this.goldItemStacks[1] = var3 == null ? null : new ItemStack(var3);

                        }

                    }

                }

            }

 

            if (this.isBurning() && this.canSmelt())

            {

                ++this.goldCookTime;

 

                if (this.goldCookTime == 200)

                {

                    this.goldCookTime = 0;

                    this.smeltItem();

                    var2 = true;

                }

            }

            else

            {

                this.goldCookTime = 0;

            }

 

            if (var1 != this.goldBurnTime > 0)

            {

                var2 = true;

                this.validate();

            }

        }

        boolean check = isActive;

        isActive = isBurning();

        if(isActive != check)

        {

            this.worldObj.markBlockNeedsUpdate(this.xCoord, this.yCoord, this.zCoord);

        }

 

        if (var2)

        {

            this.onInventoryChanged();

        }

    }

 

   

    /**

    * 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 (goldItemStacks[0] == null)

        {

            return false;

        }

        if (goldItemStacks[2] == null)

        {

            return false;

        }

 

        ItemStack itemstack = RecipesFryer.smelting().getSmeltingResult(goldItemStacks[0].getItem().shiftedIndex);

       

 

        if (itemstack == null)

        {

            return false;

        }

 

        if (goldItemStacks[2] == null)

        {

            return true;

        }

 

        if (!goldItemStacks[2].isItemEqual(itemstack))

        {

            return false;

        }

 

        if (goldItemStacks[2].stackSize < getInventoryStackLimit() && goldItemStacks[2].stackSize < goldItemStacks[2].getMaxStackSize())

        {

            return true;

        }

 

        return goldItemStacks[2].stackSize < itemstack.getMaxStackSize();

    }

 

    /**

    * Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack

    */

    public void smeltItem()

    {

        if (this.canSmelt())

        {

            ItemStack var1 = RecipesFryer.smelting().getSmeltingResult(this.goldItemStacks[0].getItem().shiftedIndex);

 

            if (this.goldItemStacks[2] == null)

            {

                this.goldItemStacks[2] = var1.copy();

            }

            else if (this.goldItemStacks[2].itemID == var1.itemID)

            {

                ++this.goldItemStacks[2].stackSize;

            }

 

            --this.goldItemStacks[0].stackSize;

 

            if (this.goldItemStacks[0].stackSize == 0)

            {

                Item var2 = this.goldItemStacks[0].getItem().getContainerItem();

                this.goldItemStacks[0] = var2 == null ? null : new ItemStack(var2);

            }

        }

    }

 

    /**

    * Return true if item is a fuel source (getItemBurnTime() > 0).

    */

    public static boolean isItemFuel(ItemStack par0ItemStack)

    {

        return getItemBurnTime(par0ItemStack) > 0;

    }

   

    /**

    * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't

    * fuel

    */

    public static int getItemBurnTime(ItemStack par1ItemStack)

    {

        if (par1ItemStack == null)

        {

            return 0;

        }

 

        int i = par1ItemStack.getItem().shiftedIndex;

 

        if (i < 256 && Block.blocksList[i].blockMaterial == Material.wood)

        {

            return 0;

        }

 

        if (i == Item.stick.shiftedIndex)

        {

            return 0;

        }

 

        if (i == Item.coal.shiftedIndex)

        {

            return 0;

        }

 

        if (i == Item.bucketLava.shiftedIndex)

        {

            return 0;

        }

 

        if (i == Block.sapling.blockID)

        {

            return 0;

        }

 

        if (i == Item.blazeRod.shiftedIndex)

        {

            return 0;

        }

       

        else

        {

            return ModLoader.addAllFuel(par1ItemStack.itemID, par1ItemStack.getItemDamage());

        }

    }

    /**

    * Do not make give this method the name canInteractWith because it clashes with Container

    */

    public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)

    {

        if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)

        {

            return false;

        }

 

        return par1EntityPlayer.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64D;

    }

 

    public void openChest()

    {

    }

 

    public void closeChest()

    {

    }

 

    public boolean isActive()

    {

        return this.isActive;

    }

   

}



 


package net.minecraft.src;

 

import java.util.HashMap;

import java.util.Map;

 

public class RecipesFryer

{

    private static final RecipesFryer FryerBase = new RecipesFryer();

 

    /** The list of smelting results. */

    private Map FryerList = new HashMap();

    private Map FryerExperience = new HashMap();

 

    /**

    * Used to call methods addSmelting and getSmeltingResult.

    */

    public static final RecipesFryer smelting()

    {

        return FryerBase;

    }

 

    private RecipesFryer()

    {

        addSmelting(Block.dirt.blockID, new ItemStack(Block.cobblestone, 1, 0), 0.7F);

    }

 

    /**

    * Adds a smelting recipe.

    */

    public void addSmelting(int id, ItemStack itemStack, float experience)

    {

        FryerList.put(Integer.valueOf(id), itemStack);

        this.FryerExperience.put(Integer.valueOf(itemStack.itemID), Float.valueOf(experience));

    }

 

    /**

    * Returns the smelting result of an item.

    */

    public ItemStack getSmeltingResult(int id)

    {

        return (ItemStack)FryerList.get(Integer.valueOf(id));

    }

 

    public Map getSmeltingList()

    {

        return FryerList;

    }

    public float getExperience(int par1)

    {

        return this.FryerExperience.containsKey(Integer.valueOf(par1)) ? ((Float)this.FryerExperience.get(Integer.valueOf(par1))).floatValue() : 0.0F;

    } 

}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...