diff options
Diffstat (limited to 'builtin/game/item.lua')
-rw-r--r-- | builtin/game/item.lua | 178 |
1 files changed, 13 insertions, 165 deletions
diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 2a4b4e38f..b49787987 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -5,8 +5,8 @@ local builtin_shared = ... local function copy_pointed_thing(pointed_thing) return { type = pointed_thing.type, - above = vector.new(pointed_thing.above), - under = vector.new(pointed_thing.under), + above = pointed_thing.above and vector.copy(pointed_thing.above), + under = pointed_thing.under and vector.copy(pointed_thing.under), ref = pointed_thing.ref, } end @@ -15,15 +15,6 @@ end -- Item definition helpers -- -function core.inventorycube(img1, img2, img3) - img2 = img2 or img1 - img3 = img3 or img1 - return "[inventorycube" - .. "{" .. img1:gsub("%^", "&") - .. "{" .. img2:gsub("%^", "&") - .. "{" .. img3:gsub("%^", "&") -end - function core.get_pointed_thing_position(pointed_thing, above) if pointed_thing.type == "node" then if above then @@ -37,144 +28,6 @@ function core.get_pointed_thing_position(pointed_thing, above) end end -function core.dir_to_facedir(dir, is6d) - --account for y if requested - if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then - - --from above - if dir.y < 0 then - if math.abs(dir.x) > math.abs(dir.z) then - if dir.x < 0 then - return 19 - else - return 13 - end - else - if dir.z < 0 then - return 10 - else - return 4 - end - end - - --from below - else - if math.abs(dir.x) > math.abs(dir.z) then - if dir.x < 0 then - return 15 - else - return 17 - end - else - if dir.z < 0 then - return 6 - else - return 8 - end - end - end - - --otherwise, place horizontally - elseif math.abs(dir.x) > math.abs(dir.z) then - if dir.x < 0 then - return 3 - else - return 1 - end - else - if dir.z < 0 then - return 2 - else - return 0 - end - end -end - --- Table of possible dirs -local facedir_to_dir = { - vector.new( 0, 0, 1), - vector.new( 1, 0, 0), - vector.new( 0, 0, -1), - vector.new(-1, 0, 0), - vector.new( 0, -1, 0), - vector.new( 0, 1, 0), -} --- Mapping from facedir value to index in facedir_to_dir. -local facedir_to_dir_map = { - [0]=1, 2, 3, 4, - 5, 2, 6, 4, - 6, 2, 5, 4, - 1, 5, 3, 6, - 1, 6, 3, 5, - 1, 4, 3, 2, -} -function core.facedir_to_dir(facedir) - return facedir_to_dir[facedir_to_dir_map[facedir % 32]] -end - -function core.dir_to_wallmounted(dir) - if math.abs(dir.y) > math.max(math.abs(dir.x), math.abs(dir.z)) then - if dir.y < 0 then - return 1 - else - return 0 - end - elseif math.abs(dir.x) > math.abs(dir.z) then - if dir.x < 0 then - return 3 - else - return 2 - end - else - if dir.z < 0 then - return 5 - else - return 4 - end - end -end - --- table of dirs in wallmounted order -local wallmounted_to_dir = { - [0] = vector.new( 0, 1, 0), - vector.new( 0, -1, 0), - vector.new( 1, 0, 0), - vector.new(-1, 0, 0), - vector.new( 0, 0, 1), - vector.new( 0, 0, -1), -} -function core.wallmounted_to_dir(wallmounted) - return wallmounted_to_dir[wallmounted % 8] -end - -function core.dir_to_yaw(dir) - return -math.atan2(dir.x, dir.z) -end - -function core.yaw_to_dir(yaw) - return vector.new(-math.sin(yaw), 0, math.cos(yaw)) -end - -function core.is_colored_paramtype(ptype) - return (ptype == "color") or (ptype == "colorfacedir") or - (ptype == "colorwallmounted") or (ptype == "colordegrotate") -end - -function core.strip_param2_color(param2, paramtype2) - if not core.is_colored_paramtype(paramtype2) then - return nil - end - if paramtype2 == "colorfacedir" then - param2 = math.floor(param2 / 32) * 32 - elseif paramtype2 == "colorwallmounted" then - param2 = math.floor(param2 / 8) * 8 - elseif paramtype2 == "colordegrotate" then - param2 = math.floor(param2 / 32) * 32 - end - -- paramtype2 == "color" requires no modification. - return param2 -end - local function has_all_groups(tbl, required_groups) if type(required_groups) == "string" then return (tbl[required_groups] or 0) ~= 0 @@ -323,12 +176,12 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2, end -- Place above pointed node - local place_to = vector.new(above) + local place_to = vector.copy(above) -- If node under is buildable_to, place into it instead (eg. snow) if olddef_under.buildable_to then log("info", "node under is buildable to") - place_to = vector.new(under) + place_to = vector.copy(under) end if core.is_protected(place_to, playername) then @@ -409,7 +262,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2, -- Run callback if def.after_place_node and not prevent_after_place then -- Deepcopy place_to and pointed_thing because callback can modify it - local place_to_copy = vector.new(place_to) + local place_to_copy = vector.copy(place_to) local pointed_thing_copy = copy_pointed_thing(pointed_thing) if def.after_place_node(place_to_copy, placer, itemstack, pointed_thing_copy) then @@ -420,7 +273,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2, -- Run script hook for _, callback in ipairs(core.registered_on_placenodes) do -- Deepcopy pos, node and pointed_thing because callback can modify them - local place_to_copy = vector.new(place_to) + local place_to_copy = vector.copy(place_to) local newnode_copy = {name=newnode.name, param1=newnode.param1, param2=newnode.param2} local oldnode_copy = {name=oldnode.name, param1=oldnode.param1, param2=oldnode.param2} local pointed_thing_copy = copy_pointed_thing(pointed_thing) @@ -548,7 +401,7 @@ function core.node_punch(pos, node, puncher, pointed_thing) -- Run script hook for _, callback in ipairs(core.registered_on_punchnodes) do -- Copy pos and node because callback can modify them - local pos_copy = vector.new(pos) + local pos_copy = vector.copy(pos) local node_copy = {name=node.name, param1=node.param1, param2=node.param2} local pointed_thing_copy = pointed_thing and copy_pointed_thing(pointed_thing) or nil callback(pos_copy, node_copy, puncher, pointed_thing_copy) @@ -589,7 +442,7 @@ function core.node_dig(pos, node, digger) local def = core.registered_nodes[node.name] -- Copy pos because the callback could modify it if def and (not def.diggable or - (def.can_dig and not def.can_dig(vector.new(pos), digger))) then + (def.can_dig and not def.can_dig(vector.copy(pos), digger))) then log("info", diggername .. " tried to dig " .. node.name .. " which is not diggable " .. core.pos_to_string(pos)) @@ -636,7 +489,7 @@ function core.node_dig(pos, node, digger) if def and def.preserve_metadata then local oldmeta = core.get_meta(pos):to_table().fields -- Copy pos and node because the callback can modify them. - local pos_copy = vector.new(pos) + local pos_copy = vector.copy(pos) local node_copy = {name=node.name, param1=node.param1, param2=node.param2} local drop_stacks = {} for k, v in pairs(drops) do @@ -668,7 +521,7 @@ function core.node_dig(pos, node, digger) -- Run callback if def and def.after_dig_node then -- Copy pos and node because callback can modify them - local pos_copy = vector.new(pos) + local pos_copy = vector.copy(pos) local node_copy = {name=node.name, param1=node.param1, param2=node.param2} def.after_dig_node(pos_copy, node_copy, oldmetadata, digger) end @@ -679,7 +532,7 @@ function core.node_dig(pos, node, digger) core.set_last_run_mod(origin.mod) -- Copy pos and node because callback can modify them - local pos_copy = vector.new(pos) + local pos_copy = vector.copy(pos) local node_copy = {name=node.name, param1=node.param1, param2=node.param2} callback(pos_copy, node_copy, digger) end @@ -744,13 +597,8 @@ core.nodedef_default = { -- Node properties drawtype = "normal", visual_scale = 1.0, - -- Don't define these because otherwise the old tile_images and - -- special_materials wouldn't be read - --tiles ={""}, - --special_tiles = { - -- {name="", backface_culling=true}, - -- {name="", backface_culling=true}, - --}, + tiles = {}, + special_tiles = {}, post_effect_color = {a=0, r=0, g=0, b=0}, paramtype = "none", paramtype2 = "none", |