1
0
Fork 0

Get rid of a ton of global variables

This commit is contained in:
Wuzzy 2017-01-24 02:31:49 +01:00
parent 06933135b4
commit bc9491ffdd
22 changed files with 214 additions and 4114 deletions

View File

@ -16,7 +16,7 @@ local function get_dir(pos)
end
end
function plock(start, max, tick, player, yaw)
local function plock(start, max, tick, player, yaw)
if start+tick < max then
player:set_look_pitch(-1.2)
player:set_look_yaw(yaw)
@ -27,7 +27,7 @@ function plock(start, max, tick, player, yaw)
end
end
function exit(pos)
local function exit(pos)
local npos = minetest.find_node_near(pos, 1, "beds:bed_bottom")
if npos ~= nil then pos = npos end
if minetest.get_node({x=pos.x+1,y=pos.y,z=pos.z}).name == "air" then
@ -173,7 +173,7 @@ minetest.register_craft({
}
})
beds_player_spawns = {}
local beds_player_spawns = {}
local file = io.open(minetest.get_worldpath().."/beds_player_spawns", "r")
if file then
beds_player_spawns = minetest.deserialize(file:read("*all"))

View File

@ -1,13 +1,3 @@
-- Boilerplate to support localized strings if intllib mod is installed.
local S;
if (minetest.get_modpath("intllib")) then
dofile(minetest.get_modpath("intllib").."/intllib.lua");
S = intllib.Getter(minetest.get_current_modname());
else
S = function ( s ) return s end;
end
local function deepcopy ( t )
local nt = { };
for k, v in pairs(t) do

View File

