new line_of_sight and fence_top added

master
TenPlus1 2018-07-18 10:13:19 +01:00
parent f6b5effe09
commit 63c9812dad
4 changed files with 47 additions and 32 deletions

39
api.lua
View File

@ -3,7 +3,7 @@
mobs = {}
mobs.mod = "redo"
mobs.version = "20180708"
mobs.version = "20180710"
-- Intllib
@ -213,17 +213,17 @@ local get_distance = function(a, b)
end
-- check line of sight (BrunoMine)
-- check line of sight (by BrunoMine, tweaked by Astrobe)
local line_of_sight = function(self, pos1, pos2, stepsize)
stepsize = stepsize or 1
local stepv = vector.multiply(vector.direction(pos1, pos2), stepsize)
local s, pos = minetest.line_of_sight(pos1, pos2, stepsize)
-- normal walking and flying mobs can see you through air
if s == true then
return true
end
if s == true then return true end
-- New pos1 to be analyzed
local npos1 = {x = pos1.x, y = pos1.y, z = pos1.z}
@ -236,39 +236,15 @@ local line_of_sight = function(self, pos1, pos2, stepsize)
-- Nodename found
local nn = minetest.get_node(pos).name
-- Target Distance (td) to travel
local td = get_distance(pos1, pos2)
-- Actual Distance (ad) traveled
local ad = 0
-- It continues to advance in the line of sight in search of a real
-- obstruction which counts as 'normal' nodebox.
while minetest.registered_nodes[nn]
and (minetest.registered_nodes[nn].walkable == false
or minetest.registered_nodes[nn].drawtype == "nodebox") do
-- Check if you can still move forward
if td < ad + stepsize then
return true -- Reached the target
end
npos1 = vector.add(npos1, stepv)
-- Moves the analyzed pos
local d = get_distance(pos1, pos2)
npos1.x = ((pos2.x - pos1.x) / d * stepsize) + pos1.x
npos1.y = ((pos2.y - pos1.y) / d * stepsize) + pos1.y
npos1.z = ((pos2.z - pos1.z) / d * stepsize) + pos1.z
-- NaN checks
if d == 0
or npos1.x ~= npos1.x
or npos1.y ~= npos1.y
or npos1.z ~= npos1.z then
return false
end
ad = ad + stepsize
if get_distance(npos1, pos2) < stepsize then return true end
-- scan again
r, pos = minetest.line_of_sight(npos1, pos2, stepsize)
@ -277,7 +253,6 @@ local line_of_sight = function(self, pos1, pos2, stepsize)
-- New Nodename found
nn = minetest.get_node(pos).name
end
return false

View File

@ -146,6 +146,37 @@ default.register_fence("mobs:fence_wood", {
},
})
-- mob fence top (has enlarged collisionbox to stop mobs getting over)
minetest.register_node("mobs:fence_top", {
description = S("Mob Fence Top"),
drawtype = "nodebox",
tiles = {"default_wood.png"},
paramtype = "light",
is_ground_content = false,
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2},
},
collision_box = {
type = "fixed",
fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4},
},
selection_box = {
type = "fixed",
fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4},
},
})
minetest.register_craft({
output = "mobs:fence_top 12",
recipe = {
{"group:wood", "group:wood", "group:wood"},
{"", "default:fence_wood", ""},
}
})
-- items that can be used as fuel
minetest.register_craft({
type = "fuel",
@ -182,3 +213,9 @@ minetest.register_craft({
recipe = "mobs:fence_wood",
burntime = 7,
})
minetest.register_craft({
type = "fuel",
recipe = "mobs:fence_top",
burntime = 2,
})

View File

@ -12,6 +12,7 @@ if minetest.get_modpath("lucky_block") then
{"dro", {"mobs:shears"}, 1},
{"dro", {"mobs:protector"}, 1},
{"dro", {"mobs:fence_wood"}, 10},
{"dro", {"mobs:fence_top"}, 12},
{"lig"},
})
end

View File

@ -17,11 +17,13 @@ Crafts:
- Magic Lasso is similar to nets but with a better chance of picking up larger mobs.
- Shears are used to right-click sheep and return 1-3 wool.
- Protection Rune lets you protect tamed mobs from harm by other players
- Mob Fence and Fence Top (to stop mobs escaping/glitching through fences)
Lucky Blocks: 9
Changelog:
- 1.45- Added Fence Top to add on top of any fence to stop mobs escaping, new line_of_sight tweaked by Astrobe
- 1.44- Added ToolRanks support for swords when attacking mobs
- 1.43- Better 0.4.16 compatibility, added general attack function and settings
- 1.42- Added "all" option to immune_to table, tidied floating mobs to be less intensive