Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Recipes.


YoWazzup
 Share

Recommended Posts

Hey everybody!

 

Last week or so I posted a topic here that showed my coed and my error, well no I fixed that and everything is working, but how do I add the recipes? Here's my code:

 

TileEntity:


package net.minecraft.src.CocoCraft.Misc;

import java.util.List;
import net.minecraft.src.*;

public class TileEntityAlloynizer extends TileEntity
    implements IInventory
{
    private ItemStack furnaceItemStacks[];
    public int furnaceBurnTime;
    public int currentItemBurnTime;
    public int furnaceCookTime;

    public TileEntityAlloynizer()
    {
        furnaceItemStacks = new ItemStack[7];
        furnaceBurnTime = 0;
        currentItemBurnTime = 0;
        furnaceCookTime = 0;
    }

    public int getSizeInventory()
    {
        return furnaceItemStacks.length;
    }

   

    public ItemStack decrStackSize(int i, int j)
    {
        if (furnaceItemStacks[i] != null)
        {
            if (furnaceItemStacks[i].stackSize <= j)
            {
                ItemStack itemstack = furnaceItemStacks[i];
                furnaceItemStacks[i] = null;
                return itemstack;
            }
            ItemStack itemstack1 = furnaceItemStacks[i].splitStack(j);
            if (furnaceItemStacks[i].stackSize == 0)
            {
                furnaceItemStacks[i] = null;
            }
            return itemstack1;
        }
        else
        {
            return null;
        }
    }

    public void setInventorySlotContents(int i, ItemStack itemstack)
    {
        furnaceItemStacks[i] = itemstack;
        if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
        {
            itemstack.stackSize = getInventoryStackLimit();
        }
    }

    public String getInvName()
    {
        return "Alloynizer";
    }

    public void readFromNBT(NBTTagCompound nbttagcompound)
    {
        super.readFromNBT(nbttagcompound);
        NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
        furnaceItemStacks = new ItemStack[getSizeInventory()];
        for (int i = 0; i < nbttaglist.tagCount(); i++)
        {
            NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
            byte byte0 = nbttagcompound1.getByte("Slot");
            if (byte0 >= 0 && byte0 < furnaceItemStacks.length)
            {
                furnaceItemStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
            }
        }

        furnaceBurnTime = nbttagcompound.getShort("BurnTime");
        furnaceCookTime = nbttagcompound.getShort("CookTime");
        currentItemBurnTime = getItemBurnTime(furnaceItemStacks[1]);
    }

    public void writeToNBT(NBTTagCompound nbttagcompound)
    {
        super.writeToNBT(nbttagcompound);
        nbttagcompound.setShort("BurnTime", (short)furnaceBurnTime);
        nbttagcompound.setShort("CookTime", (short)furnaceCookTime);
        NBTTagList nbttaglist = new NBTTagList();
        for (int i = 0; i < furnaceItemStacks.length; i++)
        {
            if (furnaceItemStacks[i] != null)
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte)i);
                furnaceItemStacks[i].writeToNBT(nbttagcompound1);
                nbttaglist.appendTag(nbttagcompound1);
            }
        }

        nbttagcompound.setTag("Items", nbttaglist);
    }

    public int getInventoryStackLimit()
    {
        return 64;
    }

    public int getCookProgressScaled(int i)
    {
        return (furnaceCookTime * i) / 200;
    }

    public int getBurnTimeRemainingScaled(int i)
    {
        if (currentItemBurnTime == 0)
        {
            currentItemBurnTime = 200;
        }
        return (furnaceBurnTime * i) / currentItemBurnTime;
    }

    public boolean isBurning()
    {
        return furnaceBurnTime > 0;
    }

    public void updateEntity()
    {
        boolean flag = furnaceBurnTime > 0;
        boolean flag1 = false;
        if (furnaceBurnTime > 0)
        {
            furnaceBurnTime-= 2;
        }
        if (!worldObj.isRemote)
        {
            if (furnaceBurnTime == 0 && canSmelt())
            {
                currentItemBurnTime = furnaceBurnTime = getItemBurnTime(furnaceItemStacks[7]);
                if (furnaceBurnTime > 0)
                {
                    flag1 = true;
                    if (furnaceItemStacks[1] != null)
                    {
                        if (furnaceItemStacks[1].getItem().func_46056_k())
                        {
                            furnaceItemStacks[1] = new ItemStack(furnaceItemStacks[1].getItem().setFull3D());
                        }
                        else
                        {
                            furnaceItemStacks[1].stackSize--;
                        }
                        if (furnaceItemStacks[1].stackSize == 0)
                        {
                            furnaceItemStacks[1] = null;
                        }
                    }
                }
            }
            if (isBurning() && canSmelt())
            {
                furnaceCookTime+= 2;
                if (furnaceCookTime == 200)
                {
                    furnaceCookTime = 0;
                    smeltItem();
                    flag1 = true;
                }
            }
            else
            {
                furnaceCookTime = 0;
            }
        }
        if (flag1)
        {
            onInventoryChanged();
        }
    }

    private boolean canSmelt()
    {
        ItemStack result = getRecipe(furnaceItemStacks[0], furnaceItemStacks[1], furnaceItemStacks[2], furnaceItemStacks[3], furnaceItemStacks[4]);
        if(result == null) return false;
        if(furnaceItemStacks[2] == null) return true;
        if(furnaceItemStacks[2] != null && furnaceItemStacks[2].itemID == result.itemID&& furnaceItemStacks[2].stackSize < (furnaceItemStacks[2].getMaxStackSize() - (result.stackSize-1))) return true;
        return false;
    }

    public void smeltItem()
    {
        if (!canSmelt())
        {
            return;
        }
        ItemStack itemstack = getRecipe(furnaceItemStacks[0], furnaceItemStacks[1], furnaceItemStacks[2], furnaceItemStacks[3], furnaceItemStacks[4]);
        if (furnaceItemStacks[2] == null)
        {
            furnaceItemStacks[2] = itemstack.copy();
        }
        else if (furnaceItemStacks[2].itemID == itemstack.itemID)
        {
            furnaceItemStacks[2].stackSize+= itemstack.stackSize;
        }
        if(furnaceItemStacks[0] != null){
                furnaceItemStacks[0].stackSize--;
            if (furnaceItemStacks[0].stackSize <= 0)
            {
                furnaceItemStacks[0] = null;
            }
        }
        if(furnaceItemStacks[3] != null){
                furnaceItemStacks[3].stackSize--;
            if (furnaceItemStacks[3].stackSize <= 0)
            {
                furnaceItemStacks[3] = null;
            }
        }
    }

    private int getItemBurnTime(ItemStack itemstack)
    {
        if (itemstack == null)
        {
            return 0;
        }
        int i = itemstack.getItem().shiftedIndex;
        if (i == mod_CocoCraft.MagicDust.shiftedIndex)
        {
            return 800;
        }
        else
        {
            return 0;
        }
    }

    public boolean isUseableByPlayer(EntityPlayer entityplayer)
    {
        if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)
        {
            return false;
        }
        return entityplayer.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64D;
    }

    public void openChest()
    {
    }

    public void closeChest()
    {
    }

    @Override
    public ItemStack getStackInSlotOnClosing(int var1) {
        return null;
    }

    private ItemStack getRecipe(ItemStack itemStack, ItemStack itemStack0, ItemStack itemStack1, ItemStack itemStack2, ItemStack itemStack3) {
        int i1;
        int i2;
        int i3;
        int i4;
        int i5;
        if(itemStack == null) i1 = 0; else i1 = itemStack.itemID;
        if(itemStack0 == null) i2 = 0; else i2 = itemStack0.itemID;
        if(itemStack1 == null) i3 = 0; else i3 = itemStack1.itemID;
        if(itemStack2 == null) i4 = 0; else i4 = itemStack2.itemID;
        if(itemStack3 == null) i5 = 0; else i5 = itemStack3.itemID;
       
        
        
        if(i1 == Block.blockDiamond.blockID && i2 == Block.blockGold.blockID) return new ItemStack(Block.blockDiamond, 2);
        if(i2 == Block.blockDiamond.blockID && i1 == Block.blockGold.blockID) return new ItemStack(Block.blockDiamond, 2);
        if(i1 == Item.diamond.shiftedIndex && i2 == mod_CocoCraft.CocoIngot.shiftedIndex && i3 == mod_CocoCraft.MithrilIngot.shiftedIndex && i4 == Item.coal.shiftedIndex && i5 == Item.coal.shiftedIndex) return new ItemStack(mod_CocoCraft.Alloy, 2);
        
        return null;
    }


