[SOLVED] Some bugs with my workbench

User avatar
Esteban
Member
 
Posts: 872
Joined: Sun Sep 08, 2013 13:26
GitHub: Esteban-
IRC: Esteban
In-game: Esteban

[SOLVED] Some bugs with my workbench

by Esteban » Mon Jul 27, 2015 23:11

Hello, I wonder if anyone can help me fix some bugs I have with my workbench mod I have for my sub-game. The mod I am using is an edited version of darkrose's workbench mod (I know, it's pretty old).

I planned to use blockmen's version, but it was not compatible with the latest version of the armor mod, so I kept using darkrose's version instead since it didnt have dependencies on it. However, since the mod is old, it has some bugs, and I doubt I will get help from the creator...

If you know of a mod that adds a workbench apart of blockmen's I would really appreciate it. The only thing I would have to do is just change the craft recipe and close this thread. :)

If there are no other options,I would appreciate if someone could point out what causes the following problems:

A)Decreasing output: If I place the craft output in the crafting grid, it decreases the amount. Example, I place a wooden plank and I get 4 sticks. When I move the 4 sticks to the crafting grid, they are reduced to one stick.

B) Infinite output: Continuing the previous example, If I move that stick from the grid to the inventory, It does not remove the wooden planks. Thus, infinite sticks from a single wooden plank.

+ Visual representation


+ Edited Code from the mod
Last edited by Esteban on Tue Jul 28, 2015 19:17, edited 1 time in total.
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: [Help] Some bugs with my workbench

by Hybrid Dog » Tue Jul 28, 2015 17:46

l guess you need to make it remove the craft input when you take the output https://gist.github.com/HybridDog/d06d1 ... ch-lua-L98
what is post? https://gist.github.com/HybridDog/d06d1 ... h-lua-L127
 

User avatar
Esteban
Member
 
Posts: 872
Joined: Sun Sep 08, 2013 13:26
GitHub: Esteban-
IRC: Esteban
In-game: Esteban

Re: [Help] Some bugs with my workbench

by Esteban » Tue Jul 28, 2015 19:16

Hybrid Dog wrote:l guess you need to make it remove the craft input when you take the output https://gist.github.com/HybridDog/d06d1 ... ch-lua-L98

Thanks for pointing the problem out, but I changed the mod I was using. I found out that cornernote made an update to the code a long time ago, and so far it has no problems. I should've done a better search ...


I don't know, but it did appear a couple of times as an error in the log window of the game. Probably something I may have erased by accident.

Anyways, I appreciate your help , this tells more of how these weird formspec things work! :)

And for other peeps that want a crafting table/workbench, here is a copy for the updated code by cornernote:
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
-- init.lua
--
-- workbench minetest mod, by darkrose
-- Copyright (C) Lisa Milne 2012 <lisa@ltmnet.com>
--
-- updated by cornernote
-- Copyright (C) Brett O'Donnell 2012 <cornernote@gmail.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Lesser General Public License as
-- published by the Free Software Foundation, either version 2.1 of the
-- License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public
-- License along with this program.  If not, see
-- <http://www.gnu.org/licenses/>

-- expose api
workbench = {}

-- on_construct
workbench.on_construct = function(pos)
   local width = minetest.get_item_group(minetest.env:get_node(pos).name, "craft_width")
   local meta = minetest.env:get_meta(pos)
   local inv = meta:get_inventory()
   inv:set_size("craftresult", 1)
   inv:set_size("table", width*width)
   inv:set_width("craft", width)
   meta:set_string("formspec", "size[8,"..(width+4.5).."]"
      .."list[current_name;craftresult;6,2;1,1;]"
      .."list[current_player;main;0,"..(width+0.5)..";8,4;]"
      .."list[current_name;table;0,0;"..width..","..width..";]")
   meta:set_string("infotext", width.."x"..width.." WorkBench")
   meta:set_int("width", width)
end

-- can_dig
workbench.can_dig = function(pos,player)
   local meta = minetest.env:get_meta(pos);
   local inv = meta:get_inventory()
   if inv:is_empty("table") and inv:is_empty("craftresult") then
      return true
   end
   return false
end

-- allow_metadata_inventory_move
workbench.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
   if to_list == "craftresult" then
      return 0
   end
   if to_list == "table" then
      workbench.update_inventory(pos, true, true)
   end
   return count
end

-- allow_metadata_inventory_put
workbench.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
   if listname == "craftresult" then
      return 0
   end
   return stack:get_count()