@ -1,40 +1,7 @@
crafting = {}
crafting.creative_inventory_size = 0
function init()
local inv = minetest.create_detached_inventory("creative", {
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
if minetest.setting_getbool("creative_mode") then
return count
else
return 0
end
end,
allow_put = function(inv, listname, index, stack, player)
return 0
end,
allow_take = function(inv, listname, index, stack, player)
if minetest.setting_getbool("creative_mode") then
return -1
else
return 0
end
end,
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
end,
on_put = function(inv, listname, index, stack, player)
end,
on_take = function(inv, listname, index, stack, player)
print(player:get_player_name().." takes item from creative inventory; listname="..dump(listname)..", index="..dump(index)..", stack="..dump(stack))
if stack then
print("stack:get_name()="..dump(stack:get_name())..", stack:get_count()="..dump(stack:get_count()))
end
end,
})
set_inv("#all")
end
function set_inv(filter, player)
local function set_inv(filter, player)
local inv = minetest.get_inventory({type="detached", name="creative"})
inv:set_size("main", 0)
local creative_list = {}
@ -110,6 +77,39 @@ function set_inv(filter, player)
--print("creative inventory size: "..dump(crafting.creative_inventory_size))
end
local function init()
local inv = minetest.create_detached_inventory("creative", {
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
if minetest.setting_getbool("creative_mode") then
return count
else
return 0
end
end,
allow_put = function(inv, listname, index, stack, player)
return 0
end,
allow_take = function(inv, listname, index, stack, player)
if minetest.setting_getbool("creative_mode") then
return -1
else
return 0
end
end,
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
end,
on_put = function(inv, listname, index, stack, player)
end,
on_take = function(inv, listname, index, stack, player)
print(player:get_player_name().." takes item from creative inventory; listname="..dump(listname)..", index="..dump(index)..", stack="..dump(stack))
if stack then
print("stack:get_name()="..dump(stack:get_name())..", stack:get_count()="..dump(stack:get_count()))
end
end,
})
set_inv("#all")
end
-- Create the trash field
local trash = minetest.create_detached_inventory("creative_trash", {
allow_put = function(inv, listname, index, stack, player)

View File

@ -35,7 +35,7 @@ minetest.register_abm({
--
-- Functions
grow_cactus = function(pos, node)
local grow_cactus = function(pos, node)
pos.y = pos.y-1
local name = minetest.get_node(pos).name
if minetest.get_item_group(name, "sand") ~= 0 then
@ -53,7 +53,7 @@ grow_cactus = function(pos, node)
end
end
grow_reeds = function(pos, node)
local grow_reeds = function(pos, node)
pos.y = pos.y-1
local name = minetest.get_node(pos).name
if minetest.get_node_group(name, "soil_sugarcane") ~= 0 then

View File

@ -480,7 +480,7 @@ local function punch(pos)
me = minetest.get_node(pos)
local tmp_node
local tmp_node2
oben = {x=pos.x, y=pos.y+1, z=pos.z}
local oben = {x=pos.x, y=pos.y+1, z=pos.z}
if state == 1 then
state = 0
minetest.sound_play("door_close", {pos = pos, gain = 0.3, max_hear_distance = 10})
@ -604,7 +604,7 @@ local function punch(pos)
me = minetest.get_node(pos)
local tmp_node
local tmp_node2
oben = {x=pos.x, y=pos.y+1, z=pos.z}
local oben = {x=pos.x, y=pos.y+1, z=pos.z}
if state == 1 then
state = 0
minetest.sound_play("door_close", {pos = pos, gain = 0.3, max_hear_distance = 10})

View File

@ -26,7 +26,7 @@ minetest.register_node("farming:melon", {
end
if have_change == 0 then
for z=-1,1 do
p = {x=pos.x, y=pos.y, z=pos.z+z}
local p = {x=pos.x, y=pos.y, z=pos.z+z}
local n = minetest.get_node(p)
if string.find(n.name, "melontige_linked_") and have_change == 0 then
have_change = 1
@ -249,9 +249,9 @@ minetest.register_abm({
end
if have_change == 0 then
for z=-1,1 do
p = {x=pos.x, y=pos.y-1, z=pos.z+z}
local p = {x=pos.x, y=pos.y-1, z=pos.z+z}
newpos = {x=pos.x, y=pos.y, z=pos.z+z}
n = minetest.get_node(p)
local n = minetest.get_node(p)
local nod2 = minetest.get_node(newpos)
if n.name=="default:dirt_with_grass" and nod2.name=="air" and have_change == 0
or n.name=="default:dirt" and nod2.name=="air" and have_change == 0

View File

@ -1,5 +1,3 @@
LIGHT_MAX = 15
minetest.register_craftitem("farming:pumpkin_seed", {
description = "Pumpkin Seed",
stack_max = 64,
@ -69,7 +67,7 @@ minetest.register_node("farming:pumpkin_face", {
end
if have_change == 0 then
for z=-1,1 do
p = {x=pos.x, y=pos.y, z=pos.z+z}
local p = {x=pos.x, y=pos.y, z=pos.z+z}
local n = minetest.get_node(p)
if string.find(n.name, "pumpkintige_linked_") and have_change == 0 then
have_change = 1
@ -245,9 +243,9 @@ minetest.register_abm({
end
if have_change == 0 then
for z=-1,1 do
p = {x=pos.x, y=pos.y-1, z=pos.z+z}
local p = {x=pos.x, y=pos.y-1, z=pos.z+z}
newpos = {x=pos.x, y=pos.y, z=pos.z+z}
n = minetest.get_node(p)
local n = minetest.get_node(p)
local nod2 = minetest.get_node(newpos)
if n.name=="default:dirt_with_grass" and nod2.name=="air" and have_change == 0
or n.name=="default:dirt" and nod2.name=="air" and have_change == 0

View File

@ -138,7 +138,7 @@ local names = { "Oak Boat", "Spruce Boat", "Birch Boat", "Jungle Boat", "Dark Oa
local craftstuffs = { "default:wood", "default:sprucewood", "default:birchwood", "default:junglewood", "default:darkwood", "default:acaciawood" }
for w=1, #woods do
textures = {"mcl_boats_texture.png"},
local textures = {"mcl_boats_texture.png"}
minetest.register_entity("mcl_boats:boat"..woods[w], boat)
minetest.register_craftitem("mcl_boats:boat"..woods[w], {

View File

@ -3,13 +3,13 @@
#!#!#!#Released under CC Attribution-ShareAlike 3.0 Unported #!#!#
]]--
cake_texture = {"cake_top.png","cake_bottom.png","cake_inner.png","cake_side.png","cake_side.png","cake_side.png"}
slice_1 = { -7/16, -8/16, -7/16, -5/16, 0/16, 7/16}
slice_2 = { -7/16, -8/16, -7/16, -2/16, 0/16, 7/16}
slice_3 = { -7/16, -8/16, -7/16, 1/16, 0/16, 7/16}
slice_4 = { -7/16, -8/16, -7/16, 3/16, 0/16, 7/16}
slice_5 = { -7/16, -8/16, -7/16, 5/16, 0/16, 7/16}
slice_6 = { -7/16, -8/16, -7/16, 7/16, 0/16, 7/16}
local cake_texture = {"cake_top.png","cake_bottom.png","cake_inner.png","cake_side.png","cake_side.png","cake_side.png"}
local slice_1 = { -7/16, -8/16, -7/16, -5/16, 0/16, 7/16}
local slice_2 = { -7/16, -8/16, -7/16, -2/16, 0/16, 7/16}
local slice_3 = { -7/16, -8/16, -7/16, 1/16, 0/16, 7/16}
local slice_4 = { -7/16, -8/16, -7/16, 3/16, 0/16, 7/16}
local slice_5 = { -7/16, -8/16, -7/16, 5/16, 0/16, 7/16}
local slice_6 = { -7/16, -8/16, -7/16, 7/16, 0/16, 7/16}
minetest.register_craft({
output = "mcl_cake:cake",
@ -46,7 +46,7 @@ minetest.register_node("mcl_cake:cake", {
drop = '',
on_rightclick = function(pos, node, clicker, itemstack)
minetest.do_item_eat(2, ItemStack("mcl_cake:cake_5"), ItemStack("mcl_cake:cake"), clicker, {type="nothing"})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_5",param2=param2})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_5",param2=0})
end,
sounds = default.node_sound_leaves_defaults(),
})
@ -68,7 +68,7 @@ minetest.register_node("mcl_cake:cake_5", {
drop = '',
on_rightclick = function(pos, node, clicker, itemstack)
minetest.do_item_eat(2, ItemStack("mcl_cake:cake_4"), ItemStack("mcl_cake:cake_5"), clicker, {type="nothing"})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_4",param2=param2})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_4",param2=0})
end,
sounds = default.node_sound_leaves_defaults(),
})
@ -90,7 +90,7 @@ minetest.register_node("mcl_cake:cake_4", {
drop = '',
on_rightclick = function(pos, node, clicker, itemstack)
minetest.do_item_eat(2, ItemStack("mcl_cake:cake_3"), ItemStack("mcl_cake:cake_4"), clicker, {type="nothing"})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_3",param2=param2})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_3",param2=0})
end,
sounds = default.node_sound_leaves_defaults(),
})
@ -112,7 +112,7 @@ minetest.register_node("mcl_cake:cake_3", {
drop = '',
on_rightclick = function(pos, node, clicker, itemstack)
minetest.do_item_eat(2, ItemStack("mcl_cake:cake_2"), ItemStack("mcl_cake:cake_3"), clicker, {type="nothing"})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_2",param2=param2})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_2",param2=0})
end,
sounds = default.node_sound_leaves_defaults(),
})
@ -134,7 +134,7 @@ minetest.register_node("mcl_cake:cake_2", {
drop = '',
on_rightclick = function(pos, node, clicker, itemstack)
minetest.do_item_eat(2, ItemStack("mcl_cake:cake_1"), ItemStack("mcl_cake:cake_2"), clicker, {type="nothing"})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_1",param2=param2})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_1",param2=0})
end,
sounds = default.node_sound_leaves_defaults(),
})

View File

@ -13,9 +13,7 @@ minetest.register_globalstep(function(dtime)
return false
end
if has_compass(player) then
local spawn = beds_player_spawns[player:get_player_name()] or
minetest.setting_get("static_spawnpoint") or
{x=0,y=0,z=0}
local spawn = minetest.setting_get("static_spawnpoint") or {x=0,y=0,z=0}
local pos = player:getpos()
local dir = player:get_look_horizontal()
local angle_north = math.deg(math.atan2(spawn.x - pos.x, spawn.z - pos.z))

View File

@ -2,7 +2,7 @@ mcl_minecarts = {}
mcl_minecarts.modpath = minetest.get_modpath("mcl_minecarts")
mcl_minecarts.speed_max = 10
function vector.floor(v)
local vector_floor = function(v)
return {
x = math.floor(v.x),
y = math.floor(v.y),
@ -52,7 +52,7 @@ end
function mcl_minecarts.cart:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
local pos = self.object:getpos()
if not self._railtype then
local node = minetest.get_node(vector.floor(pos)).name
local node = minetest.get_node(vector_floor(pos)).name
self._railtype = minetest.get_item_group(node, "connect_to_raillike")
end
@ -120,8 +120,8 @@ function mcl_minecarts.cart:on_step(dtime)
local dir, last_switch = nil, nil
local pos = self.object:getpos()
if self._old_pos and not self._punched then
local flo_pos = vector.floor(pos)
local flo_old = vector.floor(self._old_pos)
local flo_pos = vector_floor(pos)
local flo_old = vector_floor(self._old_pos)
if vector.equals(flo_pos, flo_old) then
return
end

View File

@ -2,7 +2,7 @@
dofile(minetest.get_modpath("mcl_throwing").."/arrow.lua")
dofile(minetest.get_modpath("mcl_throwing").."/throwable.lua")
arrows = {
local arrows = {
{"mcl_throwing:arrow", "mcl_throwing:arrow_entity"},
}
@ -34,7 +34,7 @@ minetest.register_tool("mcl_throwing:bow", {
inventory_image = "mcl_throwing_bow.png",
stack_max = 1,
on_place = function(itemstack, placer, pointed_thing)
wear = itemstack:get_wear()
local wear = itemstack:get_wear()
itemstack:replace("mcl_throwing:bow_0")
itemstack:add_wear(wear)
return itemstack
@ -58,13 +58,13 @@ minetest.register_tool("mcl_throwing:bow_0", {
stack_max = 1,
groups = {not_in_creative_inventory=1},
on_place = function(itemstack, placer, pointed_thing)
wear = itemstack:get_wear()
local wear = itemstack:get_wear()
itemstack:replace("mcl_throwing:bow_1")
itemstack:add_wear(wear)
return itemstack
end,
on_use = function(itemstack, user, pointed_thing)
wear = itemstack:get_wear()
local wear = itemstack:get_wear()
itemstack:add_wear(wear)
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
if not minetest.setting_getbool("creative_mode") then
@ -81,13 +81,13 @@ minetest.register_tool("mcl_throwing:bow_1", {
stack_max = 1,
groups = {not_in_creative_inventory=1},
on_place = function(itemstack, placer, pointed_thing)
wear = itemstack:get_wear()
local wear = itemstack:get_wear()
itemstack:replace("mcl_throwing:bow_2")
itemstack:add_wear(wear)
return itemstack
end,
on_use = function(itemstack, user, pointed_thing)
wear = itemstack:get_wear()
local wear = itemstack:get_wear()
itemstack:add_wear(wear)
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
if not minetest.setting_getbool("creative_mode") then
@ -104,7 +104,7 @@ minetest.register_tool("mcl_throwing:bow_2", {
stack_max = 1,
groups = {not_in_creative_inventory=1},
on_use = function(itemstack, user, pointed_thing)
wear = itemstack:get_wear()
local wear = itemstack:get_wear()
itemstack:replace("mcl_throwing:bow")
itemstack:add_wear(wear)
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then

View File

@ -68,7 +68,7 @@ local atan = function(x)
end
end
do_attack = function(self, player)
local do_attack = function(self, player)
if self.state ~= "attack" then
@ -86,7 +86,7 @@ do_attack = function(self, player)
end
end
set_velocity = function(self, v)
local set_velocity = function(self, v)
local yaw = self.object:getyaw() + self.rotate or 0
@ -97,14 +97,14 @@ set_velocity = function(self, v)
})
end
get_velocity = function(self)
local get_velocity = function(self)
local v = self.object:getvelocity()
return (v.x * v.x + v.z * v.z) ^ 0.5
end
set_animation = function(self, type)
local set_animation = function(self, type)
if not self.animation then
return
@ -199,7 +199,7 @@ set_animation = function(self, type)
end
-- check line of sight for walkers and swimmers alike
function line_of_sight_water(self, pos1, pos2, stepsize)
local function line_of_sight_water(self, pos1, pos2, stepsize)
local s, pos_w = minetest.line_of_sight(pos1, pos2, stepsize)
@ -238,7 +238,7 @@ function line_of_sight_water(self, pos1, pos2, stepsize)
end
-- particle effects
function effect(pos, amount, texture, min_size, max_size, radius, gravity)
local function effect(pos, amount, texture, min_size, max_size, radius, gravity)
radius = radius or 2
min_size = min_size or 0.5
@ -263,7 +263,7 @@ function effect(pos, amount, texture, min_size, max_size, radius, gravity)
end
-- check if mob is dead or only hurt
function check_for_death(self)
local function check_for_death(self)
-- has health actually changed?
if self.health == self.old_health then
@ -350,7 +350,7 @@ function check_for_death(self)
end
-- check if within physical map limits (-30911 to 30927)
function within_limits(pos, radius)
local function within_limits(pos, radius)
if (pos.x - radius) > -30913
and (pos.x + radius) < 30928
@ -407,7 +407,7 @@ local function node_ok(pos, fallback)
end
-- environmental damage (water, lava, fire, light)
do_env_damage = function(self)
local do_env_damage = function(self)
-- feed/tame text timer (so mob 'full' messages dont spam chat)
if self.htimer > 0 then
@ -480,7 +480,7 @@ do_env_damage = function(self)
end
-- jump if facing a solid node (not fences or gates)
do_jump = function(self)
local do_jump = function(self)
if self.fly
or self.child then
@ -550,7 +550,7 @@ local get_distance = function(a, b)
end
-- blast damage to entities nearby (modified from TNT mod)
function entity_physics(pos, radius)
local function entity_physics(pos, radius)
radius = radius * 2
@ -582,7 +582,7 @@ function entity_physics(pos, radius)
end
-- should mob follow what I'm holding ?
function follow_holding(self, clicker)
local function follow_holding(self, clicker)
if mobs.invis[clicker:get_player_name()] then
return false
@ -745,7 +745,7 @@ local function breed(self)
end
-- find and replace what mob is looking for (grass, wheat etc.)
function replace(self, pos)
local function replace(self, pos)
if self.replace_rate
and self.child == false
@ -774,7 +774,7 @@ function replace(self, pos)
end
-- check if daytime and also if mob is docile during daylight hours
function day_docile(self)
local function day_docile(self)
if self.docile_by_day == false then
@ -789,7 +789,7 @@ function day_docile(self)
end
-- path finding and smart mob routine by rnd
function smart_mobs(self, s, p, dist, dtime)
local function smart_mobs(self, s, p, dist, dtime)
local s1 = self.path.lastpos
@ -1057,9 +1057,9 @@ local npc_attack = function(self)
if obj
and obj.type == "monster" then
p = obj.object:getpos()
local p = obj.object:getpos()
dist = get_distance(p, s)
local dist = get_distance(p, s)
if dist < min_dist then
min_dist = dist

View File

@ -1,872 +0,0 @@
mobs = {}
mobs.default_definition = {
physical = true,
jump = function (self)
local v = self.object:getvelocity()
v.y = 5
self.object:setvelocity(v)
end,
timer = 0,
env_damage_timer = 0, -- only if state = "attack"
bombtimer = -999,
attack = {player=nil, dist=nil},
state = "stand",
v_start = false,
old_y = nil,
lifetimer = 600,
tamed = false,
boom = function(self, tnt_range)
local pos = self.object:getpos()
self.object:remove()
tnt:boom(pos)
end,
set_velocity = function(self, v)
local get_flowing_dir = function(self)
local pos = self.object:getpos()
local param2 = minetest.get_node(pos).param2
local p4 = {
{x=1,y=0,z=0},
{x=-1,y=0,z=0},
{x=0,y=0,z=1},
{x=0,y=0,z=-1},
}
local out = {x=0,y=0,z=0}
local num = 0
for i=1,4 do
local p2 = vector.add(pos, p4[i])
local name = minetest.get_node(p2).name
local par2 = minetest.get_node(p2).param2
-- param2 == 13 means water is falling down a block
if (name == "default:water_flowing" and par2 < param2 and param2 < 13) or (name == "default:water_flowing" and par2 == 13) or name == "air" then
out = vector.add(out, p4[i])
num = num + 1
end
end
if num then
return out
else
return false
end
end
local yaw = self.object:getyaw()
if self.drawtype == "side" then
yaw = yaw+(math.pi/2)
end
local x = math.sin(yaw) * -v
local z = math.cos(yaw) * v
local v1 = {x=x, y=self.object:getvelocity().y, z=z}
local pos = self.object:getpos()
local name = minetest.get_node(pos).name
if name == "default:water_flowing" then
local v = get_flowing_dir(self)
if v then
v1 = vector.add(v1, vector.multiply(v, 1.3))
end
end
self.object:setvelocity(v1)
end,
get_velocity = function(self)
local v = self.object:getvelocity()
return (v.x^2 + v.z^2)^(0.5)
end,
set_animation = function(self, type)
if not self.animation then
return
end
if not self.animation.current then
self.animation.current = ""
end
if type == "stand" and self.animation.current ~= "stand" then
if
self.animation.stand_start
and self.animation.stand_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.stand_start,y=self.animation.stand_end},
self.animation.speed_normal, 0
)
self.animation.current = "stand"
end
elseif type == "look" and self.animation.current ~= "look" then
if
self.animation.look_start
and self.animation.look_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.look_start,y=self.animation.look_end},
self.animation.speed_normal, 0
)
self.animation.current = "look"
end
elseif type == "eat" and self.animation.current ~= "eat" then
if
self.animation.eat_start
and self.animation.eat_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.eat_start,y=self.animation.eat_end},
self.animation.speed_normal, 0
)
self.animation.current = "eat"
if self.name == "mobs:sheep" and self.naked then
local pos = self.object:getpos()
pos.y = pos.y - 1
if minetest.get_node(pos).name == "default:dirt_with_grass" then
minetest.set_node(pos, {name = "default:dirt"})
self.naked = false
if not self.color then
self.object:set_properties({
textures = {"sheep.png"},
})
else
self.object:set_properties({
textures = {"sheep_"..self.color..".png"},
})
end
end
end
end
elseif type == "shoot" and self.animation.current ~= "shoot" then
if
self.animation.shoot_start
and self.animation.shoot_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.shoot_start,y=self.animation.shoot_end},
self.animation.speed_normal, 0
)
self.animation.shootdur = (self.animation.shoot_end - self.animation.shoot_start)/self.animation.speed_normal - .5
self.animation.current = "shoot"
end
elseif type == "fly" and self.animation.current ~= "fly" then
if
self.animation.fly_start
and self.animation.fly_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.fly_start,y=self.animation.fly_end},
self.animation.speed_normal, 0
)
self.animation.current = "fly"
end
elseif type == "walk" and self.animation.current ~= "walk" then
if
self.animation.walk_start
and self.animation.walk_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.walk_start,y=self.animation.walk_end},
self.animation.speed_normal, 0
)
self.animation.current = "walk"
end
elseif type == "run" and self.animation.current ~= "run" then
if
self.animation.run_start
and self.animation.run_end
and self.animation.speed_run
then
self.object:set_animation(
{x=self.animation.run_start,y=self.animation.run_end},
self.animation.speed_run, 0
)
self.animation.current = "run"
end
elseif type == "punch" and self.animation.current ~= "punch" then
if
self.animation.punch_start
and self.animation.punch_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.punch_start,y=self.animation.punch_end},
self.animation.speed_normal, 0
)
self.animation.current = "punch"
end
elseif type == "hurt" and self.animation.current ~= "hurt" then
self.animation.hurtdur = .5
if
self.animation.hurt_start
and self.animation.hurt_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.hurt_start,y=self.animation.hurt_end},
self.animation.speed_normal, 0
)
self.animation.current = "hurt"
self.animation.hurtdur = (self.animation.hurt_end - self.animation.hurt_start)/self.animation.speed_normal - 1
end
elseif type == "death" and self.animation.current ~= "death" then
self.animation.deathdur = 1
if
self.animation.death_start
and self.animation.death_end
and self.animation.speed_normal
then
self.object:set_animation(
{x=self.animation.death_start,y=self.animation.death_end},
self.animation.speed_normal, 0
)
self.animation.current = "death"
self.animation.deathdur = (self.animation.death_end - self.animation.death_start)/self.animation.speed_normal - .5
end
end
end,
on_step = function(self, dtime)
if self.type == "monster" and minetest.setting_getbool("only_peaceful_mobs") then
self.object:remove()
end
self.lifetimer = self.lifetimer - dtime
if self.lifetimer <= 0 and not self.tamed then
local player_count = 0
for _,obj in ipairs(minetest.get_objects_inside_radius(self.object:getpos(), 30)) do
if obj:is_player() then
player_count = player_count+1
end
end
if player_count == 0 and self.state ~= "attack" then
self.object:remove()
return
end
end
if self.object:getvelocity().y > 0.1 then
local yaw = self.object:getyaw()
if self.drawtype == "side" then
yaw = yaw+(math.pi/2)
end
local x = math.sin(yaw) * -2
local z = math.cos(yaw) * 2
self.object:setacceleration({x=x, y=-10, z=z})
else
self.object:setacceleration({x=0, y=-10, z=0})
end
if self.disable_fall_damage and self.object:getvelocity().y == 0 then
if not self.old_y then
self.old_y = self.object:getpos().y
else
local d = self.old_y - self.object:getpos().y
if d > 5 then
local damage = d-5
self.object:set_hp(self.object:get_hp()-damage)
if self.object:get_hp() == 0 then
self.object:remove()
end
end
self.old_y = self.object:getpos().y
end
end
self.timer = self.timer+dtime
self.bombtimer = self.bombtimer+dtime
if self.state ~= "attack" then
if self.timer < 1 then
return
end
self.timer = 0
end
if self.sounds and self.sounds.random and math.random(1, 100) <= 1 then
minetest.sound_play(self.sounds.random, {object = self.object})
end
local do_env_damage = function(self)
local pos = self.object:getpos()
local n = minetest.get_node(pos)
if self.light_damage and self.light_damage ~= 0
and pos.y>0
and minetest.get_node_light(pos)
and minetest.get_node_light(pos) > 4
and minetest.get_timeofday() > 0.2
and minetest.get_timeofday() < 0.8
then
self.object:set_hp(self.object:get_hp()-self.light_damage)
if self.object:get_hp() == 0 then
self.object:remove()
end
end
if self.water_damage and self.water_damage ~= 0 and
minetest.get_item_group(n.name, "water") ~= 0
then
self.object:set_hp(self.object:get_hp()-self.water_damage)
if self.object:get_hp() == 0 then
self.object:remove()
end
end
if self.lava_damage and self.lava_damage ~= 0 and
minetest.get_item_group(n.name, "lava") ~= 0
then
self.object:set_hp(self.object:get_hp()-self.lava_damage)
if self.object:get_hp() == 0 then
self.object:remove()
end
end
end
-- ridable pigs
if self.name == "mobs:pig" and self.saddle == "yes" and self.driver then
local item = self.driver:get_wielded_item()
if item:get_name() == "mobs:carrotstick" then
local yaw = self.driver:get_look_yaw() - math.pi / 2
local velo = self.object:getvelocity()
local v = 1.5
if math.abs(velo.x) + math.abs(velo.z) < .6 then velo.y = 5 end
self.state = "walk"
self:set_animation("walk")
self.object:setyaw(yaw)
self.object:setvelocity({x = -math.sin(yaw) * v, y = velo.y, z = math.cos(yaw) * v})
local inv = self.driver:get_inventory()
local stack = inv:get_stack("main", self.driver:get_wield_index())
stack:add_wear(100)
if stack:get_wear() > 65400 then
stack = {name = "fishing:pole", count = 1}
end
inv:set_stack("main", self.driver:get_wield_index(), stack)
return
end
end
self.env_damage_timer = self.env_damage_timer + dtime
if self.state == "attack" and self.env_damage_timer > 1 then
self.env_damage_timer = 0
do_env_damage(self)
elseif self.state ~= "attack" then
do_env_damage(self)
end
if self.type == "monster" and minetest.setting_getbool("enable_damage") then
for _,player in pairs(minetest.get_connected_players()) do
local s = self.object:getpos()
local p = player:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist < 2 and self.attack_type == "bomb" and self.bombmode ~= "armed" then
if self.sounds and self.sounds.approach then
minetest.sound_play(self.sounds.approach, {object = self.object})
end
self.bombmode = "armed"
self.bombtimer = 0
end
if dist < self.view_range then
if self.attack.dist then
if dist < self.attack.dist then
self.attack.player = player
self.attack.dist = dist
end
else
self.state = "attack"
self.attack.player = player
self.attack.dist = dist
end
end
end
end
if self.follow and self.follow ~= "" and not self.following then
for _,player in pairs(minetest.get_connected_players()) do
local s = self.object:getpos()
local p = player:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if self.view_range and dist < self.view_range then
self.following = player
end
end
end
if self.following and self.following:is_player() then
if self.following:get_wielded_item():get_name() ~= self.follow then
self.following = nil
self.v_start = false
else
local s = self.object:getpos()
local p = self.following:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist > self.view_range then
self.following = nil
self.v_start = false
else
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = math.atan(vec.z/vec.x)+math.pi/2
if self.drawtype == "side" then
yaw = yaw+(math.pi/2)
end
if p.x > s.x then
yaw = yaw+math.pi
end
self.object:setyaw(yaw)
if dist > 2 then
if not self.v_start then
self.v_start = true
self.set_velocity(self, self.walk_velocity)
else
if self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then
self:jump()
end
self.set_velocity(self, self.walk_velocity)
end
self:set_animation("walk")
else
self.v_start = false
self.set_velocity(self, 0)
self:set_animation("stand")
end
return
end
end
end
if self.state == "stand" then
if math.random(1, 4) == 1 then
self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/180*math.pi))
end
self.set_velocity(self, 0)
self.set_animation(self, "stand")
local standanim = math.random(1,4)
if standanim == 2 then
self.set_animation(self, "look")
elseif standanim == 3 then
self.set_animation(self, "eat")
elseif standanim == 4 then
self.set_animation(self, "fly")
end
if math.random(1, 100) <= 50 then
self.set_velocity(self, self.walk_velocity)
self.state = "walk"
self.set_animation(self, "walk")
end
elseif self.state == "walk" then
if math.random(1, 100) <= 30 then
self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/180*math.pi))
end
if self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then
self:jump()
end
self:set_animation("walk")
self.set_velocity(self, self.walk_velocity)
if math.random(1, 100) <= 10 then
self.set_velocity(self, 0)
self.state = "stand"
self:set_animation("stand")
end
elseif self.state == "attack" and (self.attack_type == "dogfight" or self.attack_type == "bomb") then
if not self.attack.player or not self.attack.player:is_player() then
self.state = "stand"
self:set_animation("stand")
self.attack = {player=nil, dist=nil}
return
end
local s = self.object:getpos()
local p = self.attack.player:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist > self.view_range or self.attack.player:get_hp() <= 0 then
self.state = "stand"
self.v_start = false
self.set_velocity(self, 0)
self.attack = {player=nil, dist=nil}
self:set_animation("stand")
return
else
self.attack.dist = dist
end
if self.attack_type == "bomb" and self.bombmode == "armed" and self.bombtimer > 2 then
-- print("***BOOM",self.bombtimer)
self.bombmode = "exploded"
self.boom(self, math.random(2, 4))
end
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = math.atan(vec.z/vec.x)+math.pi/2
if self.drawtype == "side" then
yaw = yaw+(math.pi/2)
end
if p.x > s.x then
yaw = yaw+math.pi
end
-- creepers use a spiraling approach:
if self.attack_type == "bomb" then
yaw = yaw - 14*math.pi/180
end
self.object:setyaw(yaw)
if self.attack.dist > 2 then
if not self.v_start then
self.v_start = true
self.set_velocity(self, self.run_velocity)
else
if self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then
self:jump()
end
self.set_velocity(self, self.run_velocity)
end
self:set_animation("run")
else
self.set_velocity(self, 0)
self:set_animation("punch")
self.v_start = false
if self.timer > 1 then
self.timer = 0
if self.sounds and self.sounds.attack then
minetest.sound_play(self.sounds.attack, {object = self.object})
end
self.attack.player:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups = {fleshy=self.damage}
}, vec)
end
end
elseif self.state == "attack" and self.attack_type == "shoot" then
if not self.attack.player or not self.attack.player:is_player() then
self.state = "stand"
self:set_animation("stand")
self.attack = {player=nil, dist=nil}
return
end
local s = self.object:getpos()
local p = self.attack.player:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist > self.view_range or self.attack.player:get_hp() <= 0 then
self.state = "stand"
self.v_start = false
self.set_velocity(self, 0)
self.attack = {player=nil, dist=nil}
self:set_animation("stand")
return
else
self.attack.dist = dist
self.shoot_interval = (dist + self.view_range) / self.view_range
end
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = math.atan(vec.z/vec.x)+math.pi/2
if self.drawtype == "side" then
yaw = yaw+(math.pi/2)
end
if p.x > s.x then
yaw = yaw+math.pi
end
self.object:setyaw(yaw)
if self.attack.dist < 4 then
self.set_velocity(self, -self.run_velocity)
elseif self.attack.dist > 8 then
self.set_velocity(self, self.run_velocity)
else
self.set_velocity(self, 0)
end
if self.timer > self.shoot_interval and math.random(1, 100) <= 60 then
self.timer = 0
self:set_animation("shoot")
minetest.after(self.animation.shootdur, function()
self:set_animation("walk")
end)
if self.sounds and self.sounds.attack then
minetest.sound_play(self.sounds.attack, {object = self.object})
end
local p = self.object:getpos()
p.y = p.y + (self.collisionbox[2]+self.collisionbox[5])/2
local obj = minetest.add_entity(p, self.arrow)
local amount = (vec.x^2+vec.y^2+vec.z^2)^0.5
local v = 15
vec.y = vec.y+1
vec.x = vec.x*v/amount
vec.y = vec.y*v/amount
vec.z = vec.z*v/amount
obj:setvelocity(vec)
end
end
end,
on_activate = function(self, staticdata, dtime_s)
self.object:set_armor_groups({fleshy=self.armor})
self.object:setacceleration({x=0, y=-10, z=0})
self.state = "stand"
self.attack = {player = nil, dist = nil}
self.object:setvelocity({x=0, y=self.object:getvelocity().y, z=0})
self.object:setyaw(math.random(1, 360)/180*math.pi)
if self.type == "monster" and minetest.setting_getbool("only_peaceful_mobs") then
self.object:remove()
end
self.lifetimer = 600 - dtime_s
if staticdata then
local tmp = minetest.deserialize(staticdata)
if tmp and tmp.lifetimer then
self.lifetimer = tmp.lifetimer - dtime_s
end
if tmp and tmp.tamed then
self.tamed = tmp.tamed
end
if tmp and tmp.color then
self.color = tmp.color
end
if tmp and tmp.naked then
self.naked = tmp.naked
end
if tmp and tmp.saddle then
self.saddle = tmp.saddle
end
end
if self.name == "mobs:sheep" and self.color and not self.naked then
self.object:set_properties({
textures = {"sheep_"..self.color..".png"},
})
self.drops = {
{name = "mobs:mutton_raw",
chance = 1,
min = 1,
max = 2,},
{name = "wool:"..self.color,
chance = 1,
min = 1,
max = 1,},
}
end
if self.name == "mobs:sheep" and not self.color then
local col = "white"
local cols = {"dark_grey", "grey", "black", "brown", "pink"}
if math.random(100) > 80 then
col = cols[math.random(1,5)]
end
self.color = col
self.object:set_properties({
textures = {"sheep_"..self.color..".png"},
})
self.drops = {
{name = "mobs:mutton_raw",
chance = 1,
min = 1,
max = 2,},
{name = "wool:"..self.color,
chance = 1,
min = 1,
max = 1,},
}
end
if self.name == "mobs:sheep" and self.naked then
self.object:set_properties({
textures = {"sheep_sheared.png"},
})
end
if self.name == "mobs:pig" and self.saddle == "yes" then
self.object:set_properties({
textures = {"pig_with_saddle.png"},
})
end
if self.lifetimer <= 0 and not self.tamed then
self.object:remove()
end
end,
get_staticdata = function(self)
local tmp = {
lifetimer = self.lifetimer,
tamed = self.tamed,
color = self.color,
naked = self.naked,
saddle = self.saddle,
}
return minetest.serialize(tmp)
end,
on_punch = function(self, hitter)
-- death happens at 20 hp so we can play the death animation:
if self.object:get_hp() <= 20 then
local pos = self.object:getpos()
minetest.add_particlespawner({
amount = 20,
time = .2,
minpos = {x=pos.x-1, y=pos.y-.5, z=pos.z-1},
maxpos = {x=pos.x+1, y=pos.y+.5, z=pos.z+1},
minvel = {x=0, y=.3, z=0},
maxvel = {x=0, y=2, z=0},
minacc = {x=-.2, y=-.2, z=-.2},
maxacc = {x=.2, y=.2, z=.2},
minexptime = 1,
maxexptime = 5,
minsize = 1,
maxsize = 1,
collisiondetection = false,
vertical = false,
texture = "bettertnt_smoke.png",
})
self:set_animation("death")
self.object:set_hp(1000)
if self.name == "mobs:pig" and self.driver then
local name = self.driver:get_player_name()
self.driver:set_detach()
default.player_attached[name] = false
default.player_set_animation(self.driver, "stand" , 30)
self.driver = nil
end
minetest.after(self.animation.deathdur, function()
self.object:remove()
end)
if self.sounds and self.sounds.death then
minetest.sound_play(self.sounds.death, {object = self.object})
end
pos.y = pos.y + 0.5
local obj = nil
local ndrops = 0
for _,drop in ipairs(self.drops) do
if math.random(1, drop.chance) == 1 and ndrops < (self.maxdrops or 100) then
obj = minetest.add_item(pos, ItemStack(drop.name.." "..math.random(drop.min, drop.max)))
ndrops = ndrops + 1
if obj then
obj:setvelocity({x=math.random(-1,1), y=5, z=math.random(-1,1)})
end
end
end
else
if self.sounds and self.sounds.hurt then
minetest.sound_play(self.sounds.hurt, {object = self.object})
end
self:set_animation("hurt")
minetest.after(self.animation.hurtdur, function()
self:set_animation("walk")
end)
end
end,
__index = function(table,key)
return mobs.default_definition[key]
end,}
function mobs:register_mob(name, def)
setmetatable (def,mobs.default_definition)
minetest.register_entity(name, def)
end
function mobs:check_player_dist(pos, node)
for _,player in pairs(minetest.get_connected_players()) do
local p = player:getpos()
local dist = ((p.x-pos.x)^2 + (p.y-pos.y)^2 + (p.z-pos.z)^2)^0.5
if dist < 24 then
return 1
end
end
return nil
end
mobs.spawning_mobs = {}
function mobs:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height, spawn_func)
if minetest.setting_getbool(string.gsub(name,":","_").."_spawn") ~= false then
mobs.spawning_mobs[name] = true
minetest.register_abm({
nodenames = nodes,
neighbors = {"air"},
interval = 10,
chance = chance,
action = function(pos, node, _, active_object_count_wider)
if node.name == "default:ice" or node.name == "default:glass" then
return
end
if active_object_count_wider > active_object_count then
return
end
if not mobs.spawning_mobs[name] then
return
end
pos.y = pos.y+1
if not minetest.get_node_light(pos) then
return
end
if minetest.get_node_light(pos) > max_light then
return
end
if minetest.get_node_light(pos) < min_light then
return
end
if pos.y > max_height then
return
end
if minetest.get_node(pos).name ~= "air" then
return
end
pos.y = pos.y+1
if minetest.get_node(pos).name ~= "air" then
return
end
if spawn_func and not spawn_func(pos, node) then
return
end
if mobs:check_player_dist(pos, node) then
return
end
if minetest.setting_getbool("display_mob_spawn") then
minetest.chat_send_all("[mobs] Add "..name.." at "..minetest.pos_to_string(pos))
end
minetest.add_entity(pos, name)
end
})
end
end
function mobs:register_arrow(name, def)
minetest.register_entity(name, {
physical = false,
visual = def.visual,
visual_size = def.visual_size,
textures = def.textures,
velocity = def.velocity,
hit_player = def.hit_player,
hit_node = def.hit_node,
on_step = function(self, dtime)
local pos = self.object:getpos()
if minetest.get_node(self.object:getpos()).name ~= "air" then
minetest.sound_play("bowhit1", {pos = pos})
self.hit_node(self, pos, node)
self.object:remove()
return
end
pos.y = pos.y-1
for _,player in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if player:is_player() then
self.hit_player(self, player)
minetest.sound_play("damage", {pos = pos})
self.object:remove()
return
end
end
end
})
end
function mobs:register_egg(mob, desc, img)
minetest.register_craftitem(mob, {
description = "Spawn "..desc,
inventory_image = img,
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
if pointed_thing.above and not minetest.is_protected(pos, placer:get_player_name()) then
pos.y = pos.y + 0.5
minetest.add_entity(pos, mob)
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
end
return itemstack
end,
})
end

