mirror of
https://github.com/minetest-mods/hopper.git
synced 2024-12-22 13:22:28 +01:00
Refactor the hopper place function
This commit is contained in:
parent
c691f370b4
commit
d0c8e18c5a
@ -18,24 +18,30 @@ local function get_hopper_formspec(pos)
|
|||||||
return formspec
|
return formspec
|
||||||
end
|
end
|
||||||
|
|
||||||
local hopper_on_place = function(itemstack, placer, pointed_thing, node_name)
|
|
||||||
local pos = pointed_thing.under
|
|
||||||
local pos2 = pointed_thing.above
|
|
||||||
local x = pos.x - pos2.x
|
|
||||||
local z = pos.z - pos2.z
|
|
||||||
|
|
||||||
local returned_stack, success
|
|
||||||
-- unfortunately param2 overrides are needed for side hoppers even in the non-single-craftable-item case
|
-- unfortunately param2 overrides are needed for side hoppers even in the non-single-craftable-item case
|
||||||
-- because they are literally *side* hoppers - their spouts point to the side rather than to the front, so
|
-- because they are literally *side* hoppers - their spouts point to the side rather than to the front, so
|
||||||
-- the default item_place_node orientation code will not orient them pointing toward the selected surface.
|
-- the default item_place_node orientation code will not orient them pointing toward the selected surface.
|
||||||
if x == -1 and (hopper.config.single_craftable_item or node_name == "hopper:hopper_side") then
|
local hopper_on_place = function(itemstack, placer, pointed_thing, node_name)
|
||||||
returned_stack, success = minetest.item_place_node(ItemStack("hopper:hopper_side"), placer, pointed_thing, 0)
|
local returned_stack, success
|
||||||
elseif x == 1 and (hopper.config.single_craftable_item or node_name == "hopper:hopper_side") then
|
|
||||||
returned_stack, success = minetest.item_place_node(ItemStack("hopper:hopper_side"), placer, pointed_thing, 2)
|
if not (hopper.config.single_craftable_item or node_name == "hopper:hopper_side") then
|
||||||
elseif z == -1 and (hopper.config.single_craftable_item or node_name == "hopper:hopper_side") then
|
returned_stack, success = minetest.item_place_node(itemstack, placer, pointed_thing)
|
||||||
returned_stack, success = minetest.item_place_node(ItemStack("hopper:hopper_side"), placer, pointed_thing, 3)
|
return returned_stack
|
||||||
elseif z == 1 and (hopper.config.single_craftable_item or node_name == "hopper:hopper_side") then
|
end
|
||||||
returned_stack, success = minetest.item_place_node(ItemStack("hopper:hopper_side"), placer, pointed_thing, 1)
|
|
||||||
|
local pointed_pos = pointed_thing.under
|
||||||
|
local hopper_pos = pointed_thing.above
|
||||||
|
|
||||||
|
local param2_by_offset = {
|
||||||
|
[vector.new(-1, 0, 0):to_string()] = 0,
|
||||||
|
[vector.new( 0, 0, 1):to_string()] = 1,
|
||||||
|
[vector.new( 1, 0, 0):to_string()] = 2,
|
||||||
|
[vector.new( 0, 0,-1):to_string()] = 3,
|
||||||
|
}
|
||||||
|
local param2 = param2_by_offset[(pointed_pos - hopper_pos):to_string()]
|
||||||
|
|
||||||
|
if param2 then
|
||||||
|
returned_stack, success = minetest.item_place_node(ItemStack("hopper:hopper_side"), placer, pointed_thing, param2)
|
||||||
else
|
else
|
||||||
if hopper.config.single_craftable_item then
|
if hopper.config.single_craftable_item then
|
||||||
node_name = "hopper:hopper" -- For cases where single_craftable_item was set on an existing world and there are still side hoppers in player inventories
|
node_name = "hopper:hopper" -- For cases where single_craftable_item was set on an existing world and there are still side hoppers in player inventories
|
||||||
@ -44,7 +50,7 @@ local hopper_on_place = function(itemstack, placer, pointed_thing, node_name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if success then
|
if success then
|
||||||
local meta = minetest.get_meta(pos2)
|
local meta = minetest.get_meta(hopper_pos)
|
||||||
meta:set_string("placer", placer:get_player_name())
|
meta:set_string("placer", placer:get_player_name())
|
||||||
if not minetest.settings:get_bool("creative_mode") then
|
if not minetest.settings:get_bool("creative_mode") then
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
|
Loading…
Reference in New Issue
Block a user