Jump to content

Adding furnace GUI


AlenEviLL

Recommended Posts

Hello guys!

 

I was wondering how to apply furnace GUI to the block I have just created. I don't want to draw GUI again as it has to be pretty much the same as the normal furnace's GUI looks like. The only thing is that I want this furnace to be able to smelt only one type of ore, and that's it. Can anyone help with that please?

Link to comment
Share on other sites

No, so I have to just copy that into my furnace file? OK I will try that now

 

Not quite. You will most likely have to create a new slot that ONLY takes in the ore you wanted. Anything else can't be put into it to be smelted etc.

 

 

Have fun with it! :D

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

I'm not Mew, and I can guarantee Mew knows more than I on this matter :)

 

 

but personally, I would just derive my own furnace from BlockFurnace, then derive my own tile entity from TileEntityFurnace...

 

in my new class for the "MyBlockFurnace" i'd simply add an override onBlockActivated to point the gui to "MyTileEntityFurnace"

 

and in "MyTileEntityFurnace" i'd simply add an override for canSmelt() and check in there if the itemstack in the furnace is in a list/array of those I want to allow....

 

 

... I'm not saying this is correct ;) I'm certainly not saying it's the most efficient way  - I'm just saying that I'd probably try that way myself first...

 

Mew will hopefully point out the stupidity of this, or say "actually that'll work" - i hope for the latter, i expect the former :)

 

 

 

[ and if i was at home, i'd have tried this before posting it, but i'm not, so i haven't ;) ]

Link to comment
Share on other sites

Haha, nice one ingiethingie!

 

Well I wouldn't say I would be much better on the topic... I have never really played around with Containers too much. Though that is the next thing on my list of GUI stuff to learn (At the moment I am working on draggable GUI's and such. Extremely fun stuff). xD But from what I do know, there are two differen't slots in the Furnace container. Slot (the generic slot that can hold anything, the slot used for your inventory etc.), and SlotFurnace (Which is the slot to the side, the one that cannot have anything put into it). That is where my idea for the custom Slot comes into play. The SlotFurnace looks like this:

 

 

package net.minecraft.inventory;

import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.stats.AchievementList;
import net.minecraft.util.MathHelper;

public class SlotFurnace extends Slot
{
    /** The player that is using the GUI where this slot resides. */
    private EntityPlayer thePlayer;
    private int field_75228_b;

    public SlotFurnace(EntityPlayer par1EntityPlayer, IInventory par2IInventory, int par3, int par4, int par5)
    {
        super(par2IInventory, par3, par4, par5);
        this.thePlayer = par1EntityPlayer;
    }

    /**
     * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
     */
    public boolean isItemValid(ItemStack par1ItemStack)
    {
        return false;
    }

    /**
     * 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)
    {
        if (this.getHasStack())
        {
            this.field_75228_b += Math.min(par1, this.getStack().stackSize);
        }

        return super.decrStackSize(par1);
    }

    public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
    {
        this.onCrafting(par2ItemStack);
        super.onPickupFromSlot(par1EntityPlayer, par2ItemStack);
    }

    /**
     * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
     * internal count then calls onCrafting(item).
     */
    protected void onCrafting(ItemStack par1ItemStack, int par2)
    {
        this.field_75228_b += par2;
        this.onCrafting(par1ItemStack);
    }

    /**
     * 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);
        }
    }
}

 

 

 

Now if we remove all that isn't needed, we get a generic custom slot. This looks like so:

 

 

package net.minecraft.inventory;

import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.stats.AchievementList;
import net.minecraft.util.MathHelper;

public class SlotFurnace extends Slot
{
    private int field_75228_b;

    public SlotFurnace(EntityPlayer par1EntityPlayer, IInventory par2IInventory, int par3, int par4, int par5)
    {
        super(par2IInventory, par3, par4, par5);
    }

    /**
     * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
     */
    public boolean isItemValid(ItemStack par1ItemStack)
    {
        return true;
    }

    /**
     * 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)
    {
        if (this.getHasStack())
        {
            this.field_75228_b += Math.min(par1, this.getStack().stackSize);
        }

        return super.decrStackSize(par1);
    }
}

 

 

 

But that can still hold anything in it. So we have to change isItemValid(). This should now look like so:

   /**
     * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
     */
    public boolean isItemValid(ItemStack par1ItemStack)
    {
    	if (par1ItemStack.itemID == Item.appleRed.itemID)
    		return true;
    	return false;
    }

 

So the whole the file should now look like this:

 

 

package net.minecraft.inventory;

import com.mrmewniverse.core.MewniversalCore;

import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.stats.AchievementList;
import net.minecraft.util.MathHelper;

public class SlotFurnace extends Slot
{
    private int field_75228_b;

    public SlotFurnace(EntityPlayer par1EntityPlayer, IInventory par2IInventory, int par3, int par4, int par5)
    {
        super(par2IInventory, par3, par4, par5);
    }

    /**
     * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
     */
    public boolean isItemValid(ItemStack par1ItemStack)
    {
    	if (par1ItemStack.itemID == Item.appleRed.itemID)
    		return true;
    	return false;
    }

    /**
     * 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)
    {
        if (this.getHasStack())
        {
            this.field_75228_b += Math.min(par1, this.getStack().stackSize);
        }

        return super.decrStackSize(par1);
    }
}

 

 

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

And you can simplify it again in:

public class SlotRestricted extends Slot
{
    public static final int allowedID = yourItem.itemID;

    public SlotRestricted(IInventory par2IInventory, int par3, int par4, int par5)
    {
        super(par2IInventory, par3, par4, par5);
    }

    /**
     * Check if the stack is a valid item for this slot.
     */
    public boolean isItemValid(ItemStack par1ItemStack)
    {
    	return par1ItemStack.itemID == allowedID;
    }
}

Link to comment
Share on other sites

@gotolink, i can do even better :)

 

import com.hydroflame.item.EquipementBase;

 

import net.minecraft.inventory.IInventory;

import net.minecraft.inventory.Slot;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

 

public class SlotOnlyForClass extends Slot{
private Class onlyFor;
public SlotOnlyForClass(IInventory iinventory, int index, int x, int y, Class classrestriction) {
	super(iinventory, index, x, y);
	onlyFor = classrestriction;
}

public boolean isItemValid(ItemStack itemStack)
    {
	return onlyFor.isAssignableFrom(Item.itemsList[itemStack.itemID].getClass());
    }
}

 

usage:

this.addSlotToContainer(new SlotOnlyForClass(inventory, id, x, y, BlockOre.class));

 

 

it will only accept BlockOre and any of its subclass :)

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Well at least I was on the right track xD

 

But there you go, I did say I had more to learn xD

 

And thanks for the Achievement ingiethingie!

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

  • 3 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.