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