Add 'mobs_redo' compatibility (WIP)

This commit is contained in:
AntumDeluge 2017-08-08 01:38:12 -07:00
parent c364ad6e85
commit e35dd34462
3 changed files with 401 additions and 345 deletions

@ -1,3 +1,4 @@
default default
mobs?
spawneggs? spawneggs?
tnt? tnt?

109
init.lua

@ -26,6 +26,61 @@ for I in pairs(scripts) do
dofile(sneeker.modpath .. '/' .. scripts[I] .. '.lua') dofile(sneeker.modpath .. '/' .. scripts[I] .. '.lua')
end end
local radius = tonumber(core.settings:get('tnt_radius') or 3)
local def = {
hp_max = 20,
physical = true,
collisionbox = {-0.25, -0.7, -0.25, 0.25, 0.8, 0.25},
visual = 'mesh',
mesh = 'character.b3d',
textures = {'sneeker.png'},
makes_footstep_sound = false,
jump_height = 5,
}
if core.global_exists('mobs') then
def.type = 'monster'
def.walk_velocity = 1.5
def.knock_back = 2
def.attack_type = 'explode'
def.explosion_radius = radius
--[[
def.on_blast = function(object, damage)
explode(object)
end
]]
def.animation = {
stand_start = 0,
stand_end = 79,
stand_speed = 30,
walk_start = 168,
walk_end = 187,
walk_speek = 30,
}
def.sounds = {
explode = 'sneeker_explode',
distance = 128,
}
mobs:register_mob(sneeker.mob_name, def)
-- TODO: Add alias
else
def.walk_speed = 1.5
def.knockback_level = 2
def.animation = {
stand_START = 0,
stand_END = 79,
walk_START = 168,
walk_END = 187,
}
def.animation_speed = 30
local function jump(self,pos,direction) local function jump(self,pos,direction)
local velocity = self.object:getvelocity() local velocity = self.object:getvelocity()
if core.registered_nodes[core.get_node(pos).name].climbable then if core.registered_nodes[core.get_node(pos).name].climbable then
@ -55,6 +110,7 @@ local function jump(self,pos,direction)
end end
end end
local function random_turn(self) local function random_turn(self)
if self.turn_timer > math.random(2,5) then if self.turn_timer > math.random(2,5) then
local select_turn = math.random(1,3) local select_turn = math.random(1,3)
@ -70,27 +126,6 @@ local function random_turn(self)
end end
end end
local def = {
hp_max = 20,
physical = true,
collisionbox = {-0.25,-0.7,-0.25, 0.25,0.8,0.25},
visual = 'mesh',
mesh = 'character.b3d',
textures = {'sneeker.png'},
makes_footstep_sound = false,
-- Original
animation = {
stand_START = 0,
stand_END = 79,
walk_START = 168,
walk_END = 187
},
walk_speed = 1.5,
jump_height = 5,
animation_speed = 30,
knockback_level = 2
}
def.on_activate = function(self,staticdata) def.on_activate = function(self,staticdata)
self.yaw = 0 self.yaw = 0
@ -119,6 +154,7 @@ def.on_activate = function(self,staticdata)
end end
end end
def.on_step = function(self, dtime) def.on_step = function(self, dtime)
if self.knockback then if self.knockback then
return return
@ -313,6 +349,7 @@ def.on_step = function(self, dtime)
end end
end end
def.on_punch = function(self,puncher,time_from_last_punch,tool_capabilities,dir) def.on_punch = function(self,puncher,time_from_last_punch,tool_capabilities,dir)
if self.knockback == false then if self.knockback == false then
local knockback_level = self.knockback_level local knockback_level = self.knockback_level
@ -335,39 +372,13 @@ def.on_punch = function(self,puncher,time_from_last_punch,tool_capabilities,dir)
end end
end end
def.get_staticdata = function(self) def.get_staticdata = function(self)
return core.serialize({ return core.serialize({
powered = self.powered powered = self.powered
}) })
end end
core.register_entity(sneeker.mob_name, def) core.register_entity(sneeker.mob_name, def)
if core.get_modpath('spawneggs') and core.get_modpath('tnt') then
core.register_craftitem(sneeker.spawnegg_name, {
description = 'Sneeker Spawn Egg',
inventory_image = 'sneeker_spawnegg.png',
stack_max = 64,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type == 'node' then
local pos = pointed_thing.above
pos.y = pos.y+1
core.add_entity(pos, sneeker.mob_name)
if not core.settings:get_bool('creative_mode') then
itemstack:take_item()
end
return itemstack
end
end
})
core.register_craft({
output = sneeker.spawnegg_name,
type = 'shapeless',
recipe = {
'spawneggs:egg', 'tnt:tnt',
},
})
core.register_alias('spawneggs:sneeker', sneeker.spawnegg_name)
end end

@ -23,6 +23,20 @@ sneeker.log('Spawn chance: ' .. spawn_chance_percent)
sneeker.log('Spawn interval: ' .. tostring(spawn_interval) .. ' (' .. tostring(spawn_interval/60) .. ' minute(s))') sneeker.log('Spawn interval: ' .. tostring(spawn_interval) .. ' (' .. tostring(spawn_interval/60) .. ' minute(s))')
sneeker.log('Maximum light value for spawn: ' .. tostring(spawn_maxlight)) sneeker.log('Maximum light value for spawn: ' .. tostring(spawn_maxlight))
if core.global_exists('mobs') then
mobs:spawn({
name = sneeker.mob_name,
nodes = {'default:dirt_with_grass', 'default:stone'},
neighbors = {'air'},
min_light = -1,
max_light = spawn_maxlight,
interval = spawn_interval,
chance = spawn_chance,
})
mobs:register_egg(sneeker.mob_name, 'Sneeker Spawn Egg', 'sneeker_spawnegg.png', 0, false)
else
core.register_abm({ core.register_abm({
nodenames = {'default:dirt_with_grass', 'default:stone'}, nodenames = {'default:dirt_with_grass', 'default:stone'},
neighbors = {'air'}, neighbors = {'air'},
@ -77,3 +91,33 @@ core.register_abm({
sneeker.spawn(pos) sneeker.spawn(pos)
end end
}) })
if core.get_modpath('spawneggs') and core.get_modpath('tnt') then
core.register_craftitem(sneeker.spawnegg_name, {
description = 'Sneeker Spawn Egg',
inventory_image = 'sneeker_spawnegg.png',
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type == 'node' then
local pos = pointed_thing.above
pos.y = pos.y+1
core.add_entity(pos, sneeker.mob_name)
if not core.settings:get_bool('creative_mode') then
itemstack:take_item()
end
return itemstack
end
end
})
core.register_craft({
output = sneeker.spawnegg_name,
type = 'shapeless',
recipe = {
'spawneggs:egg', 'tnt:tnt',
},
})
core.register_alias('spawneggs:sneeker', sneeker.spawnegg_name)
end
end