Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey guys, currently I am working on my custom crafting table and i need help with the container i think. When I want to place items inside the crafting grid they just get dublicated or teleported in other slots, here is my ContainerCrafter.class, when u want more code just tell me.

 

ContainerCrafter.class

 

 

package ml.xenon.atomdex.physics.containers;

 

 

import ml.xenon.atomdex.physics.blocks.ModBlocks;

import ml.xenon.atomdex.physics.blocks.TileEntityCrafter;

import ml.xenon.atomdex.physics.inventory.CraftingManagerCrafter;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

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.world.World;

 

public class ContainerCrafter extends Container {

 

protected TileEntityCrafter tile_entity;

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

    public IInventory craftResult = new InventoryCraftResult();

    private World worldObj;

    private int posX;

    private int posY;

    private int posZ;

 

    public static int InputSlotNumber = 10; //Number of Slots in the Crafting Grid

    public static int InOutputSlotNumber = InputSlotNumber + 1; //Same plus Output Slot

    public static int InventorySlotNumber = 36; //Inventory Slots (Inventory and Hotbar)

    public static int InventoryOutSlotNumber = InventorySlotNumber + 1; //Inventory Slot Number + Output

    public static int FullSlotNumber = InventorySlotNumber + InOutputSlotNumber; //All slots

   

   

   

    public ContainerCrafter(InventoryPlayer inventory, TileEntityCrafter tile){

 

 

    this.tile_entity = tile;

            int o=0;

            int var6;

            int var7;

            worldObj = tile.getWorldObj();

            posX = tile.xCoord;

            posY = tile.yCoord;

            posZ = tile.zCoord;

 

 

            addSlotToContainer(new SlotCrafting(inventory.player, this.craftMatrix, craftResult, 0, 135, 50));

           

            for (var6 = 0; var6 < 2; ++var6)

            {

                for (var7 = 0; var7 < 5; ++var7)

                {

                    this.addSlotToContainer(new Slot(this.craftMatrix, var7 + var6 * 3, 30 + var7 * 18, 17 + var6 * 18));

                }

            }

           

 

           

 

            for (var6 = 0; var6 < 3; ++var6)

            {

                for (var7 = 0; var7 < 9; ++var7)

                {

                    this.addSlotToContainer(new Slot(inventory, var7 + var6 * 9 + 9, 8 + var7 * 18, 84 + var6 * 18));

                }

            }

 

            for (var6 = 0; var6 < 9; ++var6)

            {

                this.addSlotToContainer(new Slot(inventory, var6, 8 + var6 * 18, 142));

            }

 

            this.onCraftMatrixChanged(this.craftMatrix);

         

         

           

          }

 

 

    @Override

    public void onCraftMatrixChanged(IInventory par1IInventory){

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

}

 

    @Override

    public void onContainerClosed(EntityPlayer p_75134_1_)

    {

        super.onContainerClosed(p_75134_1_);

 

        if (!this.worldObj.isRemote)

        {

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

            {

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

 

                if (itemstack != null)

                {

                    p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false);

                }

            }

        }

    }

 

   

    @Override

public boolean canInteractWith(EntityPlayer par1EntityPlayer){

if (worldObj.getBlock(posX, posY, posZ) != ModBlocks.crafter){

return false;

}

 

return par1EntityPlayer.getDistanceSq((double)posX + 0.5D, (double)posY + 0.5D, (double)posZ + 0.5D) <= 64D;

}

   

    @Override

    public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_)

    {

        return p_94530_2_.inventory != this.craftResult && super.func_94530_a(p_94530_1_, p_94530_2_);

    }

   

   

  @Override

  public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)

    {

        ItemStack var3 = null;

        Slot var4 = (Slot)this.inventorySlots.get(par2);

 

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

        {

            ItemStack var5 = var4.getStack();

            var3 = var5.copy();

 

            if (par2 == 0)

            {

                if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, true))

                {

                    return null;

                }

 

                var4.onSlotChange(var5, var3);

            }

            else if (par2 >= InOutputSlotNumber && par2 < InventoryOutSlotNumber)

            {

                if (!this.mergeItemStack(var5, InventoryOutSlotNumber, FullSlotNumber, false))

                {

                    return null;

                }

            }

            else if (par2 >= InventoryOutSlotNumber && par2 < FullSlotNumber)

            {

                if (!this.mergeItemStack(var5, InOutputSlotNumber, InventoryOutSlotNumber, false))

                {

                    return null;

                }

            }

            else if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, false))

            {

                return null;

            }

 

            if (var5.stackSize == 0)

            {

                var4.putStack((ItemStack)null);

            }

            else

            {

                var4.onSlotChanged();

            }

 

            if (var5.stackSize == var3.stackSize)

            {

                return null;

            }

 

            var4.onPickupFromSlot(par1EntityPlayer, var5);

        }

 

        return var3;

    }

}

 

 

 

I hope u can help me.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.