7 Commits
mobs ... 5.x

Author SHA1 Message Date
Jordan Irwin
84f6c2f3c9 Hack: check that coordinates are numbers before setting new velocity 2021-05-06 18:01:33 -07:00
Jordan Irwin
6c46f8bf7e Check that tnt is enabled 2021-05-06 18:00:40 -07:00
Jordan Irwin
45b0bf5f08 Update for Minetest 5.x API 2021-05-06 17:58:47 -07:00
Jordan Irwin
6efa22caf4 Fix line endings 2021-05-06 17:32:24 -07:00
Jordan Irwin
b88e4357f9 Add tnt as dependency 2021-05-06 17:14:03 -07:00
Jordan Irwin
cc9cb71090 Whitespace cleanup 2021-05-06 17:13:44 -07:00
Jordan Irwin
a89eb699c9 Move description & dependencies into mod.conf 2021-05-06 17:10:14 -07:00
5 changed files with 375 additions and 351 deletions

View File

@@ -1 +0,0 @@
default

View File

@@ -1 +0,0 @@
Adds some explosive nuisance.

View File

@@ -9,9 +9,9 @@ dofile(minetest.get_modpath("creeper").."/tnt_function.lua")
dofile(minetest.get_modpath("creeper").."/spawn.lua")
local function jump(self,pos,direction)
local velocity = self.object:getvelocity()
local velocity = self.object:get_velocity()
if minetest.registered_nodes[minetest.get_node(pos).name].climbable then
self.object:setvelocity({x=velocity.x,y=4,z=velocity.z})
self.object:set_velocity({x=velocity.x,y=4,z=velocity.z})
return
end
@@ -29,7 +29,7 @@ local function jump(self,pos,direction)
if def and def.walkable
and def2 and not def2.walkable
and def.drawtype ~= "fencelike" then
self.object:setvelocity({
self.object:set_velocity({
x=velocity.x*2.2,
y=self.jump_height,
z=velocity.z*2.2
@@ -85,7 +85,7 @@ def.on_activate = function(self,staticdata)
self.powered = false
self.knockback = false
self.state = math.random(1,2)
self.old_y = self.object:getpos().y
self.old_y = self.object:get_pos().y
local data = minetest.deserialize(staticdata)
if data and type(data) == "table" then
@@ -101,6 +101,11 @@ def.on_activate = function(self,staticdata)
end
end
local function isnan(n)
return tostring(n) == tostring((-1)^.5)
end
def.on_step = function(self, dtime)
if self.knockback then
return
@@ -109,13 +114,13 @@ def.on_step = function(self, dtime)
local ANIM_STAND = 1
local ANIM_WALK = 2
local pos = self.object:getpos()
local yaw = self.object:getyaw()
local pos = self.object:get_pos()
local yaw = self.object:get_yaw()
local inside = minetest.get_objects_inside_radius(pos,10)
local walk_speed = self.walk_speed
local animation = self.animation
local anim_speed = self.animation_speed
local velocity = self.object:getvelocity()
local velocity = self.object:get_velocity()
self.timer = self.timer+0.01
self.turn_timer = self.turn_timer+0.01
@@ -133,10 +138,10 @@ def.on_step = function(self, dtime)
if self.turn == "right" then
self.yaw = self.yaw+self.turn_speed
self.object:setyaw(self.yaw)
self.object:set_yaw(self.yaw)
elseif self.turn == "left" then
self.yaw = self.yaw-self.turn_speed
self.object:setyaw(self.yaw)
self.object:set_yaw(self.yaw)
end
if self.chase and self.visualx < 2 then
@@ -174,7 +179,7 @@ def.on_step = function(self, dtime)
if velocity.x ~= 0
or velocity.z ~= 0 then
self.object:setvelocity({x=0,y=velocity.y,z=0})
self.object:set_velocity({x=0,y=velocity.y,z=0})
end
end
@@ -186,12 +191,12 @@ def.on_step = function(self, dtime)
self.direction = {x=math.sin(yaw)*-1,y=-10,z=math.cos(yaw)}
if self.direction then
self.object:setvelocity({x=self.direction.x*walk_speed,y=velocity.y,z=self.direction.z*walk_speed})
self.object:set_velocity({x=self.direction.x*walk_speed,y=velocity.y,z=self.direction.z*walk_speed})
end
random_turn(self)
local velocity = self.object:getvelocity()
local velocity = self.object:get_velocity()
if self.turn_timer > 1 then
local direction = self.direction
@@ -250,24 +255,36 @@ def.on_step = function(self, dtime)
self.object:set_animation({x=animation.stand_START,y=animation.stand_END},anim_speed,0)
self.anim = ANIM_STAND
end
self.object:setvelocity({x=0,y=velocity.y,z=0})
self.object:set_velocity({x=0,y=velocity.y,z=0})
return
end
end
end
local ppos = object:getpos()
local ppos = object:get_pos()
self.vec = {x=ppos.x-pos.x,y=ppos.y-pos.y,z=ppos.z-pos.z}
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
if ppos.x > pos.x then
self.yaw = self.yaw+math.pi
end
self.yaw = self.yaw-2
self.object:setyaw(self.yaw)
self.object:set_yaw(self.yaw)
self.direction = {x=math.sin(self.yaw)*-1,y=0,z=math.cos(self.yaw)}
local direction = self.direction
self.object:setvelocity({x=direction.x*2.5,y=velocity.y,z=direction.z*2.5})
-- FIXME: hack
local can_set = true
for _, c in ipairs({direction.x*2.5, direction.z*2.5}) do
if isnan(c) then
can_set = false
break
end
end
if can_set then
self.object:set_velocity({x=direction.x*2.5,y=velocity.y,z=direction.z*2.5})
end
-- Jump
if self.jump_timer > 0.2 then
@@ -283,29 +300,29 @@ def.on_step = function(self, dtime)
-- Swim
local node = minetest.get_node(pos)
if minetest.get_item_group(node.name,"water") ~= 0 then
self.object:setacceleration({x=0,y=1,z=0})
local velocity = self.object:getvelocity()
if self.object:getvelocity().y > 5 then
self.object:setvelocity({x=0,y=velocity.y-velocity.y/2,z=0})
self.object:set_acceleration({x=0,y=1,z=0})
local velocity = self.object:get_velocity()
if self.object:get_velocity().y > 5 then
self.object:set_velocity({x=0,y=velocity.y-velocity.y/2,z=0})
else
self.object:setvelocity({x=0,y=velocity.y+1,z=0})
self.object:set_velocity({x=0,y=velocity.y+1,z=0})
end
else
self.object:setacceleration({x=0,y=-10,z=0})
self.object:set_acceleration({x=0,y=-10,z=0})
end
end
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})
self.object:set_velocity({x=dir.x*knockback_level,y=3,z=dir.z*knockback_level})
self.knockback = true
minetest.after(0.6,function()
self.knockback = false
end)
end
if self.object:get_hp() < 1 then
local pos = self.object:getpos()
local pos = self.object:get_pos()
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}

5
mod.conf Normal file
View File

@@ -0,0 +1,5 @@
name = creeper
title = Creeper
description = Adds some explosive nuisance.
author = Rui
depends = default, tnt

View File

@@ -37,8 +37,8 @@ local function eject_drops(drops, pos, radius)
local obj = minetest.add_item(drop_pos, item)
if obj then
obj:get_luaentity().collect = true
obj:setacceleration({x=0, y=-10, z=0})
obj:setvelocity({x=math.random(-3, 3), y=10,
obj:set_acceleration({x=0, y=-10, z=0})
obj:set_velocity({x=math.random(-3, 3), y=10,
z=math.random(-3, 3)})
end
count = count - max
@@ -100,12 +100,12 @@ local function entity_physics(pos, radius)
radius = radius * 2
local objs = minetest.get_objects_inside_radius(pos, radius)
for _, obj in pairs(objs) do
local obj_pos = obj:getpos()
local obj_vel = obj:getvelocity()
local obj_pos = obj:get_pos()
local obj_vel = obj:get_velocity()
local dist = math.max(1, vector.distance(pos, obj_pos))
if obj_vel ~= nil then
obj:setvelocity(calc_velocity(pos, obj_pos,
obj:set_velocity(calc_velocity(pos, obj_pos,
obj_vel, radius * 10))
end
@@ -147,7 +147,11 @@ local function explode(pos, radius)
local p = {}
local c_air = minetest.get_content_id("air")
local c_tnt = minetest.get_content_id("tnt:tnt")
local c_tnt = nil
if minetest.settings:get_bool("enable_tnt", false) then
c_tnt = minetest.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")