Workbench code (help needed!)

Post Reply
User avatar
MirceaKitsune
Member
Posts: 933
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune
Location: Romania, Bucharest

Workbench code (help needed!)

by MirceaKitsune » Post

I tried my first minetest coding attempt today. This change aims at implementing workbenches, that give you a 3 x 3 crafting area when right clicking them (whereas inventory crafting now gives you a 2 x 2 area, like in MineCraft). They are almost done and functional, but I have two major issues left. I'll quote from the TODO's in the code comments:
Workbench issue 1: As workbenches exist, the crafting area in the inventory window needs to be shrinked to 2 x 2 instead of 3 x 3, which is done below. That happens properly if for the "craft" area below, we set v2s32(2, 2) instead of v2s32(3, 3). However, that brakes the crafting pattern itself. eg: If you were putting four wood blocks in a square inside the 3 x 3 pattern (to obtain the workbench), it will no longer work in the 2 x 2 one, even if the items are in the same position. I could not figure out the adjustments to fix this.
Workbench issue 2: We need the items placed in the crafting pattern (as well as the craft result) to be inside the inventory of the workbench, not of the player. In order to achieve that, we need to use workbench_inv_id instead of "current_player" below. If we currently do that though, transferring the item and / or crafting will not work, without some advanced adjustments I could not figure out.
I'm looking for anyone who can look at my changes and help with fixing these problems, and would appreciate that. Here is the code for the current patch (apply as a normal HG .patch file):

Code: Select all

# HG changeset patch
# User Taoki@Taoki-PC
# Date 1306947411 -10800
# Node ID 28f6e4bca494ad800c165082340a74837269376f
# Parent  24182275f192844a575f9750a7098950ff8e9f1a
Attempt to implement the workbench. Please see the two TODOs for info on the last remaining issues.

diff -r 24182275f192 -r 28f6e4bca494 src/game.cpp
--- a/src/game.cpp    Tue May 31 20:02:55 2011 +0300
+++ b/src/game.cpp    Wed Jun 01 19:56:51 2011 +0300
@@ -1135,13 +1135,19 @@
                     client.getInventoryContext(),
                     &client);
 
+            // Workbench TODO 1 (by Taoki):
+            // As workbenches exist, the crafting area in the inventory window needs to be shrinked to 2 x 2 instead of 3 x 3, which is done below.
+            // That happens properly if for the "craft" area below, we set v2s32(2, 2) instead of v2s32(3, 3).
+            // However, that brakes the crafting pattern itself. eg: If you were putting four wood blocks in a square inside the 3 x 3 pattern (to obtain the workbench),
+            // it will no longer work in the 2 x 2 one, even if the items are in the same position. I could not figure out the adjustments to fix this.
+
             core::array<GUIInventoryMenu::DrawSpec> draw_spec;
             draw_spec.push_back(GUIInventoryMenu::DrawSpec(
                     "list", "current_player", "main",
                     v2s32(0, 3), v2s32(8, 4)));
             draw_spec.push_back(GUIInventoryMenu::DrawSpec(
                     "list", "current_player", "craft",
-                    v2s32(3, 0), v2s32(3, 3)));
+                    v2s32(3, 0), v2s32(2, 2)));
             draw_spec.push_back(GUIInventoryMenu::DrawSpec(
                     "list", "current_player", "craftresult",
                     v2s32(7, 1), v2s32(1, 1)));
@@ -1712,6 +1718,48 @@
                     menu->drop();
 
                 }
