Made Sticky API

Its all here, I made a big commit by mistake
This commit is contained in:
opfromthestart 2022-08-11 22:38:00 -04:00
parent 8ff938c3d0
commit 781fd38170
10 changed files with 478 additions and 70 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
*.blend1
*.blend2
*.blend3
.vscode/settings.json

View File

@ -45,3 +45,5 @@ dedicated_server_step = 0.05 #tick rate
enable_client_modding = true
csm_restriction_flags = 0
enable_mod_channels = true
more_slime = true

View File

@ -207,7 +207,7 @@ function mesecon.mvps_push(pos, dir, maximum, player_name, piston_pos)
end
function mesecon.mvps_pull_single(pos, dir, maximum, player_name, piston_pos)
local nodes = mesecon.mvps_get_stack(pos, dir, maximum, player_name, piston_pos)
local nodes = mesecon.mvps_get_stack(pos, dir, maximum, piston_pos)
if not nodes then return end
-- ensure sticky pistons; even without slimeblocks attached adhere to the unpullable rule.

View File

@ -8,8 +8,6 @@ if mod_screwdriver then
on_rotate = screwdriver.rotate_3way
end
local alldirs = {{x=0,y=0,z=1}, {x=1,y=0,z=0}, {x=0,y=0,z=-1}, {x=-1,y=0,z=0}, {x=0,y=-1,z=0}, {x=0,y=1,z=0}}
minetest.register_node("mcl_core:bone_block", {
description = S("Bone Block"),
_doc_items_longdesc = S("Bone blocks are decorative blocks and a compact storage of bone meal."),
@ -24,73 +22,6 @@ minetest.register_node("mcl_core:bone_block", {
_mcl_hardness = 2,
})
minetest.register_node("mcl_core:slimeblock", {
description = S("Slime Block"),
_doc_items_longdesc = S("Slime blocks are very bouncy and prevent fall damage."),
drawtype = "nodebox",
paramtype = "light",
is_ground_content = false,
node_box = {
type = "fixed",
fixed = {
{-0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
}
},
selection_box = {
type = "regular",
},
tiles = {"mcl_core_slime.png"},
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "blend" or true,
stack_max = 64,
-- According to Minecraft Wiki, bouncing off a slime block from a height off 255 blocks should result in a bounce height of 50 blocks
-- bouncy=44 makes the player bounce up to 49.6. This value was chosen by experiment.
-- bouncy=80 was chosen because it is higher than 66 (bounciness of bed)
groups = {dig_immediate=3, bouncy=80,fall_damage_add_percent=-100,deco_block=1},
sounds = {
dug = {name="slimenodes_dug", gain=0.6},
place = {name="slimenodes_place", gain=0.6},
footstep = {name="slimenodes_step", gain=0.3},
},
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
mvps_sticky = function(pos, node, piston_pos)
local connected = {}
for n, v in ipairs(alldirs) do
local neighbor_pos = vector.add(pos, v)
local neighbor_node = minetest.get_node(neighbor_pos)
if neighbor_node then
if neighbor_node.name == "ignore" then
minetest.get_voxel_manip():read_from_map(neighbor_pos, neighbor_pos)
neighbor_node = minetest.get_node(neighbor_pos)
end
local name = neighbor_node.name
if name ~= "air" and name ~= "ignore" and not mesecon.mvps_unsticky[name] then
local piston, piston_side, piston_up, piston_down = false, false, false, false
if name == "mesecons_pistons:piston_sticky_off" or name == "mesecons_pistons:piston_normal_off" then
piston, piston_side = true, true
elseif name == "mesecons_pistons:piston_up_sticky_off" or name == "mesecons_pistons:piston_up_normal_off" then
piston, piston_up = true, true
elseif name == "mesecons_pistons:piston_down_sticky_off" or name == "mesecons_pistons:piston_down_normal_off" then
piston, piston_down = true, true
end
if not( (piston_side and (n-1==neighbor_node.param2)) or (piston_up and (n==5)) or (piston_down and (n==6)) ) then
if piston and piston_pos then
if piston_pos.x == neighbor_pos.x and piston_pos.y == neighbor_pos.y and piston_pos.z == neighbor_pos.z then
-- Loopback to the same piston! Preventing unwanted behavior:
return {}, true
end
end
table.insert(connected, neighbor_pos)
end
end
end
end
return connected, false
end,
})
minetest.register_node("mcl_core:cobweb", {
description = S("Cobweb"),
_tt_help = S("Slows down movement"),

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -0,0 +1,70 @@
# API for `mcl_sticky`
Register your own sticky blocks or modify existing ones
## `add_empty(name)`
Adds a node that does not stick to any nodes
### Parameters
* `name`: Name of the node
## `add_stick(name1, name2)`
Makes node `name1` stick to node `name2`
### Parameters
* `name1`: Name of a node
* `name2`: Name of a node
## `add_stick_pull(name1, name2)`
Makes node `name1` stick to node `name2` when pulled(parallel)
### Parameters
* `name1`: Name of a node
* `name2`: Name of a node
## `add_stick_drag(name1, name2)`
Makes node name1 stick to node name2 when dragged(perpendicular)
### Parameters
* `name1`: Name of a node
* `name2`: Name of a node
## `remove_stick(name1, name2)`
Makes node `name1` not stick to node `name2`
### Parameters
* `name1`: Name of a node
* `name2`: Name of a node
## `remove_stick_pull(name1, name2)`
Makes node `name1` not stick to node `name2` when pulled(parallel)
### Parameters
* `name1`: Name of a node
* `name2`: Name of a node
## `remove_stick_drag(name1, name2)`
Makes node `name1` not stick to node `name2` when dragged(perpendicular)
### Parameters
* `name1`: Name of a node
* `name2`: Name of a node
## `sticks_to(node1, pos1, node2, pos2, push_vec)`
Checks if `node1` at `pos1` sticks to `node2` at `pos2` when being pushed in direction `push_vec` based on add and remove functions
### Parameters
* `node1`: First node
* `pos1`: Name of first node
* `node2`: Second node
* `pos2`: Name of second node
* `push_vec`: Direction the blocks are trying to be pushed
## `default_stick()`
Makes a function for `mvps_sticky` based on `sticks_to`
## `stick_with_cond(stick_cond)`
Makes a function for `mvps_sticky` that allows sticking only if `stick_cond`, which is like `sticks_to`
### Parameters
* `stick_cond`: Function that takes `(node1, pos1, node2, pos2, push_vec)`

View File

@ -0,0 +1,174 @@
local stick_map = {default = {{}, {}}}
local alldirs = {{x=0,y=0,z=1}, {x=1,y=0,z=0}, {x=0,y=0,z=-1}, {x=-1,y=0,z=0}, {x=0,y=-1,z=0}, {x=0,y=1,z=0}}
local function has_value(list, value)
for _, val in ipairs(list) do
if value == val then
return true
end
end
return false
end
local function remove_value(list, value)
local to_rem = {}
for id, val in ipairs(list) do
if val == value then
table.insert(to_rem, id)
end
end
for id, val in ipairs(to_rem) do
table.remove(list, val)
end
end
local function is_pull(pos1, pos2, push_vec)
return vector.equals(vector.subtract(pos1, pos2), push_vec)
end
local function is_drag(pos1, pos2, push_vec)
-- Checks if the two are perpendicular
return vector.dot(push_vec, vector.subtract(pos1, pos2)) == 0
end
mcl_sticky_api = {
sticks_to = function(node1, pos1, node2, pos2, push_vec)
local pull = 0
if is_pull(pos1, pos2, push_vec) then
pull = 2
elseif is_drag(pos1, pos2, push_vec) then
pull = 1
else
return false
end
if stick_map[node1.name] then
if stick_map[node2.name] then
return has_value(stick_map[node1.name][pull], node2.name)
else
return has_value(stick_map[node1.name][pull], "default")
end
elseif stick_map[node2.name] then
return has_value(stick_map[node2.name][pull], "default")
end
return false
end,
add_empty = function(name)
stick_map[name] = {{},{}}
end,
add_stick = function(name1, name2)
if not stick_map[name1] then
mcl_sticky_api.add_empty(name1)
end
if not stick_map[name2] then
mcl_sticky_api.add_empty(name2)
end
table.insert(stick_map[name1][1], name2)
table.insert(stick_map[name1][2], name2)
table.insert(stick_map[name2][1], name1)
table.insert(stick_map[name2][2], name1)
end,
add_stick_pull = function(name1, name2)
if not stick_map[name1] then
mcl_sticky_api.add_empty(name1)
end
if not stick_map[name2] then
mcl_sticky_api.add_empty(name2)
end
table.insert(stick_map[name1][2], name2)
table.insert(stick_map[name2][2], name1)
end,
add_stick_drag = function(name1, name2)
if not stick_map[name1] then
mcl_sticky_api.add_empty(name1)
end
if not stick_map[name2] then
mcl_sticky_api.add_empty(name2)
end
table.insert(stick_map[name1][1], name2)
table.insert(stick_map[name2][1], name1)
end,
remove_stick = function(name1, name2)
if not stick_map[name1] then
return
end
if not stick_map[name2] then
return
end
remove_value(stick_map[name1][1], name2)
remove_value(stick_map[name1][2], name2)
remove_value(stick_map[name2][1], name1)
remove_value(stick_map[name2][2], name1)
end,
remove_stick_pull = function(name1, name2)
if not stick_map[name1] then
return
end
if not stick_map[name2] then
return
end
remove_value(stick_map[name2][2], name1)
remove_value(stick_map[name1][2], name2)
end,
remove_stick_drag = function(name1, name2)
if not stick_map[name1] then
return
end
if not stick_map[name2] then
return
end
remove_value(stick_map[name1][1], name2)
remove_value(stick_map[name2][1], name1)
end,
default_stick = function()
return mcl_sticky_api.stick_with_cond(mcl_sticky_api.sticks_to)
end,
stick_with_cond = function(stick_cond)
return function(pos, node, piston_pos)
local connected = {}
for n, v in ipairs(alldirs) do
local neighbor_pos = vector.add(pos, v)
local neighbor_node = minetest.get_node(neighbor_pos)
if neighbor_node then
if neighbor_node.name == "ignore" then
minetest.get_voxel_manip():read_from_map(neighbor_pos, neighbor_pos)
neighbor_node = minetest.get_node(neighbor_pos)
end
local name2 = neighbor_node.name
if name2 ~= "air" and name2 ~= "ignore" and not mesecon.mvps_unsticky[name2] then
local piston, piston_side, piston_up, piston_down = false, false, false, false
if name2 == "mesecons_pistons:piston_sticky_off" or name2 == "mesecons_pistons:piston_normal_off" then
piston, piston_side = true, true
elseif name2 == "mesecons_pistons:piston_up_sticky_off" or name2 == "mesecons_pistons:piston_up_normal_off" then
piston, piston_up = true, true
elseif name2 == "mesecons_pistons:piston_down_sticky_off" or name2 == "mesecons_pistons:piston_down_normal_off" then
piston, piston_down = true, true
end
if not( (piston_side and (n-1==neighbor_node.param2)) or (piston_up and (n==5)) or (piston_down and (n==6)) ) then
local push_dir = minetest.facedir_to_dir(minetest.get_node(piston_pos).param2)
if name2:match("(_up)") then
push_dir = {x=0, y=1, z=0}
elseif name2:match("(_down)") then
push_dir = {x=0, y=-1, z=0}
end
if name2:match("(_on)") then
push_dir = vector.subtract(vector.new(), push_dir)
end
if piston_pos and (minetest.get_node(piston_pos) ~= "ignore") and
stick_cond(node, pos, neighbor_node, neighbor_pos, push_dir) then
if piston then
if piston_pos.x == neighbor_pos.x and piston_pos.y == neighbor_pos.y and piston_pos.z == neighbor_pos.z then
-- Loopback to the same piston! Preventing unwanted behavior:
return {}, true
end
end
table.insert(connected, neighbor_pos)
end
end
end
end
end
return connected, false
end
end,
}

View File

@ -0,0 +1,216 @@
local S = minetest.get_translator(minetest.get_current_modname())
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/api.lua")
mcl_sticky_api.add_stick("default", "mcl_sticky:slimeblock")
mcl_sticky_api.add_stick("mcl_sticky:slimeblock", "mcl_sticky:slimeblock")
minetest.register_alias("mcl_core:slimeblock", "mcl_sticky:slimeblock")
minetest.register_node("mcl_sticky:slimeblock", {
description = S("Slime Block"),
_doc_items_longdesc = S("Slime blocks are very bouncy and prevent fall damage."),
drawtype = "nodebox",
paramtype = "light",
is_ground_content = false,
node_box = {
type = "fixed",
fixed = {
{ -0.25, -0.25, -0.25, 0.25, 0.25, 0.25 },
{ -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
}
},
selection_box = {
type = "regular",
},
tiles = { "mcl_core_slime_template.png^[colorize:#00a0008c:128" },
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "blend" or true,
stack_max = 64,
-- According to Minecraft Wiki, bouncing off a slime block from a height off 255 blocks should result in a bounce height of 50 blocks
-- bouncy=44 makes the player bounce up to 49.6. This value was chosen by experiment.
-- bouncy=80 was chosen because it is higher than 66 (bounciness of bed)
groups = { dig_immediate = 3, bouncy = 80, fall_damage_add_percent = -100, deco_block = 1 },
sounds = {
dug = { name = "slimenodes_dug", gain = 0.6 },
place = { name = "slimenodes_place", gain = 0.6 },
footstep = { name = "slimenodes_step", gain = 0.3 },
},
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
mvps_sticky = mcl_sticky_api.default_stick(),
})
mcl_sticky_api.add_stick("default", "mcl_sticky:honeyblock")
mcl_sticky_api.add_stick("mcl_sticky:honeyblock", "mcl_sticky:honeyblock")
minetest.register_node("mcl_sticky:honeyblock", {
description = S("Honey Block"),
_doc_items_longdesc = S("Honey blocks are sticky and prevent fall damage."),
drawtype = "nodebox",
paramtype = "light",
is_ground_content = false,
node_box = {
type = "fixed",
fixed = {
{ -0.25, -0.25, -0.25, 0.25, 0.25, 0.25 },
{ -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
}
},
selection_box = {
type = "regular",
},
tiles = { "mcl_core_slime_template.png^[colorize:#a070008c:128" },
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "blend" or true,
stack_max = 64,
groups = { dig_immediate = 3, bouncy = -80, fall_damage_add_percent = -100, deco_block = 1 },
sounds = {
dug = { name = "slimenodes_dug", gain = 0.6 },
place = { name = "slimenodes_place", gain = 0.6 },
footstep = { name = "slimenodes_step", gain = 0.3 },
},
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
mvps_sticky = mcl_sticky_api.default_stick(),
})
minetest.register_craft({
output = "mcl_sticky:honeyblock",
recipe = { { "mcl_potions:fire_resistance", "mcl_potions:fire_resistance", "mcl_potions:fire_resistance", },
{ "mcl_potions:fire_resistance", "mcl_potions:fire_resistance", "mcl_potions:fire_resistance", },
{ "mcl_potions:fire_resistance", "mcl_potions:fire_resistance", "mcl_potions:fire_resistance", } },
replacements = { { "mcl_potions:fire_resistance", "mcl_potions:glass_bottle" },
{ "mcl_potions:fire_resistance", "mcl_potions:glass_bottle" },
{ "mcl_potions:fire_resistance", "mcl_potions:glass_bottle" },
{ "mcl_potions:fire_resistance", "mcl_potions:glass_bottle" },
{ "mcl_potions:fire_resistance", "mcl_potions:glass_bottle" },
{ "mcl_potions:fire_resistance", "mcl_potions:glass_bottle" },
{ "mcl_potions:fire_resistance", "mcl_potions:glass_bottle" },
{ "mcl_potions:fire_resistance", "mcl_potions:glass_bottle" },
{ "mcl_potions:fire_resistance", "mcl_potions:glass_bottle" },
},
})
if minetest.settings:get_bool("more_slime") then
mcl_sticky_api.add_stick("mcl_sticky:endslime", "mcl_sticky:endslime")
minetest.register_node("mcl_sticky:endslime", {
description = S("End Slime Block"),
_doc_items_longdesc = S("End slime blocks stick only to themselves"),
drawtype = "nodebox",
paramtype = "light",
is_ground_content = false,
node_box = {
type = "fixed",
fixed = {
{ -0.25, -0.25, -0.25, 0.25, 0.25, 0.25 },
{ -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
}
},
selection_box = {
type = "regular",
},
tiles = { "mcl_core_slime_template.png^[colorize:#8000808c:128" },
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "blend" or true,
stack_max = 64,
groups = { dig_immediate = 3, bouncy = 80, fall_damage_add_percent = -100, deco_block = 1 },
sounds = {
dug = { name = "slimenodes_dug", gain = 0.6 },
place = { name = "slimenodes_place", gain = 0.6 },
footstep = { name = "slimenodes_step", gain = 0.3 },
},
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
mvps_sticky = mcl_sticky_api.default_stick(),
})
minetest.register_craft({
output = "mcl_sticky:endslime",
recipe = { { "", "mcl_throwing:ender_pearl", "", },
{ "mcl_throwing:ender_pearl", "mcl_sticky:slimeblock", "mcl_throwing:ender_pearl", },
{ "", "mcl_throwing:ender_pearl", "", } },
})
mcl_sticky_api.add_stick("mcl_sticky:ichorslime", "mcl_sticky:slimeblock")
mcl_sticky_api.add_stick("mcl_sticky:ichorslime", "mcl_sticky:honeyblock")
mcl_sticky_api.add_stick("mcl_sticky:ichorslime", "default")
minetest.register_node("mcl_sticky:ichorslime", {
description = S("Ichor Block"),
_doc_items_longdesc = S("Ichor blocks stick to anything but themselves"),
drawtype = "nodebox",
paramtype = "light",
is_ground_content = false,
node_box = {
type = "fixed",
fixed = {
{ -0.25, -0.25, -0.25, 0.25, 0.25, 0.25 },
{ -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
}
},
selection_box = {
type = "regular",
},
tiles = { "mcl_core_slime_template.png^[colorize:#902000ff:128" },
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "blend" or true,
stack_max = 64,
groups = { dig_immediate = 3, bouncy = 80, fall_damage_add_percent = -100, deco_block = 1 },
sounds = {
dug = { name = "slimenodes_dug", gain = 0.6 },
place = { name = "slimenodes_place", gain = 0.6 },
footstep = { name = "slimenodes_step", gain = 0.3 },
},
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
mvps_sticky = mcl_sticky_api.default_stick(),
})
minetest.register_craft({
output = "mcl_sticky:ichorslime",
recipe = { { "", "mcl_mobitems:blaze_powder", "", },
{ "mcl_mobitems:blaze_powder", "mcl_sticky:slimeblock", "mcl_mobitems:blaze_powder", },
{ "", "mcl_mobitems:blaze_powder", "", } },
})
mcl_sticky_api.add_stick_drag("mcl_sticky:waterslime", "mcl_sticky:slimeblock")
mcl_sticky_api.add_stick_drag("mcl_sticky:waterslime", "mcl_sticky:honeyblock")
mcl_sticky_api.add_stick_drag("mcl_sticky:waterslime", "mcl_sticky:ichorslime")
mcl_sticky_api.add_stick_drag("mcl_sticky:waterslime", "mcl_sticky:waterslime")
mcl_sticky_api.add_stick_drag("mcl_sticky:waterslime", "default")
minetest.register_node("mcl_sticky:waterslime", {
description = S("Water Slime Block"),
_doc_items_longdesc = S("Water slime blocks only stick to blocks to their side"),
drawtype = "nodebox",
paramtype = "light",
is_ground_content = false,
node_box = {
type = "fixed",
fixed = {
{ -0.25, -0.25, -0.25, 0.25, 0.25, 0.25 },
{ -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
}
},
selection_box = {
type = "regular",
},
tiles = { "mcl_core_slime_template.png^[colorize:#000080ff:128" },
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "blend" or true,
stack_max = 64,
groups = { dig_immediate = 3, bouncy = 80, fall_damage_add_percent = -100, deco_block = 1 },
sounds = {
dug = { name = "slimenodes_dug", gain = 0.6 },
place = { name = "slimenodes_place", gain = 0.6 },
footstep = { name = "slimenodes_step", gain = 0.3 },
},
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
mvps_sticky = mcl_sticky_api.default_stick(),
})
minetest.register_craft({
output = "mcl_sticky:waterslime",
recipe = { { "", "mcl_ocean:prismarine_crystal", "", },
{ "mcl_ocean:prismarine_crystal", "mcl_sticky:slimeblock", "mcl_ocean:prismarine_crystal", },
{ "", "mcl_ocean:prismarine_crystal", "", } },
})
end

View File

@ -0,0 +1,11 @@
# textdomain: mcl_sticky
Slime Block=
Slime blocks are very bouncy and prevent fall damage.=
Honey Block=
Honey blocks are sticky and prevent fall damage.=
End Slime Block=
End slime blocks stick only to themselves=
Ichor Block=
Ichor blocks stick to anything but themselves=
Water Slime Block=
Water slime blocks only stick to blocks to their side=

View File

@ -0,0 +1,3 @@
name = mcl_sticky
description = Sticky blocks like honey and endslime
depends = mcl_core, mcl_sounds, mcl_nether, mcl_end, mesecons_mvps, doc