Jump to content

Improving my crafting bench


bigbaddevil6

Recommended Posts

I have been working on a Prototyping table(A 5x5 crafting bench with 4 tool slots). I have an issue, plus trying to figure out if I want to continue it this way.

 

1. How do I get it so that the 4 separate slots act as TileEntity slots so that the 4 tools can go in there and stay there but are needed to do a recipe that will have them take damage. Kinda like how the Thaumcraft Crafting table does with its wand.

 

2. Since it seems like it may be a hassle to split between a Container and TileEntity like asked above, What would be the appropriate way to make the whole table a 5x5 crafting TileEntity where it just keeps all items in there.

 

Like I said above, I'm deciding to keep it like I have it in question 1, or to learn how to change it to act differently entirely.

 

Here is an idea of what the Table looks like to get a better idea:

Link to comment
Share on other sites

Those slots can already, natively, hold items.  Apply damage to the item stack.

 

The whole bench would then be a TileEntity that has an internal inventory (like a chest) to hold and contain those items.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Yea, I got the slots and I made my own version of Slot called SlotTool(mainly to make sure that only instances of my tool can go into it). I did have it where all items took damage but didn't like the concept. I would like to have it where you add the tools to the recipe as such:

this.addRecipe(new ItemStack(ModItems.goggles), new Object[]{"     ", " G G ", "GPLPG", " G G ", "     ", "SW", PH", 'G', Items.gold_ingot, 'P', Blocks.glass_pane 'L', Items.leather, 'S', ModItems.screwdriver, 'W', ModItems.saw, 'P', ModItems.pliers, 'H', ModItems.hammer});

 

The "SW" and "PH" refer to the bottom right 4 slots. That way I can easily determine what tools are needed for what recipe. The issue is I'm not sure how to point the findMatchingRecipe() to search those 4 slots for the tools.

 

This is currently how the slots are defined. At the moment ignore that they are not in a for loop. Mainly making sure this all works before optimizing it. Would it be better to add them to the craft matrix slots or keep them separate like how they are.

 

 

 

package com.bigbaddevil7.rustic.client.interfaces;

import com.bigbaddevil7.rustic.Rustic;

import com.bigbaddevil7.rustic.init.ModBlocks;
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 ContainerTable extends Container {

    public InventoryCrafting craftMatrix;
    public static InventoryCrafting toolSlot;
    public IInventory craftResult;
    private World worldObj;
    private int posX, posY, posZ;

    public ContainerTable(InventoryPlayer invPlayer, World world, int x, int y, int z){
        craftMatrix = new InventoryCrafting(this,5 ,5);
        toolSlot = new InventoryCrafting(this, 2, 2);
        craftResult = new InventoryCraftResult();
        worldObj = world;
        posX = x;
        posY = y;
        posZ = z;

        this.addSlotToContainer(new SlotCrafting(invPlayer.player, craftMatrix, craftResult, 0, 141, 11));


        this.addSlotToContainer(new SlotTool(toolSlot, 0, 115, 43));
        this.addSlotToContainer(new SlotTool(toolSlot, 1, 115, 79));
        this.addSlotToContainer(new SlotTool(toolSlot, 2, 151, 43));
        this.addSlotToContainer(new SlotTool(toolSlot, 3, 151, 79));


        for(int i = 0; i < 5; i++){
            for(int k = 0; k < 5; k++){
                this.addSlotToContainer(new Slot(craftMatrix, k + i * 5, 8 + k * 18, 7 + i * 18));
            }
        }

        for(int i = 0; i < 3; i++){
            for(int k  = 0; k < 9; k++){
                this.addSlotToContainer(new Slot(invPlayer, k + i * 9 + 9, 8 + k * 18, 106 + i * 18));
            }
        }

        for(int i = 0; i < 9; i++){
            this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 164));
        }

        onCraftMatrixChanged(craftMatrix);
    }

    public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)this.inventorySlots.get(par2);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (par2 == 0)
            {
                if (!this.mergeItemStack(itemstack1, 10, 46, true))
                {
                    return null;
                }

                slot.onSlotChange(itemstack1, itemstack);
            }
            else if (par2 >= 10 && par2 < 37)
            {
                if (!this.mergeItemStack(itemstack1, 37, 46, false))
                {
                    return null;
                }
            }
            else if (par2 >= 37 && par2 < 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(par1EntityPlayer, itemstack1);
        }

        return itemstack;
    }

    public void onContainerClosed(EntityPlayer par1EntityPlayer)
    {
        super.onContainerClosed(par1EntityPlayer);

        if (!this.worldObj.isRemote)
        {
            for (int i = 0; i < 25; ++i)
            {
                ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);

                if (itemstack != null)
                {
                    par1EntityPlayer.dropPlayerItemWithRandomChoice(itemstack, false);
                }
            }
            ItemStack itemStack2 = this.toolSlot.getStackInSlot(0);
                if(itemStack2 != null){
                    par1EntityPlayer.dropPlayerItemWithRandomChoice(itemStack2, false);
                }
        }
    }

    public void onCraftMatrixChanged(IInventory inventory){
        craftResult.setInventorySlotContents(0, CraftingManagerTable.getInstance().findMatchingRecipe(craftMatrix, worldObj));
    }


    @Override
    public boolean canInteractWith(EntityPlayer player) {
        if(worldObj.getBlock(posX, posY, posZ) != ModBlocks.blockTable){
            return false;
        }else{
            return player.getDistanceSq((double)posX + 0.5D, (double)posY + 0.5D, (double)posZ + 0.5D) <= 64.0D;
        }
    }

    public static boolean toolInSlot(){
            ItemStack itemStack = toolSlot.getStackInSlot(0);
            if(itemStack != null){
                return true;
            }else{
                return false;
            }
    }
}

 

 

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