mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-26 09:03:01 +00:00
Does this finally fix the zombie marker wall bug?
only time will tell.
This commit is contained in:
parent
8a5979d89a
commit
f4471dfa8e
3 changed files with 49 additions and 9 deletions
|
@ -13,7 +13,19 @@ local function make_id()
|
||||||
return tostring(wea_c.get_ms_time()) .. "_" .. tostring(math.floor(math.random() * 1000000))
|
return tostring(wea_c.get_ms_time()) .. "_" .. tostring(math.floor(math.random() * 1000000))
|
||||||
end
|
end
|
||||||
|
|
||||||
local last_reset = make_id()
|
local last_resets = {}
|
||||||
|
|
||||||
|
--- Gets the last_reset value for the given player.
|
||||||
|
-- @internal
|
||||||
|
-- @param player_name string The name of the player to fetch the last_reset value for.
|
||||||
|
-- @param update=false bool If true, then update the last_reset value for the given player to a new value.
|
||||||
|
local function get_last_reset(player_name, update)
|
||||||
|
if update == nil then update = false end
|
||||||
|
if last_resets[player_name] == nil or update then
|
||||||
|
last_resets[player_name] = make_id()
|
||||||
|
end
|
||||||
|
return last_resets[player_name]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local WEAPositionMarkerWall = {
|
local WEAPositionMarkerWall = {
|
||||||
|
@ -38,7 +50,7 @@ local WEAPositionMarkerWall = {
|
||||||
|
|
||||||
on_activate = function(self, staticdata)
|
on_activate = function(self, staticdata)
|
||||||
local data = minetest.parse_json(staticdata)
|
local data = minetest.parse_json(staticdata)
|
||||||
if type(data) ~= "table" or data.id ~= last_reset then
|
if type(data) ~= "table" or data.id ~= get_last_reset(data.player_name) then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -56,7 +68,6 @@ local WEAPositionMarkerWall = {
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
on_punch = function(self, _)
|
on_punch = function(self, _)
|
||||||
print("DEBUG:pos_marker_wall on_punch")
|
|
||||||
anchor.delete(self)
|
anchor.delete(self)
|
||||||
-- Only unmark the rest of the walls
|
-- Only unmark the rest of the walls
|
||||||
-- Unmark for the player that created this wall.... NOT the player who punched it!
|
-- Unmark for the player that created this wall.... NOT the player who punched it!
|
||||||
|
@ -80,6 +91,20 @@ minetest.register_entity(
|
||||||
WEAPositionMarkerWall
|
WEAPositionMarkerWall
|
||||||
)
|
)
|
||||||
|
|
||||||
|
--- Checks the given entity for whether it's in the current generation of wall markers or not.
|
||||||
|
-- Only entities of type worldeditadditions:marker_wall will be removed.
|
||||||
|
-- @param entity ObjectRef The entity to check.
|
||||||
|
local function check_entity(entity)
|
||||||
|
if entity == nil
|
||||||
|
or entity.name ~= "worldeditadditions:marker_wall"
|
||||||
|
or entity.__id == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if entity.__id ~= get_last_reset(entity.player_name) then
|
||||||
|
entity.object:remove()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Updates the properties of a single wall to match it's side and size
|
--- Updates the properties of a single wall to match it's side and size
|
||||||
local function single_setup(entity, size, side)
|
local function single_setup(entity, size, side)
|
||||||
|
@ -140,12 +165,12 @@ local function create_single(player_name, pos1, pos2, side)
|
||||||
|
|
||||||
local pos_centre = ((pos2 - pos1) / 2) + pos1
|
local pos_centre = ((pos2 - pos1) / 2) + pos1
|
||||||
local entity = minetest.add_entity(pos_centre, "worldeditadditions:marker_wall", minetest.write_json({
|
local entity = minetest.add_entity(pos_centre, "worldeditadditions:marker_wall", minetest.write_json({
|
||||||
id = last_reset,
|
id = get_last_reset(player_name),
|
||||||
size = pos2 - pos1,
|
size = pos2 - pos1,
|
||||||
side = side,
|
side = side,
|
||||||
player_name = player_name
|
player_name = player_name
|
||||||
}))
|
}))
|
||||||
-- print("DEBUG:marker_wall create_single --> START player_name", player_name, "pos1", pos1, "pos2", pos2, "side", side, "SPAWN", pos_centre, "last_reset", last_reset)
|
-- print("DEBUG:marker_wall create_single --> START player_name", player_name, "pos1", pos1, "pos2", pos2, "side", side, "SPAWN", pos_centre, "last_reset", get_last_reset(playyer_name))
|
||||||
|
|
||||||
-- entity:get_luaentity().player_name = player_name
|
-- entity:get_luaentity().player_name = player_name
|
||||||
|
|
||||||
|
@ -473,8 +498,9 @@ local function delete(entitylist)
|
||||||
entity:remove()
|
entity:remove()
|
||||||
end
|
end
|
||||||
|
|
||||||
last_reset = make_id()
|
-- BUG: There can be multiple sets of walls, but this last_reset solution does not handle that.......
|
||||||
-- print("DEBUG:marker_wall delete --> LAST_RESET is now", last_reset, "type", type(last_reset))
|
get_last_reset(player_name, true)
|
||||||
|
-- print("DEBUG:marker_wall delete --> LAST_RESET is now", last_reset, "type", type(get_last_reset(last_reset)))
|
||||||
|
|
||||||
anchor:emit("delete", {
|
anchor:emit("delete", {
|
||||||
player_name = player_name
|
player_name = player_name
|
||||||
|
@ -486,6 +512,7 @@ end
|
||||||
anchor = EventEmitter.new({
|
anchor = EventEmitter.new({
|
||||||
create = create_wall,
|
create = create_wall,
|
||||||
delete = delete,
|
delete = delete,
|
||||||
|
check_entity = check_entity,
|
||||||
__single_setup = single_setup
|
__single_setup = single_setup
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ end
|
||||||
|
|
||||||
--- Transparently fetches from worldedit pos1 for compatibility.
|
--- Transparently fetches from worldedit pos1 for compatibility.
|
||||||
-- Called whenever pos1 is accessed in this API.
|
-- Called whenever pos1 is accessed in this API.
|
||||||
-- @private
|
-- @internal
|
||||||
-- @param player_name string The name of the player to fetch the position for.
|
-- @param player_name string The name of the player to fetch the position for.
|
||||||
-- @returns void
|
-- @returns void
|
||||||
local function compat_worldedit_pos1_get(player_name)
|
local function compat_worldedit_pos1_get(player_name)
|
||||||
|
@ -68,7 +68,7 @@ local function compat_worldedit_pos1_get(player_name)
|
||||||
end
|
end
|
||||||
--- Transparently fetches from worldedit pos2 for compatibility.
|
--- Transparently fetches from worldedit pos2 for compatibility.
|
||||||
-- Called whenever pos2 is accessed in this API.
|
-- Called whenever pos2 is accessed in this API.
|
||||||
-- @private
|
-- @internal
|
||||||
-- @param player_name string The name of the player to fetch the position for.
|
-- @param player_name string The name of the player to fetch the position for.
|
||||||
-- @returns void
|
-- @returns void
|
||||||
local function compat_worldedit_pos2_get(player_name)
|
local function compat_worldedit_pos2_get(player_name)
|
||||||
|
|
|
@ -13,6 +13,17 @@ local function ensure_player(player_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Check every single ObjectRef that is currently loaded to make sure that all rogue marker walls are properly disposed of.
|
||||||
|
-- @internal
|
||||||
|
local function garbage_collect_all()
|
||||||
|
for id, obj in pairs(minetest.object_refs) do
|
||||||
|
if obj.get_luaentity then
|
||||||
|
local luaentity = obj:get_luaentity()
|
||||||
|
weac.entities.pos_marker_wall.check_entity(luaentity)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Deletes the currently displayed marker wall.
|
--- Deletes the currently displayed marker wall.
|
||||||
-- @param event EventArgs<wea_c.pos.set> The event args for the set, push, pop, or clear events on wea_c.pos.
|
-- @param event EventArgs<wea_c.pos.set> The event args for the set, push, pop, or clear events on wea_c.pos.
|
||||||
-- @returns void
|
-- @returns void
|
||||||
|
@ -24,6 +35,8 @@ local function do_delete(event)
|
||||||
end
|
end
|
||||||
|
|
||||||
wall_entity_lists[event.player_name] = nil
|
wall_entity_lists[event.player_name] = nil
|
||||||
|
|
||||||
|
garbage_collect_all()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Updates the marker wall as appropriate.
|
--- Updates the marker wall as appropriate.
|
||||||
|
|
Loading…
Reference in a new issue