+                else if(meta && meta->typeId() == CONTENT_WORKBENCH && !random_input)
+                {
+                    dstream<<"Workbench node right-clicked"<<std::endl;
+
+                    WorkbenchNodeMetadata *workbenchmeta = (WorkbenchNodeMetadata*)meta;
+
+                    std::string workbench_inv_id;
+                    workbench_inv_id += "nodemeta:";
+                    workbench_inv_id += itos(nodepos.X);
+                    workbench_inv_id += ",";
+                    workbench_inv_id += itos(nodepos.Y);
+                    workbench_inv_id += ",";
+                    workbench_inv_id += itos(nodepos.Z);
+
+                    GUIInventoryMenu *menu =
+                        new GUIInventoryMenu(guienv, guiroot, -1,
+                            &g_menumgr, v2s16(8,7),
+                            client.getInventoryContext(),
+                            &client);
+
+                    // Workbench TODO 2 (by Taoki):
+                    // We need the items placed in the crafting pattern (as well as the craft result) to be inside the inventory of the workbench, not of the player.
+                    // In order to achieve that, we need to use workbench_inv_id instead of "current_player" below.
+                    // If we currently do that though, transferring the item and / or crafting will not work, without some advanced adjustments I could not figure out.
+
+                    core::array<GUIInventoryMenu::DrawSpec> draw_spec;
+
+                    draw_spec.push_back(GUIInventoryMenu::DrawSpec(
+                            "list", "current_player", "main",
+                            v2s32(0, 3), v2s32(8, 4)));
+                    draw_spec.push_back(GUIInventoryMenu::DrawSpec(
+                            "list", "current_player", "craft",
+                            v2s32(3, 0), v2s32(3, 3)));
+                    draw_spec.push_back(GUIInventoryMenu::DrawSpec(
+                            "list", "current_player", "craftresult",
+                            v2s32(7, 1), v2s32(1, 1)));
+
+                    menu->setDrawSpec(draw_spec);
+
+                    menu->drop();
+
+                }
                 else if(meta && meta->typeId() == CONTENT_FURNACE && !random_input)
                 {
                     dstream<<"Furnace node right-clicked"<<std::endl;
diff -r 24182275f192 -r 28f6e4bca494 src/mapnode.cpp
--- a/src/mapnode.cpp    Tue May 31 20:02:55 2011 +0300
+++ b/src/mapnode.cpp    Wed Jun 01 19:56:51 2011 +0300
@@ -342,6 +342,19 @@
     f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
     if(f->initial_metadata == NULL)
         f->initial_metadata = new ChestNodeMetadata();
+
+    i = CONTENT_WORKBENCH;
+    f = &g_content_features[i];
+    f->param_type = CPT_FACEDIR_SIMPLE;
+    f->setAllTextures("chest_side.png");
+    f->setTexture(0, "chest_top.png");
+    f->setTexture(1, "chest_top.png");
+    f->setTexture(5, "chest_front.png"); // Z-
+    f->setInventoryTexture("chest_top.png");
+    //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
+    f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
+    if(f->initial_metadata == NULL)
+        f->initial_metadata = new WorkbenchNodeMetadata();
     
     i = CONTENT_FURNACE;
     f = &g_content_features[i];
diff -r 24182275f192 -r 28f6e4bca494 src/mapnode.h
--- a/src/mapnode.h    Tue May 31 20:02:55 2011 +0300
+++ b/src/mapnode.h    Wed Jun 01 19:56:51 2011 +0300
@@ -96,7 +96,7 @@
 #define CONTENT_SIGN_WALL 14
 #define CONTENT_CHEST 15
 #define CONTENT_FURNACE 16
-//#define CONTENT_WORKBENCH 17
+#define CONTENT_WORKBENCH 17
 #define CONTENT_COBBLE 18
 #define CONTENT_STEEL 19
 #define CONTENT_GLASS 20
diff -r 24182275f192 -r 28f6e4bca494 src/materials.cpp
--- a/src/materials.cpp    Tue May 31 20:02:55 2011 +0300
+++ b/src/materials.cpp    Wed Jun 01 19:56:51 2011 +0300
@@ -76,6 +76,7 @@
     setWoodLikeDiggingProperties(CONTENT_FENCE, 0.75);
     setWoodLikeDiggingProperties(CONTENT_WOOD, 0.75);
     setWoodLikeDiggingProperties(CONTENT_CHEST, 1.0);
+    setWoodLikeDiggingProperties(CONTENT_WORKBENCH, 1.0);
 
     g_material_properties[CONTENT_SIGN_WALL].setDiggingProperties("",
             DiggingProperties(true, 0.5, 0));
diff -r 24182275f192 -r 28f6e4bca494 src/nodemetadata.cpp
--- a/src/nodemetadata.cpp    Tue May 31 20:02:55 2011 +0300
+++ b/src/nodemetadata.cpp    Wed Jun 01 19:56:51 2011 +0300
@@ -185,6 +185,61 @@
 }
 
 /*
+    WorkbenchNodeMetadata
+*/
+
+// Prototype
+WorkbenchNodeMetadata proto_WorkbenchNodeMetadata;
+
+WorkbenchNodeMetadata::WorkbenchNodeMetadata()
+{
+    NodeMetadata::registerType(typeId(), create);
+    
+    m_inventory = new Inventory();
+    m_inventory->addList("0", 3*3);
+}
+WorkbenchNodeMetadata::~WorkbenchNodeMetadata()
+{
+    delete m_inventory;
+}
+u16 WorkbenchNodeMetadata::typeId() const
+{
+    return CONTENT_WORKBENCH;
+}
+NodeMetadata* WorkbenchNodeMetadata::create(std::istream &is)
+{
+    WorkbenchNodeMetadata *d = new WorkbenchNodeMetadata();
+    d->m_inventory->deSerialize(is);
+    return d;
+}
+NodeMetadata* WorkbenchNodeMetadata::clone()
+{
+    WorkbenchNodeMetadata *d = new WorkbenchNodeMetadata();
+    *d->m_inventory = *m_inventory;
+    return d;
+}
+void WorkbenchNodeMetadata::serializeBody(std::ostream &os)
+{
+    m_inventory->serialize(os);
+}
+std::string WorkbenchNodeMetadata::infoText()
+{
+    return "Workbench";
+}
+bool WorkbenchNodeMetadata::nodeRemovalDisabled()
+{
+    /*
+        Disable removal if workbench contains something
+    */
+    InventoryList *list = m_inventory->getList("0");
+    if(list == NULL)
+        return false;
+    if(list->getUsedSlots() == 0)
+        return false;
+    return true;
+}
+
+/*
     FurnaceNodeMetadata
 */
 
