From be0f5317d174ab347c2604dcde57afb7ac261e04 Mon Sep 17 00:00:00 2001 From: FatalErr42O <58855799+FatalError42O@users.noreply.github.com> Date: Sun, 17 Mar 2024 21:59:03 -0700 Subject: [PATCH] added config setting for vertical rotation factor, and fixed mag wear initialization --- ammo_api.lua | 13 +++++++++---- classes/Gun.lua | 2 +- init.lua | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ammo_api.lua b/ammo_api.lua index 2758f63..7b698a9 100644 --- a/ammo_api.lua +++ b/ammo_api.lua @@ -25,13 +25,18 @@ end function Guns4d.ammo.initialize_mag_data(itemstack, meta) meta = meta or itemstack:get_meta() meta:set_string("guns4d_loaded_bullets", minetest.serialize({})) - if meta:get_int("guns4d_spawn_with_ammo") > 0 then - bullets = { - [def.accepted_bullets[1]]=meta:get_int("guns4d_spawn_with_ammo") + local loaded + local spawn = meta:get_int("guns4d_spawn_with_ammo") + if (spawn > 0) or Guns4d.config.interpret_initial_wear_as_ammo then + local def = Guns4d.ammo.registered_magazines[itemstack:get_name()] + loaded = { + [def.accepted_bullets[1]]=(spawn > 0 and spawn) or math.floor(def.capacity*(1-(itemstack:get_wear()/65535))) } meta:set_int("guns4d_spawn_with_ammo", 0) + meta:set_string("guns4d_loaded_bullets", minetest.serialize(loaded)) + itemstack:set_wear(0) else - bullets = minetest.deserialize(meta:get_string("guns4d_loaded_bullets")) + loaded = minetest.deserialize(meta:get_string("guns4d_loaded_bullets")) end Guns4d.ammo.update_mag(nil, itemstack, meta) return itemstack diff --git a/classes/Gun.lua b/classes/Gun.lua index b3bfa65..441284b 100644 --- a/classes/Gun.lua +++ b/classes/Gun.lua @@ -296,7 +296,7 @@ function gun_default:update(dt) local look_rotation = handler.look_rotation --remember that this is in counterclock-wise rotation. For 4dguns we use clockwise so it makes a bit more sense for recoil. So it needs to be inverted. local total_rot = self.total_offset_rotation local player_rot = self.player_rotation - local constant = 5 --make this a config setting + local constant = Guns4d.config.vertical_rotation_factor --player look rotation. I'm going to keep it real, I don't remember what this math does. Player handler just stores the player's rotation from MT in degrees, which is for some reason inverted player_rot.y = -handler.look_rotation.y diff --git a/init.lua b/init.lua index cd825d1..07aff30 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,8 @@ Guns4d.config = { control_held_toggle_threshold = 0, empty_symbol = "0e", infinite_ammo_priv = "guns4d_infinite_ammo", - interpret_initial_wear_as_ammo = false + interpret_initial_wear_as_ammo = false, + vertical_rotation_factor = 10 --`["official_content.replace_ads_with_bloom"] = false, --`["official_content.uses_magazines"] = true }