Jump to content

Recommended Posts

Posted

Hi,

 

I've been trying to learn how to mod in Forge, and got some things working correctly like custom blocks, slabs and stairs.

 

What i wanted to do next is creating a custom crafting table that amongst other things keeps the items in the slots when closing. I've been spending quite some days now to try to get it work, but alas, to no avail.

 

I've made a custom block and I got a UI to load when right clicking the block, but I'm stuck with the crafting result slot. I've created a tile entity and a container, but the crafting recipe isn't updating when the items are placed in the crafting grid. I looked at the container and tile entity classes for the furnace, workbench and hopper but I can't get any further.

 

I think the problem is that the slots from the container and the itemstacks from the tile entity aren't referencing the same values or something like that.

 

Does anyone know of any custom workbench tutorials for 1.8 , or could tell me how to set up the slots and inventories inside the container constructor? I also can't seem to find how the UI is updated inside the workbench to display the new contents of a slot, and where (which function) the stacks of the crafting grid are decreased when something is crafted...

Posted

I finally got it to work after some extensive debugging. I'll clean up the code and test an idea I have, and then I'll come back and explain what the problem was and how to fix it in case someone has the same problem that I had.

Posted

Hi,

 

I had actually already looked at that example project. I hadn't seen the other page though.

 

The main problem is that those and many other examples aren't using the InventoryCrafting class with itemstacks that are persistent when closing and opening the UI.

 

Problems occur because normally, you would have an ItemStack array in a tile entity class which has the itemstacks for the slots. However, as the easiest way to get the crafting to work is to use the InventoryCrafting class, some problems arise as this class has its own ItemStack array. These two normally won't be synched and things just won't work. On top of that, the InventoryCrafting class takes a container as parameter for the constructor, so it can't be declared in the tile entity either.

 

I got things working by creating a container reference in the tile entity and synching the InventoryCrafting itemstacks and the itemstacks from the tile entity. This is however far from an elegant solution. I think the best way to tackle this problem is to create some custom classes that mimic the behaviour of the InventoryCrafting class. This is what I'll be trying now. I'll post the code if I get it to work. I was initially against this approach as it doesn't reuse as much of the vanilla code and requires more custom coding - even though most of it might just be copy-paste of existing methods...

 

 

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.