File diff suppressed because it is too large Load Diff

View File

@ -39,7 +39,7 @@ local function get_v(v)
return math.sqrt(v.x^2+v.z^2)
end
function merge(a, b)
local function merge(a, b)
if type(a) == 'table' and type(b) == 'table' then
for k,v in pairs(b) do if type(v)=='table' and type(a[k] or false)=='table' then merge(a[k],v) else a[k]=v end end
end

View File

@ -139,7 +139,7 @@ mobs:register_mob("mobs_mc:skeleton2", {
mobs:register_spawn("mobs_mc:skeleton2", {"group:crumbly", "group:cracky", "group:choppy", "group:snappy"}, 7, -1, 5000, 4, -3000)
arrows = {
local arrows = {
{"mcl_throwing:arrow", "mcl_throwing:arrow_entity" },
}

View File

@ -118,11 +118,9 @@ mobs:register_mob("mobs_mc:greenmedium", {
jump_chance = 100,
fear_height = 60,
on_die =function(self, pos)
lavasmall = minetest.add_entity(self.object:getpos(), "mobs_mc:greensmall")
lavasmall = minetest.add_entity(self.object:getpos(), "mobs_mc:greensmall")
lavasmall = minetest.add_entity(self.object:getpos(), "mobs_mc:greensmall")
lavasmall = minetest.add_entity(self.object:getpos(), "mobs_mc:greensmall")
ent = lavasmall:get_luaentity()
for i=1,4 do
minetest.add_entity(self.object:getpos(), "mobs_mc:greensmall")
end
end
})
@ -178,11 +176,11 @@ mobs:register_mob("mobs_mc:greenbig", {
jump_height = 8,
jump_chance = 100,
fear_height = 60,
on_die =function(self, pos)
lavasmall = minetest.add_entity(self.object:getpos(), "mobs_mc:greenmedium")
lavasmall = minetest.add_entity(self.object:getpos(), "mobs_mc:greenmedium")
ent = lavasmall:get_luaentity()
on_die = function(self, pos)
for i=1,2 do
minetest.add_entity(self.object:getpos(), "mobs_mc:greenmedium")
end
end,
})
mobs:register_spawn("mobs_mc:greensmall", {"default:flowing_water", "default:mossycobble"}, 7, -1, 5000, 4, 31000)
mobs:register_spawn("mobs_mc:greenmedium", {"default:flowing_water", "default:mossycobble"}, 7, -1, 5000, 4, 31000)
@ -302,12 +300,10 @@ mobs:register_mob("mobs_mc:lavabig", {
jump_height = 8,
jump_chance = 100,
fear_height = 60,
on_die =function(self, pos)
lavasmall = minetest.add_entity(self.object:getpos(), "mobs_mc:lavasmall")
lavasmall = minetest.add_entity(self.object:getpos(), "mobs_mc:lavasmall")
lavasmall = minetest.add_entity(self.object:getpos(), "mobs_mc:lavasmall")
lavasmall = minetest.add_entity(self.object:getpos(), "mobs_mc:lavasmall")
ent = lavasmall:get_luaentity()
on_die = function(self, pos)
for i=1,4 do
minetest.add_entity(self.object:getpos(), "mobs_mc:lavasmall")
end
end
})

View File

@ -142,7 +142,7 @@ mobs:register_mob("mobs_mc:wolf", {
lava_damage = 5,
light_damage = 0,
on_rightclick = function(self, clicker)
tool = clicker:get_wielded_item()
local tool = clicker:get_wielded_item()
local dog
local ent
if tool:get_name() == "mcl_mobitems:meat_raw" then

View File

@ -18,6 +18,111 @@ else
end
end
-- CONSTANTS
local SIGN_WITH = 110
local SIGN_PADDING = 8
local LINE_LENGTH = 16
local NUMBER_OF_LINES = 4
local LINE_HEIGHT = 14
local CHAR_WIDTH = 5
local string_to_array = function(str)
local tab = {}
for i=1,string.len(str) do
table.insert(tab, string.sub(str, i,i))
end
return tab
end
local string_to_word_array = function(str)
local tab = {}
local current = 1
tab[1] = ""
for _,char in ipairs(string_to_array(str)) do
if char ~= " " then
tab[current] = tab[current]..char
else
current = current+1
tab[current] = ""
end
end
return tab
end
local create_lines = function(text)
local line = ""
local line_num = 1
local tab = {}
for _,word in ipairs(string_to_word_array(text)) do
if string.len(line)+string.len(word) < LINE_LENGTH and word ~= "|" then
if line ~= "" then
line = line.." "..word
else
line = word
end
else
table.insert(tab, line)
if word ~= "|" then
line = word
else
line = ""
end
line_num = line_num+1
if line_num > NUMBER_OF_LINES then
return tab
end
end
end
table.insert(tab, line)
return tab
end
local generate_line = function(s, ypos)
local i = 1
local parsed = {}
local width = 0
local chars = 0
while chars < max_chars and i <= #s do
local file = nil
if charmap[s:sub(i, i)] ~= nil then
file = charmap[s:sub(i, i)]
i = i + 1
elseif i < #s and charmap[s:sub(i, i + 1)] ~= nil then
file = charmap[s:sub(i, i + 1)]
i = i + 2
else
print("[signs] W: unknown symbol in '"..s.."' at "..i.." (probably "..s:sub(i, i)..")")
i = i + 1
end
if file ~= nil then
width = width + CHAR_WIDTH
table.insert(parsed, file)
chars = chars + 1
end
end
width = width - 1
local texture = ""
local xpos = math.floor((SIGN_WITH - 2 * SIGN_PADDING - width) / 2 + SIGN_PADDING)
for i = 1, #parsed do
texture = texture..":"..xpos..","..ypos.."="..parsed[i]..".png"
xpos = xpos + CHAR_WIDTH + 1
end
return texture
end
local generate_texture = function(lines)
local texture = "[combine:"..SIGN_WITH.."x"..SIGN_WITH
local ypos = 12
for i = 1, #lines do
texture = texture..generate_line(lines[i], ypos)
ypos = ypos + LINE_HEIGHT
end
return texture
end
local signs = {
{delta = {x = 0, y = 0, z = 0.399}, yaw = 0},
{delta = {x = 0.399, y = 0, z = 0}, yaw = math.pi / -2},
@ -197,111 +302,6 @@ minetest.register_entity("signs:text", {
end
})
-- CONSTANTS
local SIGN_WITH = 110
local SIGN_PADDING = 8
local LINE_LENGTH = 16
local NUMBER_OF_LINES = 4
local LINE_HEIGHT = 14
local CHAR_WIDTH = 5
string_to_array = function(str)
local tab = {}
for i=1,string.len(str) do
table.insert(tab, string.sub(str, i,i))
end
return tab
end
string_to_word_array = function(str)
local tab = {}
local current = 1
tab[1] = ""
for _,char in ipairs(string_to_array(str)) do
if char ~= " " then
tab[current] = tab[current]..char
else
current = current+1
tab[current] = ""
end
end
return tab
end
create_lines = function(text)
local line = ""
local line_num = 1
local tab = {}
for _,word in ipairs(string_to_word_array(text)) do
if string.len(line)+string.len(word) < LINE_LENGTH and word ~= "|" then
if line ~= "" then
line = line.." "..word
else
line = word
end
else
table.insert(tab, line)
if word ~= "|" then
line = word
else
line = ""
end
line_num = line_num+1
if line_num > NUMBER_OF_LINES then
return tab
end
end
end
table.insert(tab, line)
return tab
end
generate_texture = function(lines)
local texture = "[combine:"..SIGN_WITH.."x"..SIGN_WITH
local ypos = 12
for i = 1, #lines do
texture = texture..generate_line(lines[i], ypos)
ypos = ypos + LINE_HEIGHT
end
return texture
end
generate_line = function(s, ypos)
local i = 1
local parsed = {}
local width = 0
local chars = 0
while chars < max_chars and i <= #s do
local file = nil
if charmap[s:sub(i, i)] ~= nil then
file = charmap[s:sub(i, i)]
i = i + 1
elseif i < #s and charmap[s:sub(i, i + 1)] ~= nil then
file = charmap[s:sub(i, i + 1)]
i = i + 2
else
print("[signs] W: unknown symbol in '"..s.."' at "..i.." (probably "..s:sub(i, i)..")")
i = i + 1
end
if file ~= nil then
width = width + CHAR_WIDTH
table.insert(parsed, file)
chars = chars + 1
end
end
width = width - 1
local texture = ""
local xpos = math.floor((SIGN_WITH - 2 * SIGN_PADDING - width) / 2 + SIGN_PADDING)
for i = 1, #parsed do
texture = texture..":"..xpos..","..ypos.."="..parsed[i]..".png"
xpos = xpos + CHAR_WIDTH + 1
end
return texture
end
if minetest.setting_get("log_mods") then
minetest.log("action", "signs loaded")
end

View File

@ -1,4 +1,4 @@
player_running_physics = {}
local player_running_physics = {}
minetest.register_globalstep(function(dtime)
for _,player in ipairs(minetest.get_connected_players()) do
--local pos = player:getpos()

View File

@ -53,7 +53,7 @@ local function update_wall(pos)
minetest.add_node(pos, {name = basename..sum})
end
function update_wall_global(pos)
local function update_wall_global(pos)
for i = 1,5 do
local dir = directions[i]
update_wall({x = pos.x + dir.x, y = pos.y + dir.y, z = pos.z + dir.z})