public ItemStack getStackInSlot(int var1)
{
	return this.furnaceItemStacks[var1];
}

    
}

 

Block:

package net.minecraft.src.CocoCraft.Blocks;

import net.minecraft.src.CocoCraft.Misc.*;
import net.minecraft.src.*;

import java.util.ArrayList;
import java.util.Random;

public class BlockAlloynizer extends BlockContainer
{
    private Random rand = new Random();
    private final boolean isActive;
    
     private static boolean keepFurnaceInventory = false;

    public BlockAlloynizer(int id, boolean flag)
    {
        super(id, Material.rock);
        isActive = flag;
    }
    public boolean isOpaqueCube() {
        return false;
    }
    
    public void addCreativeItems(ArrayList itemList) {
        itemList.add(new ItemStack(this));
    }

    public boolean renderAsNormalBlock() {
        return true;
    }
    
    /**
     * Called whenever the block is added into the world. Args: world, x, y, z
     */
    public void onBlockAdded(World world, int x, int y, int z)
    {
        super.onBlockAdded(world, x, y, z);
        this.setDefaultDirection(world, x, y, z);
    }

    /**
     * set a blocks direction
     */
    private void setDefaultDirection(World world, int x, int y, int z)
    {
        if (!world.isRemote)
        {
            int var5 = world.getBlockId(x, y, z - 1);
            int var6 = world.getBlockId(x, y, z + 1);
            int var7 = world.getBlockId(x - 1, y, z);
            int var8 = world.getBlockId(x + 1, y, z);
            byte var9 = 3;

            if (Block.opaqueCubeLookup[var5] && !Block.opaqueCubeLookup[var6])
            {
                var9 = 3;
            }

            if (Block.opaqueCubeLookup[var6] && !Block.opaqueCubeLookup[var5])
            {
                var9 = 2;
            }

            if (Block.opaqueCubeLookup[var7] && !Block.opaqueCubeLookup[var8])
            {
                var9 = 5;
            }

            if (Block.opaqueCubeLookup[var8] && !Block.opaqueCubeLookup[var7])
            {
                var9 = 4;
            }

            world.setBlockMetadataWithNotify(x, y, z, var9);
        }
    }

   
    public int getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l)
{
	if(l == 1)
	{
		return mod_CocoCraft.DuplicatorSide;
	}
	if(l == 0)
	{
		return mod_CocoCraft.DuplicatorSide;
	}
	int i1 = iblockaccess.getBlockMetadata(i, j, k);
        if(l != i1)
        {
            return mod_CocoCraft.DuplicatorSide;
        }
        else
        {
            return mod_CocoCraft.DuplicatorFront;
        }
}
    public int getBlockTextureFromSide(int side)
    {
	if (side == 3)
	{
		return mod_CocoCraft.DuplicatorFront;
	}
	else
	{
		return mod_CocoCraft.DuplicatorSide;
	}
    }
    /**
     * Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the
     * block.
     */
    public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player)
    {
        if (world.isRemote)
        {
            return true;
        }
        else
        {
        	TileEntityAlloynizer tile = (TileEntityAlloynizer)world.getBlockTileEntity(x, y, z);

            if (tile != null)
            {
            	GuiAlloynizer GUI = new GuiAlloynizer(player.inventory, tile);
                ModLoader.openGUI(player, GUI);
            }

            return true;
        }
    }

    /**

    /**
     * Returns the TileEntity used by this block.
     */
    public TileEntity getBlockEntity()
    {
        return new TileEntityAlloynizer();
    }

    /**
     * Called when the block is placed in the world.
     */
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entity)
    {
        int var6 = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

        if (var6 == 0)
        {
            world.setBlockMetadataWithNotify(x, y, z, 2);
        }

        if (var6 == 1)
        {
            world.setBlockMetadataWithNotify(x, y, z, 5);
        }

        if (var6 == 2)
        {
            world.setBlockMetadataWithNotify(x, y, z, 3);
        }

        if (var6 == 3)
        {
            world.setBlockMetadataWithNotify(x, y, z, 4);
        }
    }

    /**
     * Called whenever the block is removed.
     */
    public void onBlockRemoval(World world, int x, int y, int z)
    {
        if (!keepFurnaceInventory)
        {
        	TileEntityAlloynizer tile = (TileEntityAlloynizer)world.getBlockTileEntity(x, y, z);

            if (tile != null)
            {
                for (int var6 = 0; var6 < tile.getSizeInventory(); ++var6)
                {
                    ItemStack var7 = tile.getStackInSlot(var6);

                    if (var7 != null)
                    {
                        float var8 = this.rand.nextFloat() * 0.8F + 0.1F;
                        float var9 = this.rand.nextFloat() * 0.8F + 0.1F;
                        float var10 = this.rand.nextFloat() * 0.8F + 0.1F;

                        while (var7.stackSize > 0)
                        {
                            int var11 = this.rand.nextInt(21) + 10;

                            if (var11 > var7.stackSize)
                            {
                                var11 = var7.stackSize;
                            }

                            var7.stackSize -= var11;
                            EntityItem var12 = new EntityItem(world, (double)((float)x + var8), (double)((float)y + var9), (double)((float)z + var10), new ItemStack(var7.itemID, var11, var7.getItemDamage()));

                            if (var7.hasTagCompound())
                            {
                                var12.item.setTagCompound((NBTTagCompound)var7.getTagCompound().copy());
                            }

                            float var13 = 0.05F;
                            var12.motionX = (double)((float)this.rand.nextGaussian() * var13);
                            var12.motionY = (double)((float)this.rand.nextGaussian() * var13 + 0.2F);
                            var12.motionZ = (double)((float)this.rand.nextGaussian() * var13);
                            world.spawnEntityInWorld(var12);
                        }
                    }
                }
            }
        }

        super.onBlockRemoval(world, x, y, z);
    }
}

 

