Jump to content

Recommended Posts

Posted

I'm trying to make a 5x5 crafting table and i want it to drop the items on close. Here's what I've tried:

public void onContainerClosed(EntityPlayer playerIn)

      {super.onContainerClosed(playerIn);

          for(int i=0;i<25;i++){if(te.getStackInSlot(i)!=null){

         

          ItemStack slot=new ItemStack(te.getStackInSlot(i).getItem(),1,te.getStackInSlot(i).getMetadata());

          te.removeStackFromSlot(i);

          worldIn.spawnEntityInWorld(new EntityItem(worldIn, playerIn.posX,playerIn.posY,playerIn.posZ,slot));}

          }

      }

Posted

Well, i'm trying to create a 5x5 crafting table with custom recipe. I've done the gui but i haven't got it to work properly yet. Can you help me with that?

Posted

here is the containermodcrafting:

 

package minh2908.ores.init.tileentity;

 

import minh2908.ores.init.TutorialBlocks;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.inventory.Container;

import net.minecraft.inventory.IInventory;

import net.minecraft.inventory.InventoryCraftResult;

import net.minecraft.inventory.InventoryCrafting;

import net.minecraft.inventory.Slot;

import net.minecraft.inventory.SlotCrafting;

import net.minecraft.item.ItemStack;

import net.minecraft.item.crafting.CraftingManager;

import net.minecraft.util.BlockPos;

import net.minecraft.world.World;

 

public class ContainerModCrafting extends Container {

public World worldIn;

    private World worldObj;

    private BlockPos pos;

    private EntityPlayer player;

    public InventoryCrafting craftMatrix = new InventoryCrafting(this, 5, 5);

   

        public IInventory craftResult = new InventoryCraftResult();

 

    public ContainerModCrafting(InventoryPlayer playerInventory, World worldIn, BlockPos posIn)

    {

        this.worldObj = worldIn;

        this.pos = posIn;

        this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 138,60));

 

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

        {

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

            {

                this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 5, 8 + j * 18, 23 + i * 18));

            }

        }

 

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

        {

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

            {

                this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 126 + k * 18));

            }

        }

 

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

        {

            this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 184));

        }

 

        this.onCraftMatrixChanged(this.craftMatrix);

    }

 

    public void onCraftMatrixChanged(IInventory inventoryIn)

    {

        this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));

    }

 

    public void onContainerClosed(EntityPlayer playerIn)

    {

        super.onContainerClosed(playerIn);

 

        if (!this.worldObj.isRemote)

        {

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

            {

                ItemStack itemstack = this.craftMatrix.removeStackFromSlot(i);

 

                if (itemstack != null)

                {

                    playerIn.dropPlayerItemWithRandomChoice(itemstack, false);

                }

            }

        }

    }

 

    public boolean canInteractWith(EntityPlayer playerIn)

    {

        return this.worldObj.getBlockState(this.pos).getBlock() != TutorialBlocks.big_crafting ? false : playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;

    }

 

    /**

    * Take a stack from the specified inventory slot.

    */

    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)

    {

        ItemStack itemstack = null;

        Slot slot = (Slot)this.inventorySlots.get(index);

 

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

        {

            ItemStack itemstack1 = slot.getStack();

            itemstack = itemstack1.copy();

 

            if (index == 0)

            {

                if (!this.mergeItemStack(itemstack1, 10, 46, true))

                {

                    return null;

                }

 

                slot.onSlotChange(itemstack1, itemstack);

            }

            else if (index >= 10 && index < 37)

            {

                if (!this.mergeItemStack(itemstack1, 37, 46, false))

                {

                    return null;

                }

            }

            else if (index >= 37 && index < 46)

            {

                if (!this.mergeItemStack(itemstack1, 10, 37, false))

                {

                    return null;

                }

            }

            else if (!this.mergeItemStack(itemstack1, 10, 46, false))

            {

                return null;

            }

 

            if (itemstack1.stackSize == 0)

            {

                slot.putStack((ItemStack)null);

            }

            else

            {

                slot.onSlotChanged();

            }

 

            if (itemstack1.stackSize == itemstack.stackSize)

            {

                return null;

            }

 

            slot.onPickupFromSlot(playerIn, itemstack1);

        }

 

        return itemstack;

    }

 

 

    public boolean canMergeSlot(ItemStack stack, Slot p_94530_2_)

    {

        return p_94530_2_.inventory != this.craftResult && super.canMergeSlot(stack, p_94530_2_);

    }

}

 

I've read somewhere that I need a crafting manager and something else in oreder to make custom recipe, but I haven't figure out how to do that yet

EDIT: I've found a solution. Thanks for your help earlier(that was for a half-crafting table)

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.