mirror of
https://github.com/joe7575/techpack.git
synced 2024-12-26 15:37:30 +01:00
fixing bug issue #50
This commit is contained in:
parent
a5c1fd6182
commit
0adb8dadff
@ -47,8 +47,8 @@ minetest.register_node(NODE_NAME, {
|
||||
can_dig = function(pos)
|
||||
return wh.can_dig(Box, pos)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
wh.after_dig_node(Box, pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
wh.on_dig_node(Box, pos, node, player)
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
return wh.allow_metadata_inventory_put(Box, pos, listname, index, stack, player)
|
||||
@ -58,7 +58,6 @@ minetest.register_node(NODE_NAME, {
|
||||
allow_metadata_inventory_move = wh.allow_metadata_inventory_move,
|
||||
|
||||
on_rotate = screwdriver.disallow,
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -47,8 +47,8 @@ minetest.register_node(NODE_NAME, {
|
||||
can_dig = function(pos)
|
||||
return wh.can_dig(Box, pos)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
wh.after_dig_node(Box, pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
wh.on_dig_node(Box, pos, node, player)
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
return wh.allow_metadata_inventory_put(Box, pos, listname, index, stack, player)
|
||||
@ -58,7 +58,6 @@ minetest.register_node(NODE_NAME, {
|
||||
allow_metadata_inventory_move = wh.allow_metadata_inventory_move,
|
||||
|
||||
on_rotate = screwdriver.disallow,
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -47,8 +47,8 @@ minetest.register_node(NODE_NAME, {
|
||||
can_dig = function(pos)
|
||||
return wh.can_dig(Box, pos)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
wh.after_dig_node(Box, pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
wh.on_dig_node(Box, pos, node, player)
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
return wh.allow_metadata_inventory_put(Box, pos, listname, index, stack, player)
|
||||
@ -58,7 +58,6 @@ minetest.register_node(NODE_NAME, {
|
||||
allow_metadata_inventory_move = wh.allow_metadata_inventory_move,
|
||||
|
||||
on_rotate = screwdriver.disallow,
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -323,10 +323,10 @@ function techpack_warehouse.can_dig(self, pos)
|
||||
return inv:is_empty("main") and inv:is_empty("shift")
|
||||
end
|
||||
|
||||
function techpack_warehouse.after_dig_node(self, pos, oldnode, oldmetadata, digger)
|
||||
function techpack_warehouse.on_dig_node(self, pos, node, digger)
|
||||
tubelib.remove_node(pos)
|
||||
if oldnode.name == self.node_name then -- not for defect nodes
|
||||
self.State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
if node.name == self.node_name then -- not for defect nodes
|
||||
self.State:on_dig_node(pos, node, digger)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -8,7 +8,6 @@ minetest.register_node("tubelib:defect_dummy", {
|
||||
"tubelib_front.png^tubelib_defect.png",
|
||||
"tubelib_front.png^tubelib_defect.png",
|
||||
},
|
||||
drop = "",
|
||||
groups = {cracky=3, crumbly=3, choppy=3, not_in_creative_inventory=1},
|
||||
is_ground_content = false,
|
||||
})
|
||||
|
@ -391,9 +391,9 @@ minetest.register_node("tubelib:distributor", {
|
||||
return inv:is_empty("src")
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
tubelib.remove_node(pos) -- <<=== tubelib
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
end,
|
||||
|
||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||
@ -403,7 +403,6 @@ minetest.register_node("tubelib:distributor", {
|
||||
on_timer = keep_running,
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -302,6 +302,7 @@ function NodeStates:keep_running(pos, meta, val, num_items)
|
||||
self:start(pos, meta, true)
|
||||
meta:set_int("tubelib_countdown", val)
|
||||
meta:set_int("tubelib_item_meter", meta:get_int("tubelib_item_meter") + (num_items or 1))
|
||||
|
||||
if self.aging_level1 then
|
||||
local cnt = meta:get_int("tubelib_aging") + num_items
|
||||
meta:set_int("tubelib_aging", cnt)
|
||||
@ -427,15 +428,39 @@ function NodeStates:on_node_repair(pos)
|
||||
return false
|
||||
end
|
||||
|
||||
-- Return working or defect machine, depending on machine lifetime
|
||||
function NodeStates:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
local inv = minetest.get_inventory({type="player", name=digger:get_player_name()})
|
||||
local cnt = oldmetadata.fields.tubelib_aging and tonumber(oldmetadata.fields.tubelib_aging)
|
||||
if not cnt or cnt < 1 then cnt = 1 end
|
||||
local is_defect = cnt > self.aging_level1 and math.random(math.max(1, math.floor(self.aging_level2 / cnt))) == 1
|
||||
if self.node_name_defect and is_defect then
|
||||
inv:add_item("main", ItemStack(self.node_name_defect))
|
||||
else
|
||||
inv:add_item("main", ItemStack(self.node_name_passive))
|
||||
|
||||
--[[
|
||||
Callback after digging a node but before removing the node.
|
||||
|
||||
The tubelib node becomes defect after digging it:
|
||||
- always if the aging counter "tubelib_aging" is greater than self.aging_level2
|
||||
- with a certain probability if the aging counter "tubelib_aging" is greater than self.aging_level1
|
||||
but smaller than self.aging_level2
|
||||
|
||||
Info: If a tubelib machine has been running quite some time but is dropped as a non-defect machine and then placed back again, the
|
||||
tubelib machine will be reset to new (digging will reset the aging counter). So this code tries to prevent this exploit
|
||||
|
||||
]]--
|
||||
function NodeStates:on_dig_node(pos, node, player)
|
||||
local meta = M(pos)
|
||||
local cnt = tonumber(meta:get_string("tubelib_aging"))
|
||||
if (not cnt or cnt < 1) then
|
||||
cnt = 1
|
||||
end
|
||||
|
||||
local is_defect = (cnt > self.aging_level1) and ( math.random(math.max(1, math.floor(self.aging_level2 / cnt))) == 1 )
|
||||
|
||||
if is_defect then
|
||||
self:defect(pos, meta) -- replace node with defect one
|
||||
node = minetest.get_node(pos)
|
||||
end
|
||||
|
||||
|
||||
minetest.node_dig(pos, node, player) -- default behaviour (this function is called automatically if on_dig() callback isn't set)
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -99,15 +99,14 @@ minetest.register_node("tubelib:pusher", {
|
||||
end
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
tubelib.remove_node(pos) -- <<=== tubelib
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
end,
|
||||
|
||||
on_timer = keep_running,
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -312,10 +312,10 @@ minetest.register_node("tubelib_addons1:autocrafter", {
|
||||
return inv:is_empty("dst") and inv:is_empty("src")
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
autocrafterCache[minetest.hash_node_position(pos)] = nil
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -326,7 +326,6 @@ minetest.register_node("tubelib_addons1:autocrafter", {
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -207,9 +207,9 @@ minetest.register_node("tubelib_addons1:fermenter", {
|
||||
end
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -219,7 +219,6 @@ minetest.register_node("tubelib_addons1:fermenter", {
|
||||
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -147,11 +147,12 @@ minetest.register_node("tubelib_addons1:grinder", {
|
||||
return inv:is_empty("dst") and inv:is_empty("src")
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
end,
|
||||
|
||||
|
||||
on_rotate = screwdriver.disallow,
|
||||
on_timer = keep_running,
|
||||
on_receive_fields = on_receive_fields,
|
||||
@ -159,7 +160,6 @@ minetest.register_node("tubelib_addons1:grinder", {
|
||||
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -336,8 +336,8 @@ minetest.register_node("tubelib_addons1:harvester_base", {
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
end,
|
||||
|
||||
@ -347,7 +347,6 @@ minetest.register_node("tubelib_addons1:harvester_base", {
|
||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -159,8 +159,8 @@ minetest.register_node("tubelib_addons1:liquidsampler", {
|
||||
return inv:is_empty("dst") and inv:is_empty("src")
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
end,
|
||||
|
||||
@ -171,7 +171,6 @@ minetest.register_node("tubelib_addons1:liquidsampler", {
|
||||
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -99,15 +99,14 @@ minetest.register_node("tubelib_addons1:pusher_fast", {
|
||||
end
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_timer = keep_running,
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -316,9 +316,9 @@ minetest.register_node("tubelib_addons1:quarry", {
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -327,7 +327,6 @@ minetest.register_node("tubelib_addons1:quarry", {
|
||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -203,9 +203,9 @@ minetest.register_node("tubelib_addons1:reformer", {
|
||||
end
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -215,7 +215,6 @@ minetest.register_node("tubelib_addons1:reformer", {
|
||||
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -359,9 +359,9 @@ minetest.register_node("tubelib_addons3:distributor", {
|
||||
local inv = M(pos):get_inventory()
|
||||
return inv:is_empty("src")
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
|
||||
on_dig = function(pos, node, player)
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
end,
|
||||
|
||||
@ -372,7 +372,6 @@ minetest.register_node("tubelib_addons3:distributor", {
|
||||
on_timer = keep_running,
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -84,15 +84,14 @@ minetest.register_node("tubelib_addons3:pusher", {
|
||||
end
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
State:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
end,
|
||||
|
||||
on_timer = keep_running,
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
@ -75,16 +75,6 @@ local function aging(pos, meta)
|
||||
end
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
local inv = minetest.get_inventory({type="player", name=digger:get_player_name()})
|
||||
local cnt = oldmetadata.fields.tubelib_aging and tonumber(oldmetadata.fields.tubelib_aging) or 0
|
||||
local is_defect = cnt > AGING_LEVEL1 and math.random(AGING_LEVEL2 / cnt) == 1
|
||||
if is_defect then
|
||||
inv:add_item("main", ItemStack("tubelib_addons3:pushing_chest_defect"))
|
||||
else
|
||||
inv:add_item("main", ItemStack("tubelib_addons3:pushing_chest"))
|
||||
end
|
||||
end
|
||||
|
||||
local function set_state(meta, state)
|
||||
local number = meta:get_string("number")
|
||||
@ -200,8 +190,8 @@ minetest.register_node("tubelib_addons3:pushing_chest", {
|
||||
return inv:is_empty("main") and inv:is_empty("shift")
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
on_dig = function(pos, node, player)
|
||||
State:on_dig_node(pos, node, player)
|
||||
tubelib.remove_node(pos)
|
||||
end,
|
||||
|
||||
@ -212,7 +202,6 @@ minetest.register_node("tubelib_addons3:pushing_chest", {
|
||||
on_timer = shift_items,
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
||||
drop = "",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
|
Loading…
Reference in New Issue
Block a user