Jump to content

[1.7.10] Dual Input CRAFTING Table Help?


WeiseGuy

Recommended Posts

UPDATE: I have been able to pretty much get all this done, but the original classes I posted here are EXTREMELY outdated at this point as I've rewritten almost everything from scratch. Once I'm completely done, I'll update the post with the current and working code for reference to anyone else. If you go to the last post by me in this topic, I have current issues I am working on there.

 

I've been trying to make a multi-input crafting table, and I feel I'm REALLY close to completion, but I'm running into issues.

 

I had followed a tutorial for a custom crafting table but it took the standard 3x3, or 5x5, or 1x3, not a dual input where its one column and another column to equal a new item. This time I followed a dual input furnace tutorial and took out any fuel code which is where I am now and associated code is below. I really can't seem to find anything to give this mechanic available in a tutorial and can't really think of a mod that has two separate craftMatrices. Most tutorials seem to say "copy the workbench's container code" but that code is assuming an array of 3x3 (which I can modify to make a 1x1 or a 1x3 of course, but not sure how to do a 1x1 + 1x3). I think the other issue I'm having is this dual input furnace stuff was having me copy some code from the vanilla furnace, which again lies the issue of This is an instant craft if fuel requirements met (which I took fuel out of the code), and instant eats them to give output.

 

The concept:

 

Inputs:

  • I want to have a 1x1 input for tool/armor
  • I want to have a 1x3 input for modifier items I'm calling sockets

 

Output:

I want a 1x1 output that will take the inputs, look for a recipe, craft said item like a crafting table does, instantly, no need to wait, but not until player clicks on the output to get the result.

 

What I have working:

Currently have my gui displaying properly, the container seems good and holds items though I need to figure out how to limit which items can go in which slots, and I have a couple recipes created that work but they are INSTA-CRAFTED as in, as soon as the final item is in place it consumes the input and leaves the result.

 

Issues:

  • Input items consume as soon as valid crafting recipe is found, leaving resulting item only.
  • I need 1x1 to never be null, but my 1x3 to be shapeless. I can't figure out how to change my "canSocket()" code to allow slot 1/3 to be null for crafting.
  • Breaking my Block (which is tied to a TileEntity) drops the block, but all items in the container are zapped away from existence and disappear forever, I want to just have it to where I close the inventory the items are spit out like a normal crating table. - Solved!
  • I can't figure out how to say slot 0 is only instanceOf ItemTool / ItemArmor and slot 1, 2, 3 is only for instanceOf ItemSocket - Solved! isItemValid on SlotSocketStation added
  • I can't get shift click to place items in proper slots, probably due to above mentioned problem. Like, I think I can even place items into my output still, REALLY weird. - Solved
  • TODO on my part is once this is working this way, I need to figure out a nice way to add slots dynamically if possible since some tools will have 1 socket slot, others 3, but that's just dynamic GUI changes and won't be as bad once the basics are done.

 

Source Code (I think this is everything, let me know if you need another file):

www.YouTube.com/WeiseGamer

www.twitter.com/WeiseGamer

Link to comment
Share on other sites

UPDATE:

 

Well, I updated two classes:

 

SocketStationContainer.java - Updated! - http://pastebin.com/UTtkLTea - Fixed shift clicking, items go into right slots, only allows to shift click into TE if its of the right item type. Fun fact, found out Hoe's don't extend ItemTool, weird, haha. Also fixed the onContainerClosed so it now spits my items back out when GUI closes. Still can't specify what goes into each slot when I click an drag the item to it.

 

SlotSocketStation.java - Updated! - http://pastebin.com/f563JYhU - Attempted to make slots 1/2/3 only able to have a max stacksize of 1 with the new override. Didn't work, but realized I don't need to do that either so I've since removed the override. Fixed issue where now slots check for validation!

 

TileEntitySocketStation.kava - Updated! - http://pastebin.com/xhuSuYLw - Changed to IInventory instead of ISidedInventory. Removed related methods that were implemented for it. Redid read/write NBT. Stuff still auto crafts on its own though.

www.YouTube.com/WeiseGamer

www.twitter.com/WeiseGamer

Link to comment
Share on other sites

You know tinkers construct have done something similiar with their axe recipe. Check out tinkers tool forge source

 

I found it extremely difficult to try to figure out what the heck was going on. I will continue to look through and try to understand it though. I have like 15 tabs of code open from their GitHub. A couple modifier classes, some of the logic to determine whats modifiable, etc. Still trying to find where he says a 1x1 input (the tool) plus (in his case) a 2x2 (shapeless) input = 1x1 output so I can adopt to 1x1 + 1x3 (shapeless) = 1x1

www.YouTube.com/WeiseGamer

www.twitter.com/WeiseGamer

Link to comment
Share on other sites

