Stop using pig model make it a flat 2d entity, and more changes to entity system (It'll never be done at this rate)
This commit is contained in:
parent
274c8f1261
commit
c8a5f27f28
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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 = {
|
||||
|
@ -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
|
||||
|
BIN
textures/pyutest-pig-back.png
Normal file
BIN
textures/pyutest-pig-back.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 258 B |
Binary file not shown.
Before Width: | Height: | Size: 668 B After Width: | Height: | Size: 257 B |
Loading…
x
Reference in New Issue
Block a user