end

-- allow_metadata_inventory_take
workbench.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
   return stack:get_count()
end

-- on_metadata_inventory_move
workbench.on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
   if to_list == "table" then
      workbench.update_inventory(pos)
   end
end

-- on_metadata_inventory_put
workbench.on_metadata_inventory_put = function(pos, listname, index, stack, player)
   if listname == "table" then
      workbench.update_inventory(pos)
   end
end

-- on_metadata_inventory_take
workbench.on_metadata_inventory_take = function(pos, listname, index, count, player)
   if listname == "table" then
      workbench.update_inventory(pos)
   elseif listname == "craftresult" then
      workbench.update_inventory(pos, true)
   end
end

-- update_inventory
workbench.update_inventory = function(pos,update_table,skip_update_craft)
   local meta = minetest.env:get_meta(pos)
   local inv = meta:get_inventory()
   local width = meta:get_int("width")
   local tablelist = inv:get_list("table")
   local crafted = nil
   local table_dec = nil

   -- update table
   if update_table then
      -- get craft result
      if tablelist then
         _, table_dec = minetest.get_craft_result({method = "normal", width = width, items = tablelist})
      end
      -- update table
      if table_dec then
         inv:set_list("table", table_dec.items)
      else
         inv:set_list("table", nil)
      end
      tablelist = table_dec.items
   end   

   -- update craft result
   if not skip_update_craft then
      -- get craft result
      if tablelist then
         crafted = minetest.get_craft_result({method = "normal", width = width, items = tablelist})
      end
      -- update craft result
      if crafted then
         inv:set_stack("craftresult", 1, crafted.item)
      else
         inv:set_stack("craftresult", 1, nil)
      end
   end
   
end

-- register
workbench.register = function(width, recipe)
   minetest.register_node("workbench:"..width.."x"..width, {
      description = "WorkBench "..width.."x"..width,
      tile_images = {"workbench_"..width.."x"..width.."_top.png","workbench_"..width.."x"..width.."_bottom.png","workbench_"..width.."x"..width.."_side.png"},
      paramtype2 = "facedir",
      groups = {cracky=2,craft_width=width},
      legacy_facedir_simple = true,
      sounds = default.node_sound_wood_defaults(),
      on_construct = workbench.on_construct,
      can_dig = workbench.can_dig,
      allow_metadata_inventory_move = workbench.allow_metadata_inventory_move,
      allow_metadata_inventory_put = workbench.allow_metadata_inventory_put,
      allow_metadata_inventory_take = workbench.allow_metadata_inventory_take,
      on_metadata_inventory_move = workbench.on_metadata_inventory_move,
      on_metadata_inventory_put = workbench.on_metadata_inventory_put,
      on_metadata_inventory_take = workbench.on_metadata_inventory_take,
   })
   minetest.register_craft({
      output = "workbench:"..width.."x"..width,
      recipe = recipe,
   })
end

-- register workbenches
workbench.register(3, {
   {"default:wood","default:wood"},
   {"default:wood","default:wood"},
})
workbench.register(4, {
   {"default:stone","default:stone","default:stone"},
   {"default:wood","default:wood","default:wood"},
   {"default:wood","default:wood","default:wood"},
})
workbench.register(5, {
   {"default:steel_ingot","default:steel_ingot","default:steel_ingot","default:steel_ingot"},
   {"default:wood","default:wood","default:wood","default:wood"},
   {"default:wood","default:wood","default:wood","default:wood"},
   {"default:wood","default:wood","default:wood","default:wood"},
})

 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

Re: [SOLVED] Some bugs with my workbench

by BrandonReese » Tue Jul 28, 2015 20:00

I know you solved your problem, but there is also a good workbench mod from MirceaKitsune. It's going to be faster than cornernote's workbench mob because this one uses your native crafting grid.

https://github.com/MirceaKitsune/minete ... _workbench
 

User avatar
Esteban
Member
 
Posts: 872
Joined: Sun Sep 08, 2013 13:26
GitHub: Esteban-
IRC: Esteban
In-game: Esteban

Re: [SOLVED] Some bugs with my workbench

by Esteban » Tue Jul 28, 2015 20:14

BrandonReese wrote:I know you solved your problem, but there is also a good workbench mod from MirceaKitsune. It's going to be faster than cornernote's workbench mob because this one uses your native crafting grid.

https://github.com/MirceaKitsune/minete ... _workbench


Wow! Thanks for the suggestion! :D
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron