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
mobs?
spawneggs?
tnt?

137
init.lua

@ -26,7 +26,62 @@ for I in pairs(scripts) do
dofile(sneeker.modpath .. '/' .. scripts[I] .. '.lua')
end
local function jump(self,pos,direction)
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 velocity = self.object:getvelocity()
if core.registered_nodes[core.get_node(pos).name].climbable then
self.object:setvelocity({x=velocity.x,y=4,z=velocity.z})
@ -53,9 +108,10 @@ local function jump(self,pos,direction)
z=velocity.z*2.2
})
end
end
end
local function random_turn(self)
local function random_turn(self)
if self.turn_timer > math.random(2,5) then
local select_turn = math.random(1,3)
if select_turn == 1 then
@ -68,31 +124,10 @@ local function random_turn(self)
self.turn_timer = 0
self.turn_speed = 0.05*math.random()
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.anim = 1
self.timer = 0
@ -117,9 +152,10 @@ def.on_activate = function(self,staticdata)
self.object:set_properties({textures = {'sneeker_powered.png'}})
end
end
end
end
def.on_step = function(self, dtime)
def.on_step = function(self, dtime)
if self.knockback then
return
end
@ -311,9 +347,10 @@ def.on_step = function(self, dtime)
else
self.object:setacceleration({x=0,y=-10,z=0})
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
local knockback_level = self.knockback_level
self.object:setvelocity({x=dir.x*knockback_level,y=3,z=dir.z*knockback_level})
@ -333,41 +370,15 @@ def.on_punch = function(self,puncher,time_from_last_punch,tool_capabilities,dir)
end
local obj = core.add_item(p, {name='tnt:gunpowder',count=math.random(0,2)})
end
end
end
def.get_staticdata = function(self)
def.get_staticdata = function(self)
return core.serialize({
powered = self.powered
})
end
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
core.register_entity(sneeker.mob_name, def)
end

@ -23,7 +23,21 @@ sneeker.log('Spawn chance: ' .. spawn_chance_percent)
sneeker.log('Spawn interval: ' .. tostring(spawn_interval) .. ' (' .. tostring(spawn_interval/60) .. ' minute(s))')
sneeker.log('Maximum light value for spawn: ' .. tostring(spawn_maxlight))
core.register_abm({
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({
nodenames = {'default:dirt_with_grass', 'default:stone'},
neighbors = {'air'},
interval = spawn_interval,
@ -76,4 +90,34 @@ core.register_abm({
sneeker.spawn(pos)
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