From 2afadb4ae6b5b3159a5ba4130e93dc910cf73b80 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 19 Apr 2026 21:06:29 +0300 Subject: [PATCH] test removing client-side logic in headless (base pack scripts/components) --- res/content/base/scripts/components/drop.lua | 9 ++---- .../base/scripts/components/falling_block.lua | 4 +-- .../scripts/components/player_animator.lua | 2 -- res/content/base/scripts/grass_block.lua | 32 +++++++++++-------- res/content/base/scripts/world.lua | 2 +- res/scripts/components/player.lua | 2 +- 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/res/content/base/scripts/components/drop.lua b/res/content/base/scripts/components/drop.lua index c3d629828..f8ca6c9c7 100644 --- a/res/content/base/scripts/components/drop.lua +++ b/res/content/base/scripts/components/drop.lua @@ -26,7 +26,6 @@ function on_save() end if not VC_HEADLESS then - local SCALE = 0.3 local scale = {1, 1, 1} local rotation = mat4.rotate({ math.random(), math.random(), math.random() @@ -35,8 +34,8 @@ if not VC_HEADLESS then do local matrix = mat4.idt() rig:set_model(0, item.model_name(dropitem.id)) - local bodysize = math.min(scale[1], scale[2], scale[3]) * SCALE - body:set_size({scale[1] * SCALE, bodysize, scale[3] * SCALE}) + local bodysize = math.min(scale[1], scale[2], scale[3]) + body:set_size({scale[1], bodysize, scale[3]}) mat4.mul(matrix, rotation, matrix) mat4.scale(matrix, scale, matrix) rig:set_matrix(0, matrix) @@ -103,9 +102,7 @@ function on_sensor_enter(index, oid) if timer < 0.0 and index == 0 then entity:despawn() inventory.add(player.get_inventory(pid), dropitem.id, dropitem.count, dropitem.data) - if not VC_HEADLESS then - audio.play_sound_2d("events/pickup", 0.5, 0.8 + math.random() * 0.4, "regular") - end + audio.play_sound_2d("events/pickup", 0.5, 0.8 + math.random() * 0.4, "regular") end if index == 1 then target = oid diff --git a/res/content/base/scripts/components/falling_block.lua b/res/content/base/scripts/components/falling_block.lua index b6bbe4656..9bb02e25a 100644 --- a/res/content/base/scripts/components/falling_block.lua +++ b/res/content/base/scripts/components/falling_block.lua @@ -1,6 +1,5 @@ local tsf = entity.transform local body = entity.rigidbody -local rig = entity.skeleton local blockid = ARGS.block local blockstates = ARGS.states or 0 @@ -12,7 +11,8 @@ else SAVED_DATA.states = blockstates end -do -- setup visuals +if not VC_HEADLESS then-- setup visuals + local rig = entity.skeleton local id = block.index(blockid) local rotation = block.decompose_state(blockstates)[1] local textures = block.get_textures(id) diff --git a/res/content/base/scripts/components/player_animator.lua b/res/content/base/scripts/components/player_animator.lua index f82927ccd..6bd118906 100644 --- a/res/content/base/scripts/components/player_animator.lua +++ b/res/content/base/scripts/components/player_animator.lua @@ -1,5 +1,3 @@ -local tsf = entity.transform -local body = entity.rigidbody local rig = entity.skeleton local mob = entity:require_component("core:mob") diff --git a/res/content/base/scripts/grass_block.lua b/res/content/base/scripts/grass_block.lua index e58597cc4..fb7482c20 100644 --- a/res/content/base/scripts/grass_block.lua +++ b/res/content/base/scripts/grass_block.lua @@ -1,20 +1,26 @@ +local offsets = {} +for lx=-1,1 do + for ly=-1,1 do + for lz=-1,1 do + offsets[(lx * 3 + ly) * 3 + lz] = {lx, ly, lz} + end + end +end + function on_random_update(x, y, z) local dirtid = block.index('base:dirt'); if block.is_solid_at(x, y+1, z) then block.set(x, y, z, dirtid, 0) - else - local grassblockid = block.index('base:grass_block') - for lx=-1,1 do - for ly=-1,1 do - for lz=-1,1 do - if block.get(x + lx, y + ly, z + lz) == dirtid then - if not block.is_solid_at(x + lx, y + ly + 1, z + lz) then - block.set(x + lx, y + ly, z + lz, grassblockid, 0) - return - end - end - end - end + return + end + local grassblockid = block.index('base:grass_block') + for _, offset in ipairs(offsets) do + local nx, ny, nz = x + offset[1], y + offset[2], z + offset[3] + + if block.get(nx, ny, nz) == dirtid and + not block.is_solid_at(nx, ny + 1, nz) then + block.set(nx, ny, nz, grassblockid, 0) + return end end end diff --git a/res/content/base/scripts/world.lua b/res/content/base/scripts/world.lua index 7f468c291..9698eef54 100644 --- a/res/content/base/scripts/world.lua +++ b/res/content/base/scripts/world.lua @@ -1,5 +1,5 @@ function on_block_broken(id, x, y, z, playerid) - if gfx then + if not VC_HEADLESS then local size = {block.get_size(id)} gfx.particles.emit({ x + size[1] * 0.5, diff --git a/res/scripts/components/player.lua b/res/scripts/components/player.lua index 49a03377f..96b92fe81 100644 --- a/res/scripts/components/player.lua +++ b/res/scripts/components/player.lua @@ -80,7 +80,7 @@ function on_physics_update(delta) local front = mat4.mul(rot, {0, 0, -1}) local pos = tsf:get_pos() - if hud and pid == hud.get_player() then + if not VC_HEADLESS and pid == hud.get_player() then process_player_inputs(pid, rot, delta) end mob.look_at(vec3.add(pos, front))