Container:

 

package net.minecraft.src.CocoCraft.Misc;

import net.minecraft.src.CocoCraft.*;
import net.minecraft.src.CocoCraft.Misc.TileEntityAlloynizer;
import net.minecraft.src.*;
import java.util.Random;

public class ContainerAlloynizer extends Container
{
    private TileEntityAlloynizer furnace;
    private int lastCookTime;
    private int lastBurnTime;
    private int lastItemBurnTime;

    public ContainerAlloynizer(InventoryPlayer inventoryplayer, TileEntityAlloynizer tile)
    {
        lastCookTime = 0;
        lastBurnTime = 0;
        lastItemBurnTime = 0;
        furnace = tile;
        //Fuel
        //input 6
        this.addSlot(new Slot(tile, 1, 44, 62));
        
        //Inputs
        //input 1
        this.addSlot(new Slot(tile, 0, 11, 17));
        //input 2
        this.addSlot(new Slot(tile, 3, 33, 17));
        //input 3
        this.addSlot(new Slot(tile, 4, 56, 17));
        //input 4
        this.addSlot(new Slot(tile, 5, 22, 36));
        //input 5
        this.addSlot(new Slot(tile, 6, 44, 36));
        
        this.addSlot(new SlotFurnace(inventoryplayer.player, tile, 2, 116, 35));
        for (int i = 0; i < 3; i++)
        {
            for (int k = 0; k < 9; k++)
            {
                addSlot(new Slot(inventoryplayer, k + i * 9 + 9, 8 + k * 18, 84 + i * 18));
            }
        }

        for (int j = 0; j < 9; j++)
        {
            addSlot(new Slot(inventoryplayer, j, 8 + j * 18, 142));
        }
    }