diff -r 24182275f192 -r 28f6e4bca494 src/nodemetadata.h
--- a/src/nodemetadata.h    Tue May 31 20:02:55 2011 +0300
+++ b/src/nodemetadata.h    Wed Jun 01 19:56:51 2011 +0300
@@ -107,6 +107,25 @@
     Inventory *m_inventory;
 };
 
+class WorkbenchNodeMetadata : public NodeMetadata
+{
+public:
+    WorkbenchNodeMetadata();
+    ~WorkbenchNodeMetadata();
+    
+    virtual u16 typeId() const;
+    static NodeMetadata* create(std::istream &is);
+    virtual NodeMetadata* clone();
+    virtual void serializeBody(std::ostream &os);
+    virtual std::string infoText();
+    virtual Inventory* getInventory() {return m_inventory;}
+
+    virtual bool nodeRemovalDisabled();
+    
+private:
+    Inventory *m_inventory;
+};
+
 class FurnaceNodeMetadata : public NodeMetadata
 {
 public:
diff -r 24182275f192 -r 28f6e4bca494 src/server.cpp
--- a/src/server.cpp    Tue May 31 20:02:55 2011 +0300
+++ b/src/server.cpp    Wed Jun 01 19:56:51 2011 +0300
@@ -4116,6 +4116,21 @@
                 }
             }
 
