Compare commits
4 Commits
9e665ce2f4
...
c983a6d2ac
Author | SHA1 | Date |
---|---|---|
Pascal Abresch | c983a6d2ac | |
Pascal Abresch | b2ac3b2808 | |
Pascal Abresch | 232f72eb0b | |
Pascal Abresch | 5d6d1cc4c1 |
|
@ -21,6 +21,7 @@ minetest.override_item("", {
|
|||
}
|
||||
})
|
||||
|
||||
|
||||
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
||||
if reason.type == "fall" then return 0, true end
|
||||
end, true)
|
||||
|
@ -97,6 +98,129 @@ minetest.register_chatcommand("resetscale", {
|
|||
end
|
||||
})
|
||||
|
||||
local function populateCreativeInventory(player)
|
||||
local inventory = player:get_inventory()
|
||||
inventory:set_list("crafting", nil)
|
||||
inventory:set_size("crafting", 500)
|
||||
for name, node in pairs(minetest.registered_nodes) do
|
||||
inventory:add_item("crafting", ItemStack(node.name .. " 256"))
|
||||
end
|
||||
--for name, item in pairs(minetest.registered_items) do
|
||||
-- inventory:add_item("crafting", ItemStack(item.name .. " 256"))
|
||||
--end
|
||||
for name, tools in pairs(minetest.registered_tools) do
|
||||
local newTool = ItemStack(tools.name)
|
||||
local meta = newTool:get_meta()
|
||||
local chargeable = tools.groups.sparktech_chargeable
|
||||
minetest.debug(dump2(tools))
|
||||
if chargeable then
|
||||
meta:set_int("energy", chargeable)
|
||||
newTool:set_wear(1)
|
||||
meta:set_tool_capabilities(tools.spark_caps_charge)
|
||||
end
|
||||
inventory:add_item("crafting", newTool)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
minetest.register_allow_player_inventory_action(function(player, action, inventory, inventory_info)
|
||||
-- action can be "move" "put" "take", the later two ONLY when NOT dealing with player-owned inventories
|
||||
--
|
||||
-- inventory info contains
|
||||
-- put: listname, index, stack
|
||||
-- take: listname, index, stack
|
||||
-- move: count, from_list, to_list, from_index, to_index
|
||||
-- player:get_meta():set_int("creative", 1)
|
||||
-- if player:get_meta():get_int("creative") == 1 then
|
||||
|
||||
if action == "move" -- There should be no movement inside the inventory by the player
|
||||
and inventory_info.from_list == "crafting"
|
||||
and inventory_info.to_list == "crafting" then
|
||||
return 0
|
||||
end
|
||||
|
||||
if minetest.is_creative_enabled(player) then
|
||||
-- allow players to move items here, to trash them.
|
||||
-- actual trashing is done in on_player_inventory_action
|
||||
-- Make sure destination is empty
|
||||
|
||||
-- TODO
|
||||
-- if the item that i am moving into the craft list at the position
|
||||
-- is the same as the one i am moving
|
||||
-- it should then in the on_inventory callback delete the ammount of items
|
||||
-- i am moving from the previous list
|
||||
-- (moving fails because the stack on the other side is already full)
|
||||
if action == "move"
|
||||
and inventory_info.to_list == "crafting" then
|
||||
local destItem = inventory:get_stack(inventory_info.to_list, inventory_info.to_index)
|
||||
if destItem:get_name() == "" then
|
||||
return inventory_info.count
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
if action == "put" then
|
||||
local destItem = inventory:get_stack(inventory_info.listname, inventory_info.index)
|
||||
if destItem:get_name() == "" then
|
||||
return inventory_info.stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
else
|
||||
if action == "move" -- Also nothing put into this inventory by the player
|
||||
and inventory_info.to_list == "crafting"
|
||||
or action == "put"
|
||||
and inventory_info.listname == "crafting" then
|
||||
return 0
|
||||
end
|
||||
|
||||
if action == "take" then
|
||||
return inventory_info.stack:get_count()
|
||||
end
|
||||
end
|
||||
|
||||
if action == "move"
|
||||
and inventory_info.from_list == "crafting" then
|
||||
return inventory_info.count
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
local maxStackSize = minetest.settings:get("default_stack_max") or 256
|
||||
minetest.register_on_player_inventory_action(function(player, action, inventory, inventory_info)
|
||||
-- Doc sais "is_creative_enabled" should get a player name,
|
||||
-- but builtin doesn't care so implement this later with
|
||||
-- taking a player object directly.. or else a name
|
||||
if minetest.is_creative_enabled(player) then -- think CREATIVELY!
|
||||
if action == "put"
|
||||
and inventoy_info.listname == "crafting" then
|
||||
inventory:set_stack(inventory_info.listname, inventory_into.index, ItemStack(""))
|
||||
end
|
||||
|
||||
if action == "move"
|
||||
and inventory_info.to_list == "crafting" then
|
||||
inventory:set_stack(inventory_info.to_list, inventory_info.to_index, ItemStack(""))
|
||||
end
|
||||
|
||||
if action == "take" then
|
||||
inventory:set_stack(inventory_info.listname, inventory_info.index, inventory_info.itemstack)
|
||||
end
|
||||
|
||||
if action == "move"
|
||||
and inventory_info.from_list == "crafting" then
|
||||
local stack = inventory:get_stack(inventory_info.to_list, inventory_info.to_index)
|
||||
stack:set_count(maxStackSize)
|
||||
inventory:set_stack(inventory_info.from_list, inventory_info.from_index, stack)
|
||||
end
|
||||
else -- survival crafting
|
||||
-- TODO: properly implement this.
|
||||
-- or implement it dirty and quick :3
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
player:set_properties({zoom_fov = 45})
|
||||
local meta = player:get_meta()
|
||||
|
@ -105,4 +229,18 @@ minetest.register_on_joinplayer(function(player)
|
|||
scale = make_scale(player)
|
||||
end
|
||||
update_scale(player, scale)
|
||||
|
||||
local inventory = player:get_inventory()
|
||||
--FIXMT: engine hardcodes this
|
||||
inventory:set_list("craft", nil)
|
||||
inventory:set_list("craftpreview", nil)
|
||||
inventory:set_list("craftresult", nil)
|
||||
|
||||
--player:set_lighting({shadows = { intensity = 0.33} })
|
||||
if minetest.is_creative_enabled(player) then
|
||||
populateCreativeInventory(player)
|
||||
end
|
||||
-- TODO: survival crafting
|
||||
local lists = inventory:get_lists()
|
||||
minetest.debug(dump2(minetest))
|
||||
end)
|
||||
|
|
|
@ -44,20 +44,28 @@ function sparktech.add_inventory(size_x, size_y, formspec)
|
|||
local fg_highlight = verify_hexcolor_or_nil(
|
||||
minetest.settings:get("spark_gui_highlight")) or DEFAULT_HL_COLOR
|
||||
local gui_immersive = minetest.settings:get("spark_gui_full") or "true"
|
||||
if not size_x or size_x < 13.9 then size_x = 13.9 end
|
||||
if not size_x or size_x < 16.5 then size_x = 16.5 end
|
||||
if not size_y or size_y < 0 then size_y = 0 end
|
||||
local offset = ( size_x - 13.9 ) / 2
|
||||
local offset = ( size_x - 16.5 ) / 2
|
||||
if offset < 0 then offset = 0 end
|
||||
|
||||
-- FIXMT: The scrollbaroptions stepsize is incomprehensible
|
||||
-- what do these options even mean they seem to have no relation to the inventory sizes whatsoever
|
||||
-- and configuring the scrollbar to scroll exactly one inventory piece per scroll event seems to be impossible.
|
||||
local l_formspec =
|
||||
"size[" .. tostring(size_x) .. "," .. (size_y + 4.8) .. "]" ..
|
||||
"real_coordinates[true]" ..
|
||||
"list[current_player;main;" ..offset .."," .. size_y .. ";8,3;8]" ..
|
||||
"list[current_player;main;" ..offset .. "," .. (size_y + 3.8 ) .. ";8,1;]"..
|
||||
"list[current_player;craft;" .. (10.4 + offset) .. "," .. size_y .. ";3,3]" ..
|
||||
"list[current_player;craftpreview;" .. (10.4 + offset) .."," .. (size_y + 3.8) .. ";1,1]" ..
|
||||
"list[current_player;main;" ..offset .. "," .. (size_y + 3.75 ) .. ";8,1;]"..
|
||||
"scroll_container[" .. (10.4 + offset) .. "," .. size_y .. ";5,5;craftingScroller;vertical;0.1]" ..
|
||||
"list[current_player;crafting;0,0;4,500]" ..
|
||||
"scroll_container_end[]" ..
|
||||
"scrollbaroptions[min=0;max=1000;smallstep=3]" ..
|
||||
"scrollbar["..(15.5 + offset)..",".. size_y.. ";.5,4.75;vertical;craftingScroller;0]" ..
|
||||
"listcolors[#" .. fg_color .. ";#" .. fg_highlight .. "]" ..
|
||||
"bgcolor[#" .. bg_color .. ";" .. gui_immersive .. "]"
|
||||
if not formspec then formspec = "" end
|
||||
l_formspec = l_formspec .. formspec
|
||||
return l_formspec
|
||||
end
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ minetest.register_node(NAME ..":charger", {
|
|||
local inventory = minetest.get_inventory({type="node", pos=pos})
|
||||
|
||||
if inventory:room_for_item(listname, itemstack) and
|
||||
minetest.get_item_group(itemstack:get_name(), "sparktech_chargable") > 0 then
|
||||
minetest.get_item_group(itemstack:get_name(), "sparktech_chargeable") > 0 then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
|
|
|
@ -28,7 +28,7 @@ minetest.register_tool(NAME .. ":handdrill", {
|
|||
range = 6.0,
|
||||
stack_max = 1,
|
||||
groups = {
|
||||
sparktech_chargable = CAPACITY
|
||||
sparktech_chargeable = CAPACITY
|
||||
},
|
||||
tool_capabilities = TOOL.CAPS.EMPTY,
|
||||
spark_caps_charge = TOOL.CAPS.FULL,
|
||||
|
|
|
@ -27,7 +27,7 @@ minetest.register_tool(NAME .. ":powersaw", {
|
|||
range = 6.0,
|
||||
stack_max = 1,
|
||||
groups = {
|
||||
sparktech_chargable = CAPACITY
|
||||
sparktech_chargeable = CAPACITY
|
||||
},
|
||||
tool_capabilities = TOOL.CAPS.EMPTY,
|
||||
spark_caps_charge = TOOL.CAPS.FULL,
|
||||
|
|
|
@ -171,7 +171,7 @@ minetest.register_tool(NAME .. ":scanner", {
|
|||
on_place = use_fun,
|
||||
on_secondary_use = use_fun,
|
||||
groups = {
|
||||
sparktech_chargable = CAPACITY
|
||||
sparktech_chargeable = CAPACITY
|
||||
},
|
||||
_sparktech_update_energy = function (itemstack)
|
||||
local meta = itemstack:get_meta()
|
||||
|
|
Loading…
Reference in New Issue