Replace fake player code with fakelib
(#10)
Some checks failed
luacheck / luacheck (push) Has been cancelled
Some checks failed
luacheck / luacheck (push) Has been cancelled
This commit is contained in:
parent
669160743f
commit
3cb912d5c7
2
.github/workflows/luacheck.yml
vendored
2
.github/workflows/luacheck.yml
vendored
@ -5,6 +5,6 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
uses: actions/checkout@main
|
||||
- name: Luacheck
|
||||
uses: lunarmodules/luacheck@master
|
@ -8,5 +8,6 @@ read_globals = {
|
||||
"default",
|
||||
"tnt",
|
||||
"mcl_sounds",
|
||||
"mcl_explosions"
|
||||
"mcl_explosions",
|
||||
"fakelib",
|
||||
}
|
@ -14,4 +14,6 @@ If you want to scatter torches from the center of a cavern to reach floor and ce
|
||||
|
||||
For precision torch placement a set of torch crossbows are included: wooden, bronze, and steel.
|
||||
|
||||
TNT is an optional dependency for this mod, but torch bombs don't have a crafting recipe (and don't produce a damaging blast) without the tnt mod enabled.
|
||||
TNT is an optional dependency for this mod, but torch bombs don't have a crafting recipe (and don't produce a damaging blast) without the `tnt` mod enabled.
|
||||
|
||||
The `fakelib` mod is a required dependency for simulating the placement of torches.
|
||||
|
@ -1,147 +0,0 @@
|
||||
-- The purpose of this class is to have something that can be passed into callbacks that
|
||||
-- demand a "Player" object as a parameter and hopefully prevent the mods that have
|
||||
-- registered with those callbacks from crashing on a nil dereference or bad function
|
||||
-- call. This is not supposed to be a remotely functional thing, it's just supposed
|
||||
-- to provide dummy methods and return values of the correct data type for anything that
|
||||
-- might ignore the false "is_player()" return and go ahead and try to use this thing
|
||||
-- anyway.
|
||||
|
||||
-- I'm trying to patch holes in bad mod programming, essentially. If a mod is so badly
|
||||
-- programmed that it crashes anyway there's not a lot else I can do on my end of things.
|
||||
|
||||
local FakePlayer = {}
|
||||
FakePlayer.__index = FakePlayer
|
||||
|
||||
local function return_value(x)
|
||||
return (function() return x end)
|
||||
end
|
||||
|
||||
local function return_nil()
|
||||
return nil
|
||||
end
|
||||
|
||||
local function return_empty_string()
|
||||
return ""
|
||||
end
|
||||
|
||||
local function return_zero()
|
||||
return 0
|
||||
end
|
||||
|
||||
local function return_empty_table()
|
||||
return {}
|
||||
end
|
||||
|
||||
function FakePlayer.update(self, pos, player_name)
|
||||
self.is_fake_player = player_name
|
||||
self.get_pos = return_value(pos)
|
||||
end
|
||||
|
||||
function FakePlayer.create(pos, player_name)
|
||||
local self = {}
|
||||
setmetatable(self, FakePlayer)
|
||||
|
||||
self.is_fake_player = player_name
|
||||
|
||||
-- ObjectRef
|
||||
self.get_pos = return_value(pos)
|
||||
self.set_pos = return_nil
|
||||
self.move_to = return_nil
|
||||
self.punch = return_nil
|
||||
self.right_click = return_nil
|
||||
self.get_hp = return_value(10)
|
||||
self.set_hp = return_nil
|
||||
self.get_inventory = return_nil -- returns an `InvRef`
|
||||
self.get_wield_list = return_empty_string
|
||||
self.get_wield_index = return_value(1)
|
||||
self.get_wielded_item = return_value(ItemStack(nil))
|
||||
self.set_wielded_item = return_value(false)
|
||||
self.set_armor_groups = return_nil
|
||||
self.get_armor_groups = return_empty_table
|
||||
self.set_animation = return_nil
|
||||
self.get_animation = return_nil -- a set of values, maybe important?
|
||||
self.set_attach = return_nil
|
||||
self.get_attach = return_nil
|
||||
self.set_detach = return_nil
|
||||
self.set_bone_position = return_nil
|
||||
self.get_bone_position = return_nil
|
||||
self.set_properties = return_nil
|
||||
self.get_properties = return_empty_table
|
||||
|
||||
self.is_player = return_value(false)
|
||||
|
||||
self.get_nametag_attributes = return_empty_table
|
||||
self.set_nametag_attributes = return_nil
|
||||
|
||||
--LuaEntitySAO
|
||||
self.set_velocity = return_nil
|
||||
self.get_velocity = return_value({x=0,y=0,z=0})
|
||||
self.set_acceleration = return_nil
|
||||
self.get_acceleration = return_value({x=0,y=0,z=0})
|
||||
self.set_yaw = return_nil
|
||||
self.get_yaw = return_zero
|
||||
self.set_texture_mod = return_nil
|
||||
self.get_texture_mod = return_nil -- maybe important?
|
||||
self.set_sprite = return_nil
|
||||
--self.get_entity_name` (**Deprecated**: Will be removed in a future version)
|
||||
self.get_luaentity = return_nil
|
||||
|
||||
-- Player object
|
||||
|
||||
self.get_player_name = return_empty_string
|
||||
self.get_player_velocity = return_nil
|
||||
self.get_look_dir = return_value({x=0,y=1,z=0})
|
||||
self.get_look_horizontal = return_zero
|
||||
self.set_look_horizontal = return_nil
|
||||
self.get_look_vertical = return_zero
|
||||
self.set_look_vertical = return_nil
|
||||
|
||||
--self.get_look_pitch`: pitch in radians - Deprecated as broken. Use `get_look_vertical`
|
||||
--self.get_look_yaw`: yaw in radians - Deprecated as broken. Use `get_look_horizontal`
|
||||
--self.set_look_pitch(radians)`: sets look pitch - Deprecated. Use `set_look_vertical`.
|
||||
--self.set_look_yaw(radians)`: sets look yaw - Deprecated. Use `set_look_horizontal`.
|
||||
self.get_breath = return_value(10)
|
||||
self.set_breath = return_nil
|
||||
self.get_attribute = return_nil
|
||||
self.set_attribute = return_nil
|
||||
|
||||
self.set_inventory_formspec = return_nil
|
||||
self.get_inventory_formspec = return_empty_string
|
||||
self.get_player_control = return_value({jump=false, right=false, left=false, LMB=false, RMB=false, sneak=false, aux1=false, down=false, up=false} )
|
||||
self.get_player_control_bits = return_zero
|
||||
|
||||
self.set_physics_override = return_nil
|
||||
self.get_physics_override = return_value({speed = 1, jump = 1, gravity = 1, sneak = true, sneak_glitch = false, new_move = true,})
|
||||
|
||||
|
||||
self.hud_add = return_nil
|
||||
self.hud_remove = return_nil
|
||||
self.hud_change = return_nil
|
||||
self.hud_get = return_nil -- possibly important return value?
|
||||
self.hud_set_flags = return_nil
|
||||
self.hud_get_flags = return_value({ hotbar=true, healthbar=true, crosshair=true, wielditem=true, breathbar=true, minimap=true })
|
||||
self.hud_set_hotbar_itemcount = return_nil
|
||||
self.hud_get_hotbar_itemcount = return_zero
|
||||
self.hud_set_hotbar_image = return_nil
|
||||
self.hud_get_hotbar_image = return_empty_string
|
||||
self.hud_set_hotbar_selected_image = return_nil
|
||||
self.hud_get_hotbar_selected_image = return_empty_string
|
||||
self.set_sky = return_nil
|
||||
self.get_sky = return_empty_table -- may need members on this table
|
||||
|
||||
self.set_clouds = return_nil
|
||||
self.get_clouds = return_value({density = 0, color = "#fff0f0e5", ambient = "#000000", height = 120, thickness = 16, speed = {x=0, y=-2}})
|
||||
|
||||
self.override_day_night_ratio = return_nil
|
||||
self.get_day_night_ratio = return_nil
|
||||
|
||||
self.set_local_animation = return_nil
|
||||
self.get_local_animation = return_empty_table
|
||||
|
||||
self.set_eye_offset = return_nil
|
||||
self.get_eye_offset = return_value({x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return FakePlayer
|
40
init.lua
40
init.lua
@ -1,12 +1,7 @@
|
||||
local modname = minetest.get_current_modname()
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
local tnt_modpath = minetest.get_modpath("tnt")
|
||||
local mcl_tnt_modpath = minetest.get_modpath("mcl_tnt")
|
||||
local mcl_explosions_modpath = minetest.get_modpath("mcl_explosions")
|
||||
local S = minetest.get_translator(modname)
|
||||
|
||||
local FakePlayer = dofile(modpath .. "/" .. "class_fakeplayer.lua")
|
||||
local fakeplayer = FakePlayer.create({x=0,y=0,z=0}, "torch_bomb")
|
||||
local S = minetest.get_translator("torch_bomb")
|
||||
|
||||
-- Default to enabled when in singleplayer
|
||||
local enable_tnt = minetest.settings:get_bool("enable_tnt")
|
||||
@ -350,7 +345,7 @@ local function embed_torch(target, placer, pos)
|
||||
minetest.after(math.random()*0.1, play_bolt_hit, pos)
|
||||
end
|
||||
|
||||
local function kerblam(pos, placer, dirs, min_range)
|
||||
local function kerblam(pos, player, dirs, min_range)
|
||||
pos = vector.round(pos)
|
||||
local targets = {}
|
||||
for _, pos2 in ipairs(dirs) do
|
||||
@ -362,17 +357,11 @@ local function kerblam(pos, placer, dirs, min_range)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not placer then
|
||||
placer = fakeplayer
|
||||
fakeplayer:update(pos, "torch_bomb")
|
||||
end
|
||||
|
||||
minetest.log("action", placer:get_player_name() .. " detonated a torch bomb at " ..
|
||||
minetest.log("action", player:get_player_name() .. " detonated a torch bomb at " ..
|
||||
minetest.pos_to_string(pos) .. " and placed " .. #targets .. " torches.")
|
||||
|
||||
for _, target in ipairs(targets) do
|
||||
embed_torch(target, placer, pos)
|
||||
embed_torch(target, player, pos)
|
||||
end
|
||||
end
|
||||
|
||||
@ -490,19 +479,16 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
end,
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
local ignitor_name = minetest.get_meta(pos):get("torch_bomb_ignitor")
|
||||
local puncher
|
||||
if ignitor_name then
|
||||
puncher = minetest.get_player_by_name(ignitor_name)
|
||||
end
|
||||
local player_name = minetest.get_meta(pos):get("torch_bomb_ignitor")
|
||||
local player = fakelib.create_player(player_name)
|
||||
minetest.set_node(pos, {name="air"})
|
||||
if tnt_modpath then
|
||||
tnt.boom(pos, {radius=blast_radius, damage_radius=blast_radius+3})
|
||||
end
|
||||
if mcl_explosions_modpath then
|
||||
mcl_explosions.explode(pos, blast_radius, mcl_expl_info, puncher)
|
||||
mcl_explosions.explode(pos, blast_radius, mcl_expl_info, player)
|
||||
end
|
||||
kerblam(pos, puncher, dirs, min_range)
|
||||
kerblam(pos, player, dirs, min_range)
|
||||
end,
|
||||
})
|
||||
|
||||
@ -515,10 +501,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
|
||||
local function entity_detonate(player_name, target)
|
||||
--minetest.chat_send_all("entity detonate " .. (player_name or "") .. " " .. minetest.pos_to_string(target))
|
||||
local player
|
||||
if player_name then
|
||||
player = minetest.get_player_by_name(player_name)
|
||||
end
|
||||
local player = fakelib.create_player(player_name)
|
||||
if tnt_modpath then
|
||||
tnt.boom(target, {radius=blast_radius, damage_radius=blast_radius+3})
|
||||
end
|
||||
@ -741,10 +724,7 @@ if enable_grenade then
|
||||
lastpos = vector.round(lastpos)
|
||||
local luaentity = object:get_luaentity()
|
||||
local player_name = luaentity.player_name
|
||||
local player
|
||||
if player_name then
|
||||
player = minetest.get_player_by_name(player_name)
|
||||
end
|
||||
local player = fakelib.create_player(player_name)
|
||||
object:remove()
|
||||
if tnt_modpath then
|
||||
tnt.boom(lastpos, {radius=1, damage_radius=2})
|
||||
|
Loading…
x
Reference in New Issue
Block a user