    public void updateCraftingResults()
    {
        super.updateCraftingResults();
        for (int i = 0; i < crafters.size(); i++)
        {
            ICrafting icrafting = (ICrafting)crafters.get(i);
            if (lastCookTime != furnace.furnaceCookTime)
            {
                icrafting.updateCraftingInventoryInfo(this, 0, furnace.furnaceCookTime);
            }
            if (lastBurnTime != furnace.furnaceBurnTime)
            {
                icrafting.updateCraftingInventoryInfo(this, 1, furnace.furnaceBurnTime);
            }
            if (lastItemBurnTime != furnace.currentItemBurnTime)
            {
                icrafting.updateCraftingInventoryInfo(this, 2, furnace.currentItemBurnTime);
            }
        }

        lastCookTime = furnace.furnaceCookTime;
        lastBurnTime = furnace.furnaceBurnTime;
        lastItemBurnTime = furnace.currentItemBurnTime;
    }

    public void updateProgressBar(int i, int j)
    {
        if (i == 0)
        {
            furnace.furnaceCookTime = j;
        }
        if (i == 1)
        {
            furnace.furnaceBurnTime = j;
        }
        if (i == 2)
        {
            furnace.currentItemBurnTime = j;
        }
    }

    public boolean canInteractWith(EntityPlayer entityplayer)
    {
        return furnace.isUseableByPlayer(entityplayer);
    }

