From 2e91cbb1f44afba4e534d04a5efc8446538395fa Mon Sep 17 00:00:00 2001 From: IamPyu Date: Sat, 21 Dec 2024 13:32:02 -0600 Subject: [PATCH] Magic Wands system now uses new projectile system --- mods/ENTITIES/pyutest_projectiles/api.lua | 2 +- mods/ITEMS/pyutest_crafts/tools.lua | 9 ++ mods/ITEMS/pyutest_magic/wands.lua | 153 +++++----------------- textures/pyutest-explosions-wand.png | Bin 0 -> 179 bytes 4 files changed, 44 insertions(+), 120 deletions(-) create mode 100644 textures/pyutest-explosions-wand.png diff --git a/mods/ENTITIES/pyutest_projectiles/api.lua b/mods/ENTITIES/pyutest_projectiles/api.lua index 220cb7e..86fb02f 100644 --- a/mods/ENTITIES/pyutest_projectiles/api.lua +++ b/mods/ENTITIES/pyutest_projectiles/api.lua @@ -42,7 +42,7 @@ PyuTest.make_projectile = function (name, properties, options, functions) initial_properties = PyuTest.util.tableconcat({ visual = "cube", visual_size = {x=0.5, y=0.5}, - collisionbox = {-0.2, -0.2, -0.2, 0.2, 0.2, 0.2,}, + collisionbox = {-0.2, -0.2, -0.2, 0.2, 0.2, 0.2}, use_texture_alpha = false, pointable = false, glow = core.LIGHT_MAX, diff --git a/mods/ITEMS/pyutest_crafts/tools.lua b/mods/ITEMS/pyutest_crafts/tools.lua index 4dae9aa..72f5179 100644 --- a/mods/ITEMS/pyutest_crafts/tools.lua +++ b/mods/ITEMS/pyutest_crafts/tools.lua @@ -167,3 +167,12 @@ core.register_craft({ {"pyutest_tools:basalt_stick"}, } }) + +core.register_craft({ + output = "pyutest_magic:explosions_wand", + recipe = { + {"pyutest_blocks:tnt"}, + {"pyutest_tools:basalt_stick"}, + {"pyutest_tools:basalt_stick"}, + } +}) diff --git a/mods/ITEMS/pyutest_magic/wands.lua b/mods/ITEMS/pyutest_magic/wands.lua index d0255f9..fd56a03 100644 --- a/mods/ITEMS/pyutest_magic/wands.lua +++ b/mods/ITEMS/pyutest_magic/wands.lua @@ -1,41 +1,11 @@ PyuTest.make_wand = function (id, desc, texture, mana, properties, fns) - local e_id = id .. "_entity" + local e_id = id .. "_projectile" - core.register_entity(e_id, { - initial_properties = PyuTest.util.tableconcat({ - physical = false, - visual = "cube", - visual_size = {x=0.5, y=0.5}, - collisionbox = {-0.2, -0.2, -0.2, 0.2, 0.2, 0.2,}, - use_texture_alpha = false, - pointable = false, - glow = core.LIGHT_MAX, - }, properties or {}), - - _timer = 0, - _owner = nil, - on_step = function (self, dtime, moveresult) - self._timer = self._timer + dtime - - local vel = self.object:get_velocity() - vel = vector.multiply(vel, 0.98) - self.object:set_velocity(vel) - - if self._timer > 5 then - self.object:remove() - return - end - - if fns.predicate(self) then - core.sound_play("pyutest_special1", { - gain = 1, - pos = self.object:get_pos() - }) - - fns.action(self) - self.object:remove() - end - end + PyuTest.make_projectile(e_id, properties, { + _slowdown = false + }, { + on_hit_node = fns.on_hit_node, + on_hit_object = fns.on_hit_object }) PyuTest.make_item(id, desc, { @@ -48,20 +18,7 @@ PyuTest.make_wand = function (id, desc, texture, mana, properties, fns) return end - local dir = user:get_look_dir() - local pos = user:get_pos() - - pos = vector.offset(pos, 0, 1.3, 0) - pos = vector.add(pos, dir) - - local object = core.add_entity(pos, e_id) - object:set_velocity(vector.multiply(dir, 30)) - object:get_luaentity()._owner = user - - core.sound_play("pyutest_magic_action", { - gain = 1, - pos = pos - }) + PyuTest.shoot_projectile_from_object(e_id, user) return itemstack end @@ -78,15 +35,7 @@ PyuTest.make_wand("pyutest_magic:ice_wand", "Ice Wand", "pyutest-ice-wand.png", "pyutest-ice.png", } }, { - predicate = function (entity) - local pos = entity.object:get_pos() - local node = core.get_node(pos) - - return node.name ~= "air" - end, - action = function (entity) - local pos = entity.object:get_pos() - + on_hit_node = function (entity, pos, node) for e in core.objects_inside_radius(pos, 2) do if e ~= entity._owner then PyuTest.deal_damage(e, 6, PyuTest.DAMAGE_TYPES.freezing()) @@ -121,15 +70,8 @@ PyuTest.make_wand("pyutest_magic:fire_wand", "Fire Wand", "pyutest-fire-wand.png "pyutest-lava.png", } }, { - predicate = function (entity) - local pos = entity.object:get_pos() - local node = core.get_node(pos) - - local walkable = core.registered_nodes[node.name].walkable - return walkable - end, - - action = function (entity) + on_hit_node = function (entity, pos, node) + -- TODO: Fix behaviour PyuTest.dorange(entity.object:get_pos(), 1, function (p) local node = core.get_node(p) local walkable = core.registered_nodes[node.name].walkable @@ -155,50 +97,13 @@ PyuTest.make_wand("pyutest_magic:arcane_wand", "Arcane Wand", "pyutest-arcane-wa "pyutest-crystal-lantern.png", } }, { - predicate = function (entity) - local pos = entity.object:get_pos() - local node = core.get_node(pos) - - local walkable = core.registered_nodes[node.name].walkable - return walkable - end, - - action = function (entity) + on_hit_node = function (entity, pos, node) PyuTest.lightning_strike(entity.object:get_pos(), 3) end }) -PyuTest.make_wand("pyutest_magic:water_wand", "Water Wand", "pyutest-water-wand.png", 15, { - textures = { - "pyutest-water.png", - "pyutest-water.png", - "pyutest-water.png", - "pyutest-water.png", - "pyutest-water.png", - "pyutest-water.png", - } -}, { - predicate = function (entity) - local pos = entity.object:get_pos() - local node = core.get_node(pos) - - local walkable = core.registered_nodes[node.name].walkable - return walkable - end, - - action = function (entity) - PyuTest.dorange(entity.object:get_pos(), 1, function (p) - local node = core.get_node(p) - local walkable = core.registered_nodes[node.name].walkable - if walkable then return end - - core.set_node(p, {name = "pyutest_blocks:water_source"}) - end) - end -}) - -PyuTest.make_wand("pyutest_magic:teleportation_wand", "Teleportation Wand", "pyutest-teleportation-wand.png", -40, { +PyuTest.make_wand("pyutest_magic:teleportation_wand", "Teleportation Wand", +"pyutest-teleportation-wand.png", 40, { textures = { "pyutest-crystal-lantern.png", "pyutest-crystal-lantern.png", @@ -208,16 +113,26 @@ PyuTest.make_wand("pyutest_magic:teleportation_wand", "Teleportation Wand", "pyu "pyutest-crystal-lantern.png", } }, { - predicate = function (entity) - local pos = entity.object:get_pos() - local node = core.get_node(pos) - - local walkable = core.registered_nodes[node.name].walkable - return walkable - end, - - action = function (entity) - - entity._owner:set_pos(entity.object:get_pos() + vector.new(0, 1, 0)) + on_hit_node = function (entity, pos, node) + entity._owner:set_pos(entity.object:get_pos()) + end +}) + +PyuTest.make_wand("pyutest_magic:explosions_wand", "Explosions Wand", +"pyutest-explosions-wand.png", 33, { + textures = { + "pyutest-tnt-top-bottom.png", + "pyutest-tnt-top-bottom.png", + "pyutest-tnt-side.png", + "pyutest-tnt-side.png", + "pyutest-tnt-side.png", + "pyutest-tnt-side.png", + } +}, { + on_hit_node = function(self, pos, node) + PyuTest.create_explosion(pos, 2, false, 10, {}, 4) + end, + on_hit_object = function(self, object) + PyuTest.create_explosion(object:get_pos(), 2, false, 10, {}, 4) end }) diff --git a/textures/pyutest-explosions-wand.png b/textures/pyutest-explosions-wand.png new file mode 100644 index 0000000000000000000000000000000000000000..f02b65981e533c2952b9dc5111cc90cbbf41793e GIT binary patch literal 179 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Rh}-6Ar`%FCvD_Cpuod2e~aFY z1Iin`%uamx;t>#F9oi5f=$3iuiM4onzOqb@!RDUgo{N!Zc&{uzzG zRe|YR8b=TQKG%Qt*Oa9On*}Bc1U65PGigzlV>6p1_gtx2yO-zh2XTW7 e^*5xyvCR4Hb@z1FH!Ywm7(8A5T-G@yGywpUC`N<; literal 0 HcmV?d00001