Skip to content

Commit

Permalink
Replace fake player code with fakelib (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
OgelGames authored May 30, 2024
1 parent 6691607 commit 3cb912d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/luacheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ read_globals = {
"default",
"tnt",
"mcl_sounds",
"mcl_explosions"
"mcl_explosions",
"fakelib",
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
147 changes: 0 additions & 147 deletions class_fakeplayer.lua

This file was deleted.

40 changes: 10 additions & 30 deletions init.lua
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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,
})

Expand All @@ -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
Expand Down Expand Up @@ -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})
Expand Down
1 change: 1 addition & 0 deletions mod.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name = torch_bomb
description = Place torches throughout your entire surroundings with a torch bomb
depends = fakelib
optional_depends = mcl_core, mcl_sounds, mcl_explosions, mcl_tnt, default, tnt, creative, farming
min_minetest_version = 5.3.0

0 comments on commit 3cb912d

Please sign in to comment.