Fix physics projectile lob strength

This commit is contained in:
IQuant 2024-06-20 15:53:01 +03:00
parent e5e7bbb04d
commit 5013d223fb
3 changed files with 31 additions and 17 deletions

View file

@ -2,6 +2,8 @@ local inventory_helper = dofile_once("mods/quant.ew/files/src/inventory_helper.l
local ctx = dofile_once("mods/quant.ew/files/src/ctx.lua")
local util = dofile_once("mods/quant.ew/files/src/util.lua")
dofile_once("data/scripts/lib/coroutines.lua")
local item_sync = {}
function item_sync.ensure_notify_component(ent)
@ -65,19 +67,27 @@ function item_sync.host_localize_item(gid, peer_id)
end
function item_sync.make_item_global(item)
local g_id = EntityGetFirstComponentIncludingDisabled(item, "VariableStorageComponent", "ew_global_item_id")
local id = ComponentGetValue2(g_id, "value_int")
if g_id == nil then
id = allocate_global_id()
EntityAddComponent2(item, "VariableStorageComponent", {
_tags = "enabled_in_world,enabled_in_hand,enabled_in_inventory,ew_global_item_id",
value_int = id,
})
end
local item_data = inventory_helper.serialize_single_item(item)
item_data.g_id = id
ctx.item_prevent_localize[id] = false
ctx.lib.net.send_make_global(item_data)
async(function()
wait(1) -- Wait 1 frame so that game sets proper velocity.
local g_id = EntityGetFirstComponentIncludingDisabled(item, "VariableStorageComponent", "ew_global_item_id")
local id = ComponentGetValue2(g_id, "value_int")
if g_id == nil then
id = allocate_global_id()
EntityAddComponent2(item, "VariableStorageComponent", {
_tags = "enabled_in_world,enabled_in_hand,enabled_in_inventory,ew_global_item_id",
value_int = id,
})
end
local vel = EntityGetFirstComponentIncludingDisabled(item, "VelocityComponent")
if vel then
local vx, vy = ComponentGetValue2(vel, "mVelocity")
GamePrint("v "..vx.." "..vy)
end
local item_data = inventory_helper.serialize_single_item(item)
item_data.g_id = id
ctx.item_prevent_localize[id] = false
ctx.lib.net.send_make_global(item_data)
end)
end
local function get_global_ent(key)
@ -124,7 +134,10 @@ function item_sync.on_world_update_client()
end
local thrown_item = get_global_ent("ew_thrown")
if thrown_item ~= nil and not EntityHasTag(thrown_item, "ew_client_item") then
ctx.lib.net.send_item_upload(inventory_helper.serialize_single_item(thrown_item))
async(function ()
wait(1) -- Wait 1 frame so that game sets proper velocity.
ctx.lib.net.send_item_upload(inventory_helper.serialize_single_item(thrown_item))
end)
EntityKill(thrown_item)
end

View file

@ -124,10 +124,7 @@ function net_handling.mod.fire(peer_id, fire_data)
util.set_ent_firing_blocked(entity, false)
-- Add player_unit tag to fix physics projectile lob strength
EntityAddTag(entity, "player_unit")
np.UseItem(entity, mActiveItem, true, true, true, x, y, target_x, target_y)
EntityRemoveTag(entity, "player_unit")
util.set_ent_firing_blocked(entity, true)

View file

@ -20,6 +20,8 @@ local perk_fns = dofile_once("mods/quant.ew/files/src/perk_fns.lua")
local version = dofile_once("mods/quant.ew/files/version.lua") or "unknown (dev build)"
print("Noita EW version: "..version)
dofile_once("data/scripts/lib/coroutines.lua")
ModLuaFileAppend("data/scripts/gun/gun.lua", "mods/quant.ew/files/append/gun.lua")
ModLuaFileAppend("data/scripts/gun/gun_actions.lua", "mods/quant.ew/files/append/action_fix.lua")
@ -224,6 +226,8 @@ local function on_world_pre_update_inner()
end
ctx.hook.on_world_update()
end
wake_up_waiting_threads(1)
end
function OnWorldPreUpdate() -- This is called every time the game is about to start updating the world