    public ItemStack transferStackInSlot(int i)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)inventorySlots.get(i);
        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();
            if (i == 2)
            {
                if (!mergeItemStack(itemstack1, 3, 39, true))
                {
                    return null;
                }
            }
            else if (i >= 3 && i < 30)
            {
                if (!mergeItemStack(itemstack1, 30, 39, false))
                {
                    return null;
                }
            }
            else if (i >= 30 && i < 39)
            {
                if (!mergeItemStack(itemstack1, 3, 30, false))
                {
                    return null;
                }
            }
            else if (!mergeItemStack(itemstack1, 3, 39, 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;
    }
}

 

Gui and Slot class aren't needed for this. Also as you may see in my TileEntity class there is a methods thas seems to add a recipe, but does not work, it does, however, work in another tile entity class, but thas furnace only has 2 inputs, this one 5.

 

Help would really be appreciated.

 

YoWazzup

 

Link to comment
Share on other sites

You can look at my pulverizerManager and pulverizerRecipe classes.

github.com/atrain99/greenenergymod/

It's in net/minecraft/src/GreenEnergy/Biomass.

So, what would happen if I did push that shiny red button over there? ... Really? ... Can I try it? ... Damn.

Link to comment
Share on other sites

Make it a list of ItemStacks.

Like:

public class AlloynizerRecipe{
    private ItemStack[] inputs = new ItemStack[5];
    private ItemStack output;
    public AlloyNizerRecipe(ItemStack[] in, ItemStack out){
        //Assign variables here
        ...
    }
    //Getter methods here
}

Then you just modify the Manager class as needed.

Then you can: (In your class that does work)

if(AlloynizerRecipeManager.isRecipe(Args here)){
   //Alloynize!
   ...
}

So, what would happen if I did push that shiny red button over there? ... Really? ... Can I try it? ... Damn.

Link to comment
Share on other sites

Make it a list of ItemStacks.

Like:

public class AlloynizerRecipe{
    private ItemStack[] inputs = new ItemStack[5];
    private ItemStack output;
    public AlloyNizerRecipe(ItemStack[] in, ItemStack out){
        //Assign variables here
        ...
    }
    //Getter methods here
}

Then you just modify the Manager class as needed.

Then you can: (In your class that does work)

if(AlloynizerRecipeManager.isRecipe(Args here)){
   //Alloynize!
   ...
}

 

Okay, I'll try and mess with that!

Link to comment
Share on other sites

look at the class file class FurnaceRecipes. It does the entire recipe list for minecraft furnace plus has hooks to allow for adding new recipes from other classes.

 

I know, i use 2 modified versions of that, and with one item to a new item's simple. With 5 I just can't figure out.

Link to comment
Share on other sites

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.