+            // Workbench
+            if(!found)
+            {
+                ItemSpec specs[9];
+                specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
+                specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
+                specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
+                specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
+                if(checkItemCombination(items, specs))
+                {
+                    rlist->addItem(new MaterialItem(CONTENT_WORKBENCH, 1));
+                    found = true;
+                }
+            }
+
             // Furnace
             if(!found)
             {

harrison
New member
Posts: 3
Joined: Fri Jun 03, 2011 22:54

by harrison » Post

Why slavishly copy Minecraft?

gnarvin
New member
Posts: 7
Joined: Sat Apr 23, 2011 02:23

by gnarvin » Post

I kinda agree, I think it should be taken in a new direction, I think it be nice to have Workbench and if you combine 2 or more you could make a crafting Station or Work Table and you get a 4x4 grid or maybe a 4x5 grid and this will allow for much more recipes and many more intricate items. Idk but I would like to see something different then the standard workbench.

User avatar
MirceaKitsune
Member
Posts: 933
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune
Location: Romania, Bucharest

by MirceaKitsune » Post

I think Minetest already takes most ideas from Minecraft, so this wouldn't be something new. As long as it's a feature that makes sense and is good the way it is, I don't mind it copying MC. I judge things by how they work, not how much they copy. There will surely be other differences between the two, as Minetest evolves and becomes more complex.

A 4 x 4 or larger grid wouldn't make sense to me, because there's nothing that needs such a large space to craft. If there was, tools would take more materials too. Maybe if we add vehicles or larger objects, we could make a special crafting table for that size... but that would be something for the distant future (and should not replace the 3 x 3 workbench IMO).

For now, I find this workbench system easiest and most logical. We can think of new ideas, though I'm not sure what would be better and who can code anything more complex. Rather concerned with getting this code working for now, and fixing the remaining issues. The code is in waiting until anyone does, since I'm totally stuck with it.

User avatar
MirceaKitsune
Member
Posts: 933
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune
Location: Romania, Bucharest

by MirceaKitsune » Post

Just so everyone knows. The workbench code was finally finished today, and should be working exactly as intended and without any bugs. It's available in Minetest Delta, on the GIT remote https://github.com/MirceaKitsune/minetest-delta.git branch workbench (also in master, as I had merged it there). Credit goes to bahamada for doning half of the code, and helping where I got stuck. Currently, the workbench works exactly like the one in MineCraft, but I personally find that perfect.

Image

User avatar
Heinrich
Member
Posts: 27
Joined: Sat Jun 11, 2011 18:33

by Heinrich » Post

So without a workbench I won't get any tools?

bahamada
Member
Posts: 13
Joined: Sun May 15, 2011 18:07

by bahamada » Post

No as the most tools need 3x3...
But you can build torches, sticks and the workbench ;)

User avatar
Staffs
Member
Posts: 329
Joined: Thu Aug 04, 2011 13:16

by Staffs » Post

MirceaKitsune wrote:Just so everyone knows. The workbench code was finally finished today, and should be working exactly as intended and without any bugs. It's available in Minetest Delta, on the GIT remote https://github.com/MirceaKitsune/minetest-delta.git branch workbench (also in master, as I had merged it there). Credit goes to bahamada for doning half of the code, and helping where I got stuck. Currently, the workbench works exactly like the one in MineCraft, but I personally find that perfect.

Image
That link is broken is there another ?
I love mods :D

User avatar
MirceaKitsune
Member
Posts: 933
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune
Location: Romania, Bucharest

by MirceaKitsune » Post

Staffs wrote:That link is broken is there another ?
Odd. Means the branch got removed somehow, and I only have it on GIT. I should still have it locally though, and I'm not sure if it might have been merged by now. Probably was.

User avatar
Staffs
Member
Posts: 329
Joined: Thu Aug 04, 2011 13:16

by Staffs » Post

Well its not in delta though !
I love mods :D

User avatar
Staffs
Member
Posts: 329
Joined: Thu Aug 04, 2011 13:16

by Staffs » Post

Ohh shows up that .git in end isnt needed if you take .git off you see the full merged thing and your able to download The fork
I love mods :D

User avatar
Staffs
Member
Posts: 329
Joined: Thu Aug 04, 2011 13:16

by Staffs » Post

Ok i tried your fork but it didnt work somewhy textures didnt load, All textures were in data map but still didnt load.. Screenshot coming :D
Image
I love mods :D

No-Half-Measures
Member
Posts: 149
Joined: Tue Jul 26, 2011 00:42
Contact:

by No-Half-Measures » Post

Can i Point out the user that made the Workbench is MIA.

How ever i can help, Can you post your Complete debug.txt in the 'Code' tags and i can help from there.

User avatar
Staffs
Member
Posts: 329
Joined: Thu Aug 04, 2011 13:16

by Staffs » Post

Its so long i cant post it :D
I love mods :D

User avatar
dannydark
Member
Posts: 428
Joined: Fri Aug 12, 2011 21:28
Location: Manchester, UK

by dannydark » Post

PasteBin (http://pastebin.com/) :D

No-Half-Measures
Member
Posts: 149
Joined: Tue Jul 26, 2011 00:42
Contact:

by No-Half-Measures » Post

dannydark wrote:PasteBin (http://pastebin.com/) :D
Thanks danny ^^

@Staffs Delete you Debug.txt then re run Minetest jump in-game then quit and post that debug.txt

User avatar
Staffs
Member
Posts: 329
Joined: Thu Aug 04, 2011 13:16

by Staffs » Post

No-half-measures Currently my drivers are broken so i will talk later g2 wait some month :D :D
I love mods :D

hmmm
Member
Posts: 69
Joined: Sun Aug 07, 2011 17:49

by hmmm » Post

I don't really want a work bench. I want to play Minetest not Minecraft.
(although if it is larger than 3x3. Just think of all the new items you could make with a larger area to make them!)

User avatar
sdzen
Member
Posts: 1170
Joined: Fri Aug 05, 2011 22:33
Location: Paradise (your not allowed)

by sdzen » Post

if a workbench is made I believe that it should have something that sets it far apart from minecrafts workbench
Last edited by sdzen on Mon Aug 22, 2011 15:08, edited 1 time in total.

Zen S.D.

The next generation of tranquility!
malheureusement mon français n'est pas bon :<
Owner of the Zelo's
In game name: MuadTralk, spdtainted, sdzen, sd zen, sdzeno

No-Half-Measures
Member
Posts: 149
Joined: Tue Jul 26, 2011 00:42
Contact:

by No-Half-Measures » Post

sdzen wrote:if a workbench is made I believe that it should have something that sets it far apart from minecrafts workbench
hmmm wrote:I don't really want a work bench. I want to play Minetest not Minecraft.
(although if it is larger than 3x3. Just think of all the new items you could make with a larger area to make them!)

I Agree with both of you.

User avatar
Calinou
Moderator
Posts: 3169
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou
Location: Troyes, France
Contact:

by Calinou » Post

I disagree with the workbench anyway, it would make Minetest a rip-off of Minecraft. No point of playing Minetest if you bought Minecraft (like me), then.

User avatar
dannydark
Member
Posts: 428
Joined: Fri Aug 12, 2011 21:28
Location: Manchester, UK

by dannydark » Post

I think the benefits of having a workbench is that its adds a bit more of a challenge to the game as well as adding more life to the game (I tend to treat it like a companion cube on my minecraft travels), I personally think that a workbench would be nice, but like someone else said I think it should be different from the minecraft one (i.e. maybe bigger crafting area etc).

With being able to craft everything via the inventory screen it adds less fun to the game and means the game itself is a lot less challenging (personal opinion :D) much like the mese pick its easy to get and destroys everything instantly I would like to see maybe a superpickaxe command and the mese/gold pick being made fast but non-instant at breaking things (but thats another story).

Thing is you could also say the same about the furnace, minecraft has one so Minetest can't etc etc, I think if you get stuck in the mindset of if another game has something this game cant have it then you would eventually hit a point where you run out of ideas, It would be nice to take what Minecraft got right and improve on it and make Minetest the inspiration of future Minecraft updates :). Plus isn't Minetest a Infiniminer/Minecraft inspired game? yeh ok that doesn't mean it should clone everything they have done, but at least its not a creeper people are asking for hehe

Plus, It adds more content to the game! :D gotta love extra content haha

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests