change minetest. to core.

This commit is contained in:
tenplus1 2025-05-04 13:32:26 +01:00
parent fcc2bf8be3
commit 355be56a2c

View file

@ -8,23 +8,23 @@
-- translation and settings -- translation and settings
local S = minetest.get_translator("teleport_potion") local S = core.get_translator("teleport_potion")
local mcl = minetest.get_modpath("mcl_core") local mcl = core.get_modpath("mcl_core")
local dist = tonumber(minetest.settings:get("map_generation_limit") or 31000) local dist = tonumber(core.settings:get("map_generation_limit") or 31000)
-- creative check -- creative check
local creative_mode_cache = minetest.settings:get_bool("creative_mode") local creative_mode_cache = core.settings:get_bool("creative_mode")
local function is_creative(name) local function is_creative(name)
return creative_mode_cache or minetest.check_player_privs(name, {creative = true}) return creative_mode_cache or core.check_player_privs(name, {creative = true})
end end
-- choose texture for teleport pad -- choose texture for teleport pad
local teleport_pad_texture = "teleport_potion_pad.png" local teleport_pad_texture = "teleport_potion_pad.png"
if minetest.settings:get_bool("teleport_potion_use_old_texture") == true then if core.settings:get_bool("teleport_potion_use_old_texture") == true then
teleport_pad_texture = "teleport_potion_pad_v1.png" teleport_pad_texture = "teleport_potion_pad_v1.png"
end end
@ -63,7 +63,7 @@ local function effect(pos, amount, texture, min_size, max_size, radius, gravity,
radius = radius or 2 radius = radius or 2
gravity = gravity or -10 gravity = gravity or -10
minetest.add_particlespawner({ core.add_particlespawner({
amount = amount, amount = amount,
time = 0.25, time = 0.25,
minpos = pos, minpos = pos,
@ -91,13 +91,13 @@ local function set_teleport_destination(playername, dest)
effect(dest, 20, "teleport_potion_particle.png", 0.5, 1.5, 1, 7, 15) effect(dest, 20, "teleport_potion_particle.png", 0.5, 1.5, 1, 7, 15)
minetest.sound_play("portal_open", { core.sound_play("portal_open", {
pos = dest, gain = 1.0, max_hear_distance = 10}, true) pos = dest, gain = 1.0, max_hear_distance = 10}, true)
end end
--- Teleport portal --- Teleport portal
minetest.register_node("teleport_potion:portal", { core.register_node("teleport_potion:portal", {
drawtype = "plantlike", drawtype = "plantlike",
tiles = { tiles = {
{ {
@ -120,18 +120,18 @@ minetest.register_node("teleport_potion:portal", {
-- start timer when portal appears -- start timer when portal appears
on_construct = function(pos) on_construct = function(pos)
minetest.get_node_timer(pos):start(10) core.get_node_timer(pos):start(10)
end, end,
-- remove portal after 10 seconds -- remove portal after 10 seconds
on_timer = function(pos) on_timer = function(pos)
minetest.sound_play("portal_close", { core.sound_play("portal_close", {
pos = pos, gain = 1.0, max_hear_distance = 10}, true) pos = pos, gain = 1.0, max_hear_distance = 10}, true)
effect(pos, 25, "teleport_potion_particle.png", 2, 2, 1, -10, 15) effect(pos, 25, "teleport_potion_particle.png", 2, 2, 1, -10, 15)
minetest.remove_node(pos) core.remove_node(pos)
end, end,
on_blast = function() end, on_blast = function() end,
@ -143,7 +143,7 @@ local function throw_potion(itemstack, player)
local playerpos = player:get_pos() local playerpos = player:get_pos()
local obj = minetest.add_entity({ local obj = core.add_entity({
x = playerpos.x, x = playerpos.x,
y = playerpos.y + 1.5, y = playerpos.y + 1.5,
z = playerpos.z z = playerpos.z
@ -199,7 +199,7 @@ potion_entity.on_step = function(self, dtime)
local oldpos = self.player:get_pos() local oldpos = self.player:get_pos()
-- play sound and disappearing particle effect at current position -- play sound and disappearing particle effect at current position
minetest.sound_play("portal_close", { core.sound_play("portal_close", {
pos = oldpos, gain = 1.0, max_hear_distance = 5}, true) pos = oldpos, gain = 1.0, max_hear_distance = 5}, true)
oldpos.y = oldpos.y + 1 oldpos.y = oldpos.y + 1
@ -209,7 +209,7 @@ potion_entity.on_step = function(self, dtime)
-- teleport to new position, play sound and show appear effect -- teleport to new position, play sound and show appear effect
self.player:set_pos(self.lastpos) self.player:set_pos(self.lastpos)
minetest.sound_play("portal_close", { core.sound_play("portal_close", {
pos = self.lastpos, gain = 1.0, max_hear_distance = 5}, true) pos = self.lastpos, gain = 1.0, max_hear_distance = 5}, true)
effect(self.lastpos, 20, "teleport_potion_particle.png", 2, 2, 1, 10, 15) effect(self.lastpos, 20, "teleport_potion_particle.png", 2, 2, 1, 10, 15)
@ -225,11 +225,11 @@ potion_entity.on_step = function(self, dtime)
self.lastpos = pos self.lastpos = pos
end end
minetest.register_entity("teleport_potion:potion_entity", potion_entity) core.register_entity("teleport_potion:potion_entity", potion_entity)
--- Teleport potion --- Teleport potion
minetest.register_node("teleport_potion:potion", { core.register_node("teleport_potion:potion", {
tiles = {"teleport_potion_potion.png"}, tiles = {"teleport_potion_potion.png"},
drawtype = "signlike", drawtype = "signlike",
paramtype = "light", paramtype = "light",
@ -265,9 +265,9 @@ minetest.register_node("teleport_potion:potion", {
if dest then if dest then
minetest.set_node(pos, {name = "teleport_potion:portal"}) core.set_node(pos, {name = "teleport_potion:portal"})
local meta = minetest.get_meta(pos) local meta = core.get_meta(pos)
-- Set portal destination -- Set portal destination
meta:set_int("x", dest.x) meta:set_int("x", dest.x)
@ -277,12 +277,12 @@ minetest.register_node("teleport_potion:potion", {
-- Portal open effect and sound -- Portal open effect and sound
effect(pos, 20, "teleport_potion_particle.png", 0.5, 1.5, 1, 7, 15) effect(pos, 20, "teleport_potion_particle.png", 0.5, 1.5, 1, 7, 15)
minetest.sound_play("portal_open", { core.sound_play("portal_open", {
pos = pos, gain = 1.0, max_hear_distance = 10}, true) pos = pos, gain = 1.0, max_hear_distance = 10}, true)
else else
minetest.chat_send_player(name, S("Potion failed!")) core.chat_send_player(name, S("Potion failed!"))
minetest.remove_node(pos) core.remove_node(pos)
minetest.add_item(pos, "teleport_potion:potion") core.add_item(pos, "teleport_potion:potion")
end end
end end
}) })
@ -291,7 +291,7 @@ minetest.register_node("teleport_potion:potion", {
if mcl then if mcl then
minetest.register_craft({ core.register_craft({
output = "teleport_potion:potion", output = "teleport_potion:potion",
recipe = { recipe = {
{"", "mcl_core:diamond", ""}, {"", "mcl_core:diamond", ""},
@ -300,7 +300,7 @@ if mcl then
} }
}) })
else else
minetest.register_craft({ core.register_craft({
output = "teleport_potion:potion", output = "teleport_potion:potion",
recipe = { recipe = {
{"", "default:diamond", ""}, {"", "default:diamond", ""},
@ -314,7 +314,7 @@ end
local teleport_formspec_context = {} local teleport_formspec_context = {}
minetest.register_node("teleport_potion:pad", { core.register_node("teleport_potion:pad", {
tiles = {teleport_pad_texture, teleport_pad_texture .. "^[transformFY"}, tiles = {teleport_pad_texture, teleport_pad_texture .. "^[transformFY"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -345,7 +345,7 @@ minetest.register_node("teleport_potion:pad", {
-- Initialize teleport to saved location or the current position -- Initialize teleport to saved location or the current position
after_place_node = function(pos, placer, itemstack, pointed_thing) after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos) local meta = core.get_meta(pos)
local name = placer:get_player_name() local name = placer:get_player_name()
local dest = teleport_destinations[name] local dest = teleport_destinations[name]
@ -360,7 +360,7 @@ minetest.register_node("teleport_potion:pad", {
effect(pos, 20, "teleport_potion_particle.png", 0.5, 1.5, 1, 7, 15) effect(pos, 20, "teleport_potion_particle.png", 0.5, 1.5, 1, 7, 15)
minetest.sound_play("portal_open", { core.sound_play("portal_open", {
pos = pos, gain = 1.0, max_hear_distance = 10}, true) pos = pos, gain = 1.0, max_hear_distance = 10}, true)
end, end,
@ -369,35 +369,35 @@ minetest.register_node("teleport_potion:pad", {
local name = clicker:get_player_name() local name = clicker:get_player_name()
if minetest.is_protected(pos, name) then if core.is_protected(pos, name) then
minetest.record_protection_violation(pos, name) core.record_protection_violation(pos, name)
return return
end end
local meta = minetest.get_meta(pos) local meta = core.get_meta(pos)
local coords = meta:get_int("x") .. "," local coords = meta:get_int("x") .. ","
.. meta:get_int("y") .. "," .. meta:get_int("z") .. meta:get_int("y") .. "," .. meta:get_int("z")
local desc = meta:get_string("desc") local desc = meta:get_string("desc")
local formspec = "field[desc;" .. S("Description") .. ";" local formspec = "field[desc;" .. S("Description") .. ";"
.. minetest.formspec_escape(desc) .. "]" .. core.formspec_escape(desc) .. "]"
-- Only allow privileged players to change coordinates -- Only allow privileged players to change coordinates
if minetest.check_player_privs(name, "teleport") then if core.check_player_privs(name, "teleport") then
formspec = formspec .. formspec = formspec ..
"field[coords;" .. S("Teleport coordinates") .. ";" .. coords .. "]" "field[coords;" .. S("Teleport coordinates") .. ";" .. coords .. "]"
end end
teleport_formspec_context[name] = {pos = pos, coords = coords, desc = desc} teleport_formspec_context[name] = {pos = pos, coords = coords, desc = desc}
minetest.show_formspec(name, "teleport_potion:set_destination", formspec) core.show_formspec(name, "teleport_potion:set_destination", formspec)
end end
}) })
-- Check and set coordinates -- Check and set coordinates
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "teleport_potion:set_destination" then return false end if formname ~= "teleport_potion:set_destination" then return false end
@ -410,7 +410,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.control == nil and fields.desc == nil then return false end if fields.control == nil and fields.desc == nil then return false end
local meta = minetest.get_meta(context.pos) local meta = core.get_meta(context.pos)
-- Coordinates were changed -- Coordinates were changed
if fields.coords and fields.coords ~= context.coords then if fields.coords and fields.coords ~= context.coords then
@ -422,7 +422,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
meta:set_int("y", coords.y) meta:set_int("y", coords.y)
meta:set_int("z", coords.z) meta:set_int("z", coords.z)
else else
minetest.chat_send_player(name, S("Teleport Pad coordinates failed!")) core.chat_send_player(name, S("Teleport Pad coordinates failed!"))
end end
end end
@ -434,7 +434,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.desc and fields.desc ~= "" then if fields.desc and fields.desc ~= "" then
meta:set_string("infotext", S("Teleport to @1", fields.desc)) meta:set_string("infotext", S("Teleport to @1", fields.desc))
else else
local coords = minetest.string_to_pos("(" .. context.coords .. ")") local coords = core.string_to_pos("(" .. context.coords .. ")")
meta:set_string("infotext", S("Pad Active (@1,@2,@3)", meta:set_string("infotext", S("Pad Active (@1,@2,@3)",
coords.x, coords.y, coords.z)) coords.x, coords.y, coords.z))
@ -447,7 +447,7 @@ end)
if mcl then if mcl then
minetest.register_craft({ core.register_craft({
output = "teleport_potion:pad", output = "teleport_potion:pad",
recipe = { recipe = {
{"teleport_potion:potion", "mcl_core:glass", "teleport_potion:potion"}, {"teleport_potion:potion", "mcl_core:glass", "teleport_potion:potion"},
@ -456,7 +456,7 @@ if mcl then
} }
}) })
else else
minetest.register_craft({ core.register_craft({
output = "teleport_potion:pad", output = "teleport_potion:pad",
recipe = { recipe = {
{"teleport_potion:potion", "default:glass", "teleport_potion:potion"}, {"teleport_potion:potion", "default:glass", "teleport_potion:potion"},
@ -468,7 +468,7 @@ end
-- check portal & pad, teleport any entities on top -- check portal & pad, teleport any entities on top
minetest.register_abm({ core.register_abm({
label = "Potion/Pad teleportation", label = "Potion/Pad teleportation",
nodenames = {"teleport_potion:portal", "teleport_potion:pad"}, nodenames = {"teleport_potion:portal", "teleport_potion:pad"},
interval = 2, interval = 2,
@ -478,12 +478,12 @@ minetest.register_abm({
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
-- check objects inside pad/portal -- check objects inside pad/portal
local objs = minetest.get_objects_inside_radius(pos, 1) local objs = core.get_objects_inside_radius(pos, 1)
if #objs == 0 then return end if #objs == 0 then return end
-- get coords from pad/portal -- get coords from pad/portal
local meta = minetest.get_meta(pos) local meta = core.get_meta(pos)
if not meta then return end -- errorcheck if not meta then return end -- errorcheck
@ -499,7 +499,7 @@ minetest.register_abm({
if objs[n]:is_player() and not objs[n]:get_attach() then if objs[n]:is_player() and not objs[n]:get_attach() then
-- play sound on portal end -- play sound on portal end
minetest.sound_play("portal_close", { core.sound_play("portal_close", {
pos = pos, gain = 1.0, max_hear_distance = 5}, true) pos = pos, gain = 1.0, max_hear_distance = 5}, true)
pos.y = pos.y + 1 pos.y = pos.y + 1
@ -514,7 +514,7 @@ minetest.register_abm({
effect(target_coords, 20, "teleport_potion_particle.png", 2, 2, 1, 10, 15) effect(target_coords, 20, "teleport_potion_particle.png", 2, 2, 1, 10, 15)
-- play sound on destination end -- play sound on destination end
minetest.sound_play("portal_close", { core.sound_play("portal_close", {
pos = target_coords, gain = 1.0, max_hear_distance = 5}, true) pos = target_coords, gain = 1.0, max_hear_distance = 5}, true)
-- rotate player to look in pad placement direction -- rotate player to look in pad placement direction
@ -535,7 +535,7 @@ minetest.register_abm({
-- lucky blocks -- lucky blocks
if minetest.get_modpath("lucky_block") then if core.get_modpath("lucky_block") then
lucky_block:add_blocks({ lucky_block:add_blocks({
{"dro", {"teleport_potion:potion"}, 2}, {"dro", {"teleport_potion:potion"}, 2},