You can also check the vanilla player inventory crafting thing which is a 2x2. Vanilla is usually easier to understand than the other modders code. You can use the 2x2 crafting table but you can make it so visually looks like 2x 1x2 crafting tables. What i mean is that your whole crafting table is 2x2 but you can use one row to make crafting recipe's for your weapons and the other row for whatever you wanted . You can seperate the slots a bit from each-other in your gui so it looks like they are indipendent from each-other. You don't really have to make 2 crafting tables in one. Simply make one but make it so it looks like 2 visually for the player. They won't see your code anyway, they will simply play the game and won't notice it.

Link to comment
Share on other sites

You can also check the vanilla player inventory crafting thing which is a 2x2. Vanilla is usually easier to understand than the other modders code. You can use the 2x2 crafting table but you can make it so visually looks like 2x 1x2 crafting tables. What i mean is that your whole crafting table is 2x2 but you can use one row to make crafting recipe's for your weapons and the other row for whatever you wanted . You can seperate the slots a bit from each-other in your gui so it looks like they are indipendent from each-other. You don't really have to make 2 crafting tables in one. Simply make one but make it so it looks like 2 visually for the player. They won't see your code anyway, they will simply play the game and won't notice it.

 

Well, tried that route, had some issues. I feel I was closer with another route. I also realized I don't need the tile entity since its insta-craft like a crafting table. The issue is vanilla's algorithms to take the addRecipe(Itemstack stack, Object ...) is COMPLEX and awesome, but hard for me to decipher. I'm working through that to see if I can emulate the addRecipe from vanilla into my mod to make recipe additions easier.

 

Currently did fix the recipe issue I had, after removing tile entity, adding some more checks for null, etc. Working hard to get it done, so close!

www.YouTube.com/WeiseGamer

www.twitter.com/WeiseGamer

Link to comment
Share on other sites

I GOT EVERYTHING WORKING!

 

Except one part...

 

Standard left/right click will call onCraftMatrixChanged which pulls my result from the crafting manager, I can click it to get said result and the input(s) decrements properly.

 

However,

 

Left click + drag into an input inventory

Right click + drag into input inventory.

 

These two functions do not seem to update the onCraftMatrixChanged and I am not sure where they are called. I checked the IInventory classes I created and the custom Slot Classes I made and don't see how to call onCraftMatrixChanged with these functions. It's only the "drag" functions whether its right or left click.

www.YouTube.com/WeiseGamer

www.twitter.com/WeiseGamer

Link to comment
Share on other sites

I think that vanilla has the code for what you want. I have worked before with a custom crafting table myself and i think that the part of the code that you want is in the end of either the chest code or crafting table code. I don't really remember though. There is a part of code that starts with moveStackinSlot. At least i think there is. Haven't worked with inventories in a while, and cannot open my IDE cause i am on my phone right now.

Link to comment
Share on other sites

I think that vanilla has the code for what you want. I have worked before with a custom crafting table myself and i think that the part of the code that you want is in the end of either the chest code or crafting table code. I don't really remember though. There is a part of code that starts with moveStackinSlot. At least i think there is. Haven't worked with inventories in a while, and cannot open my IDE cause i am on my phone right now.

 

I have transferStackInSlot which handles moving items from slot to slot and split stacks (I believe it also does the click+drag) but I can't seem to find a way to call the containers onCraftMatrixChanged method from there, and don't see vanilla doing it either.

 

That transferStackInSlot method does take the params of mouse button and such though.

 

EDIT: Also, will be home from work in a couple hours and can post updates to all the code I have now, let me know which classes you would want to see and I'll get it done.

www.YouTube.com/WeiseGamer

www.twitter.com/WeiseGamer

Link to comment
Share on other sites

EDIT: Also, will be home from work in a couple hours and can post updates to all the code I have now, let me know which classes you would want to see and I'll get it done.

 

I am sorry. I had a busy day yesterday. Post your GUI container code.

 

No worries, will do when I get home. I have to tweak one thing and I think I have it all actually. Since the post started, I've since made god knows how many commits/changes. I added custom IInventories, custom slots, custom everything it feels like, haha.

 

One thing I'm not sure, just yet at least, is where I would add NBT data if I wanted the output itemStack to have NBT Data of like, which items were used in the 1x3 area. These will be used for enchantments.

 

I'm doing research on that though, just haven't used NBT data yet so I'm working through source code to find it.

 

I'll reply with my code later today though.

www.YouTube.com/WeiseGamer

www.twitter.com/WeiseGamer

Link to comment
Share on other sites

Oh man i just realized that you had custom slots this whole time. Maybe that's the problem. Check the vanilla Slot source code in eclipse. Maybe there is some method that you can override in your CustomSlot that will fix the dragging problem.

 

Yeah...what I did last night (well, this morning too I guess, was up until about 2:30 AM).

 

Took my InputInventory that extends IInventory and mirrored vanilla's InventoryCrafting

Took my OutputInventory that extends IInventory and mirrored vanilla's equivalent.

