Add copper, and the beginnings of a machine system.

This commit is contained in:
Signal 2025-12-29 16:53:50 -05:00
parent 30ba6e5385
commit 1e897665bb
69 changed files with 976 additions and 135 deletions

View file

@ -2,28 +2,29 @@ local ns = rgt
ns.players = {}
Player = {
listeners = {},
new = function(p)
local e = setmetatable({
local m = setmetatable({
name = p:get_player_name(),
object = p
}, {__index = Player})
local inv = p:get_inventory()
inv:set_size("hand", 1)
e:set_hotbar_size(8)
m:set_hotbar_size(8)
e.textures = {_textures = {}}
setmetatable(e.textures, {
m.textures = {_textures = {}}
setmetatable(m.textures, {
__newindex = function(tbl, key, value)
tbl._textures[idx] = value
p:set_properties {
textures = tbl._textures
}
end,
__index = e.textures._textures
__index = m.textures._textures
})
e.hunger_bar = p:hud_add {
m.hunger_bar = p:hud_add {
type = "statbar",
position = {x=0.5,y=1},
offset = {x=10,y=-96},
@ -36,29 +37,31 @@ Player = {
text2 = "rgt_pumpkin_empty.png"
}
e.props = p:get_properties()
m.props = p:get_properties()
e.eye_height = 1.6
m.eye_height = 1.6
e.hud = {}
e.poi = {}
m.hud = {}
m.poi = {}
e.wearing = {}
m.wearing = {}
e.logical_height_offset = 0
e:update_hp(p:get_hp())
m.logical_height_offset = 0
m:update_hp(p:get_hp())
e.object:set_formspec_prepend [[
m.object:set_formspec_prepend [[
formspec_version[10]
bgcolor[#000;true;#000c]
background9[0,0;0,0;rgt_container_bg.png;true;16,16]
style_type[button;border=false;bgimg=rgt_button_bg.png;bgimg_middle=8,8]
style_type[button,image_button;border=false;bgimg=rgt_button_bg.png;bgimg_middle=8,8]
listcolors[#fff0;#fff3;#0000;#444;#aaa]
]]
e.inv = Inventory(p)
m.inv = Inventory(p)
return e
m:dispatch("init")
return m
end,
update_inv = function(m)
local fs = "\
@ -160,10 +163,12 @@ Player = {
m.dir = p:get_look_dir()
local pos = p:get_pos()
pos.y = pos.y +m.eye_height
local ctl = p:get_player_control()
-- Animation
if not m.in_third_person then
local c = p:get_player_control()
local c = ctl
local moving = c.up or c.down or c.left or c.right
if moving then
@ -206,7 +211,6 @@ Player = {
else -- Third-person camera
local c = m.camera.ref
local me = m.focus and m.focus.ref or false
local ctl = p:get_player_control()
-- local lv = p:get_look_vertical()
-- local lh = p:get_look_horizontal()
-- local ldir = p:get_look_dir()
@ -299,7 +303,7 @@ Player = {
m.last_time = time
end
-- Run on-hover callbacks
-- MARK: Pointing callbacks
m.pointed_node = nil
local pointed_found = false
@ -312,6 +316,11 @@ Player = {
if m.pointed_obj.on_unhover then
m.pointed_obj:on_unhover(m)
end
if m.pointed_obj.on_interact and m.interaction_marker then
m.object:hud_remove(m.interaction_marker)
m.interaction_marker = nil
m.interaction_start = nil
end
m.hover_trigger_range = nil
end
if (m.pointed_obj and not names_match and e.on_hover) or not m.pointed_obj then
@ -325,6 +334,17 @@ Player = {
pointed_found = true
break
end
if e.on_interact and not e._no_interact and (not names_match or names_match and not m.interaction_marker) and (not e._can_interact or e:_can_interact(m)) then
if m.interaction_marker then m.object:hud_remove(m.interaction_marker) end
local dst = e.object:get_pos()
if e._interact_marker_offset then dst = dst +e:_interact_marker_offset() end
m.interaction_marker = m.object:hud_add {
type = "image_waypoint",
world_pos = dst,
scale = {x=3, y=3},
text = "rgt_rmb.png"
}
end
end
elseif pointed and pointed.type == "node" and not m.pointed_node then
pointed.node_under = minetest.get_node(pointed.under)
@ -335,50 +355,47 @@ Player = {
if m.pointed_obj.on_unhover then
m.pointed_obj:on_unhover(m)
end
if m.pointed_obj.on_interact and m.interaction_marker then
m.object:hud_remove(m.interaction_marker)
m.interaction_marker = nil
m.interaction_start = nil
end
m.pointed_obj = nil
m.hover_trigger_range = nil
end
m.pos = pos
-- Hold-to-interact handling
if m.interacting_with and m.ctl.place then
-- MARK: Progressive interaction
if ctl.place and m.ctl.place and m.pointed_obj and m.pointed_obj.on_interact and not m.pointed_obj._no_interact and (not m.pointed_obj._can_interact or m.pointed_obj:_can_interact(m)) then
if not m.interaction_start then
m.interaction_start = time
m.interaction_marker = minetest.add_entity(m.pointed_node.under, "display")
m.interaction_marker:set_properties {
visual = "sprite",
textures = {"rgt_interact_progress_0.png"}
}
else
if time -m.interaction_start > 1100000 then
m.interaction_marker:remove()
minetest.registered_nodes[minetest.get_node(m.interacting_with).name].on_interact(m.interacting_with, m)
elseif time -m.interaction_start > 1000000 then
m.interaction_marker:set_properties {
textures = {"rgt_interact_progress_100.png"}
}
elseif time -m.interaction_start > 750000 then
m.interaction_marker:set_properties {
textures = {"rgt_interact_progress_75.png"}
}
elseif time -m.interaction_start > 500000 then
m.interaction_marker:set_properties {
textures = {"rgt_interact_progress_50.png"}
}
elseif time -m.interaction_start > 250000 then
m.interaction_marker:set_properties {
textures = {"rgt_interact_progress_25.png"}
}
local duration = (m.pointed_obj._interact_time or 1) *1000000
local progress = (time -m.interaction_start) /duration
if progress > 1.1 then
m.pointed_obj:on_interact(m)
m.interaction_start = nil
m.object:hud_remove(m.interaction_marker)
m.interaction_marker = nil
elseif progress > 1 then
m.object:hud_change(m.interaction_marker, "text", "rgt_rmb_100.png")
elseif progress > 0.75 then
m.object:hud_change(m.interaction_marker, "text", "rgt_rmb_75.png")
elseif progress > 0.5 then
m.object:hud_change(m.interaction_marker, "text", "rgt_rmb_50.png")
elseif progress > 0.25 then
m.object:hud_change(m.interaction_marker, "text", "rgt_rmb_25.png")
end
end
elseif m.interacting_with and not m.ctl.place then
m.interacting_with = nil
elseif not ctl.place and m.interaction_start and (not m.pointed_obj or not m.pointed_obj._no_interact or m.pointed_obj._can_interact and m.pointed_obj:_can_interact(m)) then
m.interaction_start = nil
m.interaction_marker:remove()
m.interaction_marker = nil
if m.interaction_marker then
m.object:hud_change(m.interaction_marker, "text", "rgt_rmb.png")
end
end
m.pos = pos
-- Run on_wield callbacks
local w = p:get_wielded_item()
local wname = w:get_name()
@ -397,6 +414,8 @@ Player = {
local while_wielded = def and def.while_wielded
if while_wielded then while_wielded(m, w) end
m:dispatch("tick")
end,
set_hotbar_size = function(m, slots)
local p = m.object
@ -409,13 +428,15 @@ Player = {
p:hud_set_hotbar_selected_image("rgt_hotbar_selected.png")
end,
deinit = function(m)
m:dispatch("deinit")
m.health_display:remove()
m.wielditem_display:remove()
rgt.players[m.name] = nil
end
}
setmetatable(Player, {
__call = function(_, ...) return Player.new(...) end
__call = function(_, ...) return Player.new(...) end,
__index = EventTarget
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B