make some things nicer

This commit is contained in:
bgkillas 2024-11-14 08:46:31 -05:00
parent 85c2b3cfc1
commit 2adc80ed63
4 changed files with 21 additions and 19 deletions

View file

@ -491,9 +491,7 @@ function player_fns.spawn_player_for(peer_id, x, y, existing_playerdata)
end
print("Spawning player for "..peer_id)
local new = EntityLoad("mods/quant.ew/files/system/player/tmp/" .. peer_id .. "_base.xml", x, y)
if new ~= nil then
ewext.make_ephemerial(new)
end
util.make_ephemerial(new)
local inv_full = EntityCreateNew("inventory_full")
EntityAddChild(new, inv_full)
LoadGameEffectEntityTo(new, "mods/quant.ew/files/system/spectate/no_tinker.xml")
@ -542,9 +540,7 @@ function player_fns.spawn_player_for(peer_id, x, y, existing_playerdata)
end
function player_fns.replace_player_entity(new_entity, player_data)
if new_entity ~= nil then
ewext.make_ephemerial(new_entity)
end
util.make_ephemerial(new_entity)
if new_entity ~= nil then
local old_entity = player_data.entity
player_data.entity = new_entity

View file

@ -181,6 +181,12 @@ util.load_ents_tags = util.cached_fn(function(path)
return tags
end)
function util.make_ephemerial(ent)
if ent ~= nil and EntityGetIsAlive(ent) then
ewext.make_ephemerial(ent)
end
end
-- Load an entity that doesn't get saved.
function util.load_ephemerial(path, x, y)
--local entity = EntityCreateNew()
@ -188,9 +194,7 @@ function util.load_ephemerial(path, x, y)
--EntitySetTransform(entity, x, y)
local ent_2 = EntityLoad(path, x, y)
--EntityAddChild(entity, ent_2)
if ent_2 ~= nil then
ewext.make_ephemerial(ent_2)
end
util.make_ephemerial(ent_2)
return ent_2
end

View file

@ -167,7 +167,11 @@ local function get_sync_entities(return_all)
table_extend(entities, EntityGetWithTag("perk_fungus_tiny"))
table_extend(entities, EntityGetWithTag("helpless_animal"))
table_extend_filtered(entities, EntityGetWithTag("prop_physics"), function (ent)
return constants.phys_sync_allowed[EntityGetFilename(ent)]
local f = EntityGetFilename(ent)
if f ~= nil then
return constants.phys_sync_allowed[f]
end
return true
end)
local entities2 = {}
@ -400,8 +404,8 @@ function enemy_sync.client_cleanup()
--print("Despawning unreplicated "..enemy_id.." "..filename)
kill(enemy_id)
elseif not spawned_by_us[enemy_id] then
local filename = EntityGetFilename(enemy_id)
print("Despawning persisted "..enemy_id.." "..filename)
--local filename = EntityGetFilename(enemy_id)
print("Despawning persisted "..enemy_id)--.." "..filename)
kill(enemy_id)
end
end
@ -482,7 +486,7 @@ local function sync_enemy(enemy_info_raw, force_no_cull)
local animation = enemy_info_raw[8]
local has_died = filename == nil
local frame = GameGetFrameNum()
local frame_now = GameGetFrameNum()
--[[if confirmed_kills[remote_enemy_id] then
goto continue
@ -493,7 +497,7 @@ local function sync_enemy(enemy_info_raw, force_no_cull)
end
if ctx.entity_by_remote_id[remote_enemy_id] == nil then
if filename == nil then
if filename == nil or filename == "" or not ModDoesFileExist(filename) then
goto continue
end
times_spawned_last_minute[remote_enemy_id] = (times_spawned_last_minute[remote_enemy_id] or 0) + 1
@ -529,7 +533,7 @@ local function sync_enemy(enemy_info_raw, force_no_cull)
EntityRemoveComponent(enemy_id, ai_component)
end
end
ctx.entity_by_remote_id[remote_enemy_id] = {id = enemy_id, frame = frame}
ctx.entity_by_remote_id[remote_enemy_id] = {id = enemy_id, frame = frame_now}
for _, phys_component in ipairs(EntityGetComponent(enemy_id, "PhysicsBody2Component") or {}) do
if phys_component ~= nil and phys_component ~= 0 then
@ -555,7 +559,7 @@ local function sync_enemy(enemy_info_raw, force_no_cull)
end
local enemy_data_new = ctx.entity_by_remote_id[remote_enemy_id]
enemy_data_new.frame = frame
enemy_data_new.frame = frame_now
local enemy_id = enemy_data_new.id
for i, phys_component in ipairs(EntityGetComponent(enemy_id, "PhysicsBodyComponent") or {}) do

View file

@ -22,9 +22,7 @@ local function oh_another_world_state(entity)
print("Another world state: "..entity)
GamePrint("Another World State Entity detected")
GamePrint("Do a 'mods > restart with enabled mods' to avoid a crash")
if entity ~= nil then
ewext.make_ephemerial(entity)
end
util.make_ephemerial(entity)
end
function module.on_local_player_spawn()