Took my Input/Output slot and mirrored that of vanilla then went to Slot and ensured anything the vanilla extended wasn't causing issues.

etc etc etc with Container, Block, Slots, Inventories, IRecipe, Crafting Manager, etc.

 

Good news is, I have the ability to add a crafting recipe JUST like vanilla code which is badass IMO. Bad news is, vanilla is expecting 3x3 + output, which I changed to 2x3, but then only "draw" 1x 1x3 + output so the slot numbers are a little weird. I'm debugging with .getInventory() to count slot numbers (including null slots). Lots of fun!

 

Also found out (researching GIT Hub at work, oh yeah) a bit more on ItemStack NBT in that on the item class I can addInformation (tooltip) based on said NBT and on the same class can use onCrafted to add the NBT when its pulled out of the table.

 

Of course, this is all theory (in regards to NBT and onCraft) until I get home as remote desktop wants to lag my inputs and makes it hard to code from work when I remote into my home PC.

 

I feel maybe I should make a tutorial on how I did all this junk once I comment everything better and such as I still have yet to see a tutorial on creating a custom crafting table that uses a non-standard matrix, that is I'm using this format:

              [item]

[item] + [item] = [outputItem]

              [item]

www.YouTube.com/WeiseGamer

www.twitter.com/WeiseGamer

Link to comment
Share on other sites

Alright here is my container class, still can't get transferStackInSlot to work properly to get my items in there. Well, they all transfer properly to the right slots, but I can't figure out where to use my booleans to say if the item is valid or not. Got almost all of this from @BedrockMiner (http://bedrockminer.jimdo.com/modding-tutorials/advanced-modding/gui-container/)

 

    @Override
    public ItemStack transferStackInSlot(EntityPlayer player, int fromSlot) // Called when a player shift-clicks on a slots. You must override this or you will crash when someone does that.
    {
        ItemStack previous = null;
        Slot slot = (Slot) this.inventorySlots.get(fromSlot);

        if (slot != null && slot.getHasStack())
        {
            ItemStack current = slot.getStack();
            previous = current.copy();
            boolean slot2Valid = (current.getItem() instanceof ItemTool || current.getItem() instanceof ItemArmor || current.getItem() instanceof ItemHoe); //Checks if item going to slots 0 is Tool or Armor (or Hoe)
            boolean slot135Valid = (current.getItem() instanceof ItemSocket); //Checks if item going to slots 1, 3, or 5 is a Socket

            if (fromSlot < 5)
            {
                // From TE Inventory to Player Inventory
                if (!this.mergeItemStack(current, 5, 41, true))
                    return null;
            } else if(fromSlot > 4)
            {
                // From Player Inventory to TE Inventory (not including output of course)
                if (!this.mergeItemStack(current, 0, 4, false))
                    return null;
            }

            if (current.stackSize == 0)
                slot.putStack((ItemStack) null);
            else
                slot.onSlotChanged();

            if (current.stackSize == previous.stackSize)
                return null;
            slot.onPickupFromSlot(player, current);
        }
        return previous;
    }

 

 

EDIT:

 

Fixed it. Phew, all done. Now to figure out where to read the NBT when inputting the items to a recipe.

 

How would you do it in vanilla? Let's say one of the components is an item that has to have specific NBT data.

 

addRecipe(new ItemStack (ModItems.ModPick, 1), "XXX", " S ", " S ", 'X', ModItems.itemwithspecificNBT, 'S', Items.stick

 

Like, how do you reference item with NBT?

www.YouTube.com/WeiseGamer

www.twitter.com/WeiseGamer

Link to comment
Share on other sites

These items with nbt will be different or just one item. I mean do you have an item like books which use nbt for enchantements or the are different from each other

 

So the concept is a "bench" where I can "socket" an item like you would in Diablo or many other RPGs/games. This is basically adding a modifier in Tinker's Construct.

 

  • iron pick + empty socket = iron pick with NBT data that it has an empty socket
  • iron pick with empty socket NBT + FierySocket = iron pick with NBT data that says it has a fiery socket, which in turn allows for auto-smelt on ores.

 

I can make the ironPickWithEmptySocketNBT tool and use "onCrafted" to set NBT to say it has an empty socket every time its pulled out of a crafting table, as long as onCrafted allows me to use my socket bench and doesn't need to be in a workbench. But then on the input, how do I ask for item with only said NBT data?

 

Would I have to do something like....

 

ItemStack toolInput = ironPickWithEmptySocketNBT();
toolInput.stackTagCompound = new NBTTagCompound();
itemStack.stackTagCompound.setString("socket", ModItems.emptySocket.getUnlocalizedName());

if (itemStack.stackTagCompound != null)
{
     addRecipe(new ItemStack (ModItems.ironPickWithFierySocket), "  ", "IF", "  ", 'I', toolInput, 'F', ModItems.FierySocket
}

 

 

 

 

www.YouTube.com/WeiseGamer

www.twitter.com/WeiseGamer

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.