Workbench code (help needed!)

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

Workbench code (help needed!)

by MirceaKitsune » Wed Jun 01, 2011 21:10

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):

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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 » Fri Jun 03, 2011 23:04

Why slavishly copy Minecraft?
 

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

by gnarvin » Sat Jun 04, 2011 02:03

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: 809
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

by MirceaKitsune » Sat Jun 04, 2011 12:26

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: 809
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

by MirceaKitsune » Wed Jun 15, 2011 00:44

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 » Wed Jun 15, 2011 19:57

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

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

by bahamada » Wed Jun 15, 2011 22:12

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 » Thu Aug 18, 2011 15:10

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: 809
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

by MirceaKitsune » Fri Aug 19, 2011 11:07

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 » Fri Aug 19, 2011 11:10

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 » Fri Aug 19, 2011 11:12

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 » Fri Aug 19, 2011 11:41

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

by No-Half-Measures » Fri Aug 19, 2011 13:45

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 » Fri Aug 19, 2011 15:03

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

by dannydark » Fri Aug 19, 2011 15:24

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

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

by No-Half-Measures » Sat Aug 20, 2011 10:24

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 » Sat Aug 20, 2011 12:12

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 » Mon Aug 22, 2011 06:43

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

by sdzen » Mon Aug 22, 2011 15:08

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.
[h]Zen S.D.[/h] 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

by No-Half-Measures » Mon Aug 22, 2011 21:11

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
Member
 
Posts: 3124
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou

by Calinou » Tue Aug 23, 2011 16:42

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

by dannydark » Tue Aug 23, 2011 17:46

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
 


Return to Minetest General

Who is online

Users browsing this forum: No registered users and 16 guests

cron