From c8a5f27f285cca2f467a515286fcf29d4fe910a0 Mon Sep 17 00:00:00 2001 From: IamPyu Date: Sat, 7 Dec 2024 17:33:55 -0600 Subject: [PATCH] Stop using pig model make it a flat 2d entity, and more changes to entity system (It'll never be done at this rate) --- mods/CORE/pyutest/util.lua | 2 +- mods/ENTITIES/pyutest_entities/api.lua | 234 +++++++++++------------- mods/ENTITIES/pyutest_entities/init.lua | 36 +++- mods/ENTITIES/pyutest_mobs/basic.lua | 9 +- textures/pyutest-pig-back.png | Bin 0 -> 258 bytes textures/pyutest-pig.png | Bin 668 -> 257 bytes 6 files changed, 144 insertions(+), 137 deletions(-) create mode 100644 textures/pyutest-pig-back.png diff --git a/mods/CORE/pyutest/util.lua b/mods/CORE/pyutest/util.lua index c355edd..726d402 100644 --- a/mods/CORE/pyutest/util.lua +++ b/mods/CORE/pyutest/util.lua @@ -115,7 +115,7 @@ PyuTest.create_explosion = function(pos, range, rm_pos, dmg, damage_whitelist, m end end) - for _, v in pairs(core.get_objects_inside_radius(pos, range)) do + for v in core.objects_inside_radius(pos, range) do local function damage() if v:is_valid() then PyuTest.deal_damage(v, dmg, PyuTest.DAMAGE_TYPES.explosion(range)) diff --git a/mods/ENTITIES/pyutest_entities/api.lua b/mods/ENTITIES/pyutest_entities/api.lua index 7540c95..6048168 100644 --- a/mods/ENTITIES/pyutest_entities/api.lua +++ b/mods/ENTITIES/pyutest_entities/api.lua @@ -3,7 +3,7 @@ PATH_FIND_ALGORITHM = "Dijkstra" PyuTest.ENTITY_BLOOD_AMOUNT = 6 PyuTest.HUMAN_LIKE_CBOX = { -0.25, -1, -0.25, 0.25, 1, 0.25 } -PyuTest.BLOCK_SIZED_ANIMAL_CBOX = { -0.25, -0.25, 0, 0.25, 0.25, 0.25 } +PyuTest.SMALL_ANIMAL_CBOX = {-0.25, -0.5, -0.25, 0.25, 0.15, 0.25} PyuTest.get_nearest_entity = function(entity, pos, range, only_player, dont_ignore_allies) local closet_distance = math.huge @@ -47,55 +47,6 @@ PyuTest.get_nearest_entity = function(entity, pos, range, only_player, dont_igno return nearest end -PyuTest.register_entity_spawn = function(name, entity, def) - if def == nil then - error("Table expected for options!") - end - - core.register_node(name, { - description = "Entity Spawner", - groups = { - not_in_creative_inventory = 1, - }, - drawtype = "airlike", - walkable = false, - pointable = false - }) - - core.register_decoration({ - sidelen = 80, - decoration = name, - deco_type = "simple", - place_on = def.place_on, - spawn_by = def.spawn_by, - num_spawn_by = def.num_spawn_by, - fill_ratio = def.fill_ratio or 0.0008, - y_max = def.y_max or 31000, - y_min = def.y_min or -31000, - biomes = {} - }) - - core.register_lbm({ - name = name .. "_spawn", - run_at_every_load = true, - nodenames = { name }, - action = function(pos) - core.remove_node(pos) - - local min = def.min or 1 - local max = def.max or 1 - - if max == 1 then - core.add_entity(pos, entity) - else - for _ = min, math.random(min, max) do - core.add_entity(pos, entity) - end - end - end - }) -end - local class = {} function class:do_physics() @@ -154,18 +105,126 @@ function class:path_find_nearest_entity(follow_only_player) self:path_find_entity(PyuTest.get_nearest_entity(obj, pos, cfg.view_range, follow_only_player, false)) end +function class:on_punch() + local pos = self.object:get_pos() + core.sound_play({ + name = self.options.sounds.hurt, + pos = pos + }) + + core.add_particlespawner({ + amount = 8, + time = 0.4, + minexptime = 0.4, + maxexptime = 0.8, + minsize = 1.5, + maxsize = 1.62, + vertical = false, + glow = core.LIGHT_MAX, + + collisiondetection = false, + texture = "pyutest-blood.png", + + minpos = pos, + maxpos = pos, + minvel = vector.new(-1, -1, 1), + maxvel = vector.new(1, 1, 1), + }) +end + +function class:on_death() + local pos = self.object:get_pos() + + for _, v in pairs(self.options.drops) do + PyuTest.drop_item(pos, v) + end +end + +function class:on_step(dtime, moveresult) + self.dtime = dtime + self.moveresult = moveresult + + local obj = self.object + local cfg = self.options + local p = obj:get_properties() + + + local hp = obj:get_hp() + if self.options.health_regen and not (hp >= p.hp_max) then + obj:set_hp(hp + 0.5) + end + + if obj:get_hp() > p.hp_max then + obj:set_hp(p.hp_max) + end + + p.infotext = string.format("Mob Health: %d/%d", obj:get_hp(), p.hp_max) + obj:set_properties(p) + + self:do_physics() + + if not self.state.action_timer then + core.after(1, function () + self.state.action_timer = true + + core.after(1, function () + self.action_timer = false + end) + end) + end + + + -- follow_player + if self.options.follow_player then + self:path_find_nearest_entity(false) + end + + -- follow_items + for o in core.objects_inside_radius(obj:get_pos(), cfg.view_range) do + if o ~= obj then + for _, v in pairs(self.options.follow_items) do + local i = o:get_wielded_item() + + if i:get_name() == v then + self:path_find_entity(o) + end + end + end + end + + -- attack_entities + if self.state.action_timer then + for o in core.objects_inside_radius(obj:get_pos(), cfg.hit_range) do + if o ~= obj then + for _, v in pairs(cfg.attack_entities) do + local lua_entity = o:get_luaentity() + + if (v == "player" and o:is_player()) or (lua_entity and v == lua_entity.name) then + PyuTest.deal_damage(o, cfg.hit_damage * dtime, { + type = "punch", + object = obj + }) + end + end + end + end + end +end + PyuTest.make_mob = function(name, properties, options) local default_options = { max_jump = 1, max_drop = 8, speed = 3, hit_range = 3, + hit_damage = 3, view_range = 10, gravity = true, gravity_multiplier = 1, health_regen = true, follow_player = false, follow_items = {}, + attack_entities = {}, sounds = { hurt = "pyutest-entity-hurt" @@ -199,6 +258,7 @@ PyuTest.make_mob = function(name, properties, options) }), options = cfg, state = { + action_timer = false, target = { object = nil, position = nil, @@ -206,79 +266,5 @@ PyuTest.make_mob = function(name, properties, options) pathindex = nil } }, - - on_step = function(self, dtime, moveresult) - self.dtime = dtime - self.moveresult = moveresult - - local obj = self.object - local cfg = self.options - local p = obj:get_properties() - - - local hp = obj:get_hp() - if self.options.health_regen and not (hp >= p.hp_max) then - obj:set_hp(hp + 0.5) - end - - if obj:get_hp() > p.hp_max then - obj:set_hp(p.hp_max) - end - - p.infotext = string.format("Mob Health: %d/%d", obj:get_hp(), p.hp_max) - obj:set_properties(p) - - self:do_physics() - - -- follow_player - if self.options.follow_player then - self:path_find_nearest_entity(false) - end - - -- follow_items - for _, o in pairs(core.get_objects_inside_radius(obj:get_pos(), cfg.view_range)) do - if o ~= obj then - for _, v in pairs(self.options.follow_items) do - local i = o:get_wielded_item() - - if i:get_name() == v then - self:path_find_entity(o) - end - end - end - end - end, - - on_punch = function(self) - local pos = self.object:get_pos() - core.sound_play(self.options.sounds.hurt, { pos = pos }) - - core.add_particlespawner({ - amount = 8, - time = 0.4, - minexptime = 0.4, - maxexptime = 0.8, - minsize = 1.5, - maxsize = 1.62, - vertical = false, - glow = core.LIGHT_MAX, - - collisiondetection = false, - texture = "pyutest-blood.png", - - minpos = pos, - maxpos = pos, - minvel = vector.new(-1, -1, 1), - maxvel = vector.new(1, 1, 1), - }) - end, - - on_death = function(self) - local pos = self.object:get_pos() - - for _, v in pairs(self.options.drops) do - PyuTest.drop_item(pos, v) - end - end }, { __index = class })) end diff --git a/mods/ENTITIES/pyutest_entities/init.lua b/mods/ENTITIES/pyutest_entities/init.lua index dbe343f..497e3ee 100644 --- a/mods/ENTITIES/pyutest_entities/init.lua +++ b/mods/ENTITIES/pyutest_entities/init.lua @@ -20,6 +20,30 @@ PyuTest.make_mob("pyutest_entities:test_follower", { } }) +PyuTest.make_mob("pyutest_entities:monster", { + visual = "upright_sprite", + visual_size = { x = 1, y = 2 }, + makes_footstep_sound = true, + textures = { + "pyutest-monster.png", "pyutest-monster_back.png" + }, + nametag = "Monster", +}, { + follow_player = true, + hit_damage = 3, + max_jump = 1, + max_drop = 50, + view_range = 10, + + drops = { + "pyutest_tools:bone 2" + }, + + attack_entities = { + "player" + } +}) + PyuTest.make_mob("pyutest_entities:dummy", { visual = "upright_sprite", visual_size = { x = 1, y = 2 }, @@ -42,7 +66,7 @@ PyuTest.make_mob("pyutest_entities:item_follower", { visual_size = { x = 1, y = 2 }, makes_footstep_sound = true, textures = { - "player.png", "player_back.png" + "player.png^[brighten", "player_back.png^[brighten" }, nametag = "Item Follower", }, { @@ -54,13 +78,11 @@ PyuTest.make_mob("pyutest_entities:item_follower", { PyuTest.make_mob("pyutest_entities:pig", { hp_max = 10, - visual = "mesh", - mesh = "pyutest-pig.glb", - visual_size = {x = 6, y = 8, z = 8}, - textures = {"pyutest-pig.png"}, + visual = "upright_sprite", + visual_size = {x = 1, y = 1}, + textures = {"pyutest-pig.png", "pyutest-pig-back.png"}, nametag = "Pig", - collisionbox = PyuTest.BLOCK_SIZED_ANIMAL_CBOX, - selectionbox = PyuTest.NODEBOX_DEFAULT.fixed, + collisionbox = PyuTest.SMALL_ANIMAL_CBOX, }, { drops = {}, follow_items = { diff --git a/mods/ENTITIES/pyutest_mobs/basic.lua b/mods/ENTITIES/pyutest_mobs/basic.lua index 2c6c8c3..e87fa35 100644 --- a/mods/ENTITIES/pyutest_mobs/basic.lua +++ b/mods/ENTITIES/pyutest_mobs/basic.lua @@ -144,17 +144,16 @@ mobs:register_mob("pyutest_mobs:pig", { passive = true, walk_chance = 10, stand_chance = 4, - visual = "mesh", - mesh = "pyutest-pig.glb", - textures = {"pyutest-pig.png"}, + visual = "upright_sprite", + textures = {"pyutest-pig.png", "pyutest-pig-back.png"}, follow = {"pyutest_tools:carrot"}, runaway = true, view_range = 7, fear_height = 5, blood_amount = PyuTest.ENTITY_BLOOD_AMOUNT, makes_footstep_sound = true, - visual_size = {x = 9, y = 9, z = 9}, - collisionbox = {-0.45, -0.01, -0.45, 0.45, 0.865, 0.45}, + visual_size = {x = 1, y = 1}, + collisionbox = PyuTest.SMALL_ANIMAL_CBOX, can_leap = false, jump = false, pushable = false diff --git a/textures/pyutest-pig-back.png b/textures/pyutest-pig-back.png new file mode 100644 index 0000000000000000000000000000000000000000..f5a3e375c59798b67a21a8098bd4a03ba7959c89 GIT binary patch literal 258 zcmV+d0sa1oP)N@U zZ#dld)YX;Ac`OD7eSTfE-K=@4#T(3Kl!s%A3IK}%IiJGqW^HobfMhv8GS^?rK?ybh zbN%(U7)GdIb0rkVnyt6zW@LL literal 0 HcmV?d00001 diff --git a/textures/pyutest-pig.png b/textures/pyutest-pig.png index 24f355b07278107c4a2fedceb54e86b61b6d4002..e1489327230c0ceb2c877e2cfbda79944c6bc53c 100644 GIT binary patch literal 257 zcmV+c0sj7pP)G(BXQ!bGO}K60)hm8H0}GI{Om2N!z-TD9s1}ZC%OFWWKdVSS-oax)%)ax!b6^ z$6^h|8XpIEJ|s%BepSMQrqlq?C8o-Y(VTH2?k5C3v48Of;9*j2*Qs)h00000NkvXX Hu0mjfZTM@_ literal 668 zcmV;N0%QG&P){k{0h*9tG%DEjbsXV(V?*fUDvCpPAHm|=368n9H>b|409hi^ZK!Va~0Zp zAs{C+Ydp2^H|+eOuhTdz+CIz&P#vTo3`A?+?`_6xle&PVBP|S4Df~|Wc4N$MH{76B!}%~y++ z{0ATqKyiK^yfu)zfW<(l*v*MhtO$yJA)<*e04XI%ZiCWk5bG$EFHcH*LlJN~|H3p) z@VsB6j!okL$L}9-&cWk$K|3%XU-G*YP+j10yTJ2)%|4Ci{hAD3d#^xgv8xrq8V9R$ zu$5r#o!$~8lwpw&%1yRKkh%b+N?R3AXad3jtOityx5B^`7*YbI)NT$eCCIJdnDMCq zLy_dV9*&=1tdFEUHX(&I(+x!c*8%F2PucV1xSz|L+6^wHN-ll41RVS%C4xfwI)*j0 zMfDoMeS%!<{u`m)6HvVf)=q(jhK7cQhK7cQz2Xl_UOc