This commit is contained in:
Jordan Irwin 2021-05-08 11:42:35 -07:00
parent b082a746fa
commit be4c3617af
3 changed files with 100 additions and 101 deletions

@ -1,30 +1,27 @@
sneeker = {}
--[[
-- DISABLED!!!
do return end
--]]
sneeker = {}
dofile(minetest.get_modpath("sneeker").."/tnt_function.lua")
dofile(minetest.get_modpath("sneeker").."/spawn.lua")
local function jump(self, pos, direction)
local velocity = self.object:get_velocity()
if minetest.registered_nodes[minetest.get_node(pos).name].climbable then
if core.registered_nodes[core.get_node(pos).name].climbable then
self.object:set_velocity({x=velocity.x, y=4, z=velocity.z})
return
end
local spos = {x=pos.x+direction.x, y=pos.y, z=pos.z+direction.z}
local node = minetest.get_node_or_nil(spos)
local node = core.get_node_or_nil(spos)
spos.y = spos.y+1
local node2 = minetest.get_node_or_nil(spos)
local node2 = core.get_node_or_nil(spos)
local def, def2 = {}
if node and node.name then
def = minetest.registered_items[node.name]
def = core.registered_items[node.name]
end
if node2 and node2.name then
def2 = minetest.registered_items[node2.name]
def2 = core.registered_items[node2.name]
end
if def and def.walkable
and def2 and not def2.walkable
@ -87,7 +84,7 @@ def.on_activate = function(self,staticdata)
self.state = math.random(1, 2)
self.old_y = self.object:get_pos().y
local data = minetest.deserialize(staticdata)
local data = core.deserialize(staticdata)
if data and type(data) == "table" then
if data.powered == true then
self.powered = true
@ -116,7 +113,7 @@ def.on_step = function(self, dtime)
local pos = self.object:get_pos()
local yaw = self.object:get_yaw()
local inside = minetest.get_objects_inside_radius(pos,10)
local inside = core.get_objects_inside_radius(pos, 10)
local walk_speed = self.walk_speed
local animation = self.animation
local anim_speed = self.animation_speed
@ -146,7 +143,7 @@ def.on_step = function(self, dtime)
if self.chase and self.visualx < 2 then
if self.hiss == false then
minetest.sound_play("sneeker_hiss",{pos=pos,gain=1.5,max_hear_distance=2*64})
core.sound_play("sneeker_hiss", {pos=pos, gain=1.5, max_hear_distance=2*64})
end
self.visualx = self.visualx+0.05
self.object:set_properties({
@ -202,7 +199,7 @@ def.on_step = function(self, dtime)
local direction = self.direction
local npos = {x=pos.x+direction.x, y=pos.y+0.2, z=pos.z+direction.z}
if velocity.x == 0 or velocity.z == 0
or minetest.registered_nodes[minetest.get_node(npos).name].walkable then
or core.registered_nodes[core.get_node(npos).name].walkable then
local select_turn = math.random(1, 2)
if select_turn == 1 then
self.turn = "left"
@ -228,7 +225,7 @@ def.on_step = function(self, dtime)
self.turn = "straight"
local inside_2 = minetest.get_objects_inside_radius(pos,2)
local inside_2 = core.get_objects_inside_radius(pos, 2)
-- Boom
if #inside_2 ~= 0 then
@ -238,7 +235,7 @@ def.on_step = function(self, dtime)
if self.visualx >= 2 then
self.object:remove()
sneeker.boom(pos, self.powered)
minetest.sound_play("sneeker_explode",{pos=pos,gain=1.5,max_hear_distance=2*64})
core.sound_play("sneeker_explode", {pos=pos, gain=1.5, max_hear_distance=2*64})
end
end
end
@ -298,8 +295,8 @@ def.on_step = function(self, dtime)
end
-- Swim
local node = minetest.get_node(pos)
if minetest.get_item_group(node.name,"water") ~= 0 then
local node = core.get_node(pos)
if core.get_item_group(node.name, "water") ~= 0 then
self.object:set_acceleration({x=0, y=1, z=0})
local velocity = self.object:get_velocity()
if self.object:get_velocity().y > 5 then
@ -317,7 +314,7 @@ def.on_punch = function(self,puncher,time_from_last_punch,tool_capabilities,dir)
local knockback_level = self.knockback_level
self.object:set_velocity({x=dir.x*knockback_level, y=3, z=dir.z*knockback_level})
self.knockback = true
minetest.after(0.6,function()
core.after(0.6, function()
self.knockback = false
end)
end
@ -326,23 +323,23 @@ def.on_punch = function(self,puncher,time_from_last_punch,tool_capabilities,dir)
local x = 1/math.random(1, 5)*dir.x
local z = 1/math.random(1, 5)*dir.z
local p = {x=pos.x+x, y=pos.y, z=pos.z+z}
local node = minetest.get_node_or_nil(p)
local node = core.get_node_or_nil(p)
if node == nil or not node.name or node.name ~= "air" then
p = pos
end
local obj = minetest.add_item(p, {name="tnt:gunpowder",count=math.random(0,2)})
local obj = core.add_item(p, {name="tnt:gunpowder", count=math.random(0, 2)})
end
end
def.get_staticdata = function(self)
return minetest.serialize({
return core.serialize({
powered = self.powered
})
end
minetest.register_entity("sneeker:sneeker",def)
core.register_entity("sneeker:sneeker", def)
minetest.register_craftitem("sneeker:spawnegg",{
core.register_craftitem("sneeker:spawnegg", {
description = "Sneeker Spawn Egg",
inventory_image = "sneeker_spawnegg.png",
stack_max = 64,
@ -350,8 +347,8 @@ minetest.register_craftitem("sneeker:spawnegg",{
if pointed_thing.type == "node" then
local pos = pointed_thing.above
pos.y = pos.y+1
minetest.add_entity(pos,"sneeker:sneeker")
if not minetest.setting_getbool("creative_mode") then
core.add_entity(pos, "sneeker:sneeker")
if not core.setting_getbool("creative_mode") then
itemstack:take_item()
end
return itemstack

@ -1,4 +1,5 @@
minetest.register_abm({
core.register_abm({
nodenames = {"default:dirt_with_grass", "default:stone"},
neighbors = {"air"},
interval = 30,
@ -8,25 +9,25 @@ minetest.register_abm({
return
end
pos.y = pos.y+1
if not minetest.get_node_light(pos) then
if not core.get_node_light(pos) then
return
end
if minetest.get_node_light(pos) > 5 then
if core.get_node_light(pos) > 5 then
return
end
if minetest.get_node_light(pos) < -1 then
if core.get_node_light(pos) < -1 then
return
end
if pos.y > 31000 then
return
end
if minetest.get_node(pos).name ~= "air" then
if core.get_node(pos).name ~= "air" then
return
end
pos.y = pos.y+1
if minetest.get_node(pos).name ~= "air" then
if core.get_node(pos).name ~= "air" then
return
end
minetest.add_entity(pos,"sneeker:sneeker")
core.add_entity(pos, "sneeker:sneeker")
end
})

@ -1,14 +1,15 @@
-- From TNT
local cid_data = {}
local radius = tonumber(minetest.setting_get("tnt_radius") or 3)
local radius = tonumber(core.setting_get("tnt_radius") or 3)
local large_radius = 5
local loss_prob = {
["default:cobble"] = 3,
["default:dirt"] = 4,
}
minetest.after(0, function()
for name, def in pairs(minetest.registered_nodes) do
cid_data[minetest.get_content_id(name)] = {
core.after(0, function()
for name, def in pairs(core.registered_nodes) do
cid_data[core.get_content_id(name)] = {
name = name,
drops = def.drops,
flammable = def.groups.flammable,
@ -34,7 +35,7 @@ local function eject_drops(drops, pos, radius)
item:set_count(count)
end
rand_pos(pos, drop_pos, radius)
local obj = minetest.add_item(drop_pos, item)
local obj = core.add_item(drop_pos, item)
if obj then
obj:get_luaentity().collect = true
obj:set_acceleration({x=0, y=-10, z=0})
@ -62,7 +63,7 @@ local function add_drop(drops, item)
end
local function destroy(drops, pos, cid)
if minetest.is_protected(pos, "") then
if core.is_protected(pos, "") then
return
end
local def = cid_data[cid]
@ -70,9 +71,9 @@ local function destroy(drops, pos, cid)
def.on_blast(vector.new(pos), 1)
return
end
minetest.remove_node(pos)
core.remove_node(pos)
if def then
local node_drops = minetest.get_node_drops(def.name, "")
local node_drops = core.get_node_drops(def.name, "")
for _, item in ipairs(node_drops) do
add_drop(drops, item)
end
@ -98,7 +99,7 @@ end
local function entity_physics(pos, radius)
-- Make the damage radius larger than the destruction radius
radius = radius * 2
local objs = minetest.get_objects_inside_radius(pos, radius)
local objs = core.get_objects_inside_radius(pos, radius)
for _, obj in pairs(objs) do
local obj_pos = obj:get_pos()
local obj_vel = obj:get_velocity()
@ -115,7 +116,7 @@ local function entity_physics(pos, radius)
end
local function add_effects(pos, radius)
minetest.add_particlespawner({
core.add_particlespawner({
amount = 128,
time = 1,
minpos = vector.subtract(pos, radius / 2),
@ -146,16 +147,16 @@ local function explode(pos, radius)
local drops = {}
local p = {}
local c_air = minetest.get_content_id("air")
local c_air = core.get_content_id("air")
local c_tnt = nil
if minetest.settings:get_bool("enable_tnt", false) then
c_tnt = minetest.get_content_id("tnt:tnt")
if core.settings:get_bool("enable_tnt", false) then
c_tnt = core.get_content_id("tnt:tnt")
end
local c_tnt_burning = minetest.get_content_id("tnt:tnt_burning")
local c_gunpowder = minetest.get_content_id("tnt:gunpowder")
local c_gunpowder_burning = minetest.get_content_id("tnt:gunpowder_burning")
local c_boom = minetest.get_content_id("tnt:boom")
local c_tnt_burning = core.get_content_id("tnt:tnt_burning")
local c_gunpowder = core.get_content_id("tnt:gunpowder")
local c_gunpowder_burning = core.get_content_id("tnt:gunpowder_burning")
local c_boom = core.get_content_id("tnt:boom")
for z = -radius, radius do
for y = -radius, radius do
@ -189,9 +190,9 @@ function sneeker.boom(pos,large)
if large then
radius = large_radius
end
minetest.sound_play("sneeker_explode", {pos=pos, gain=1.5, max_hear_distance=2*64})
minetest.set_node(pos, {name="tnt:boom"})
minetest.get_node_timer(pos):start(0.5)
core.sound_play("sneeker_explode", {pos=pos, gain=1.5, max_hear_distance=2*64})
core.set_node(pos, {name="tnt:boom"})
core.get_node_timer(pos):start(0.5)
local drops = explode(pos, radius)
entity_physics(pos, radius)
eject_drops(drops, pos, radius)