brewing update

master
runs 2020-08-04 03:54:57 +02:00
parent c9c6a98360
commit 0571cb2810
23 changed files with 289 additions and 147 deletions

View File

@ -2,6 +2,9 @@
Create incredible potions for Minetest. Create incredible potions for Minetest.
**This mod requires Player Physics mod as hard dependency.**
## API ## API
### brewing.register_potion_craft ### brewing.register_potion_craft
@ -23,7 +26,13 @@ Create incredible potions for Minetest.
- Level: Intensity of the effect (1 to 3) - Level: Intensity of the effect (1 to 3)
- Recipe: The 3 ingredients to craft the potion. - Recipe: The 3 ingredients to craft the potion. The recipe is SHAPED (the order matters).
## Duration Time of the Effects
- For Jump & Speed effects= 60s (lvl1), 30s (lvl2) and 15s (lvl3).
- For Health & Air effects= 15s (lvl1), 3s (lvl2) and 60s (lvl3).
- Note: "One Use Health" and "One Use Air" obviously have no time.
## Recipe Book ## Recipe Book

View File

@ -1,7 +1,7 @@
local S, modname = ... local S, modname = ...
-- Function to register the potions -- Function to register the potions
brewing.register_potion = function(sname, name, fname, time, def) brewing.register_potion = function(sname, name, fname, def)
local tps = {"add", "sub"} local tps = {"add", "sub"}
for t=1, #tps do for t=1, #tps do
for i=1, #def.types do for i=1, #def.types do
@ -29,21 +29,17 @@ brewing.register_potion = function(sname, name, fname, time, def)
if t == 2 then if t == 2 then
flags.inv = true flags.inv = true
end end
for name, val in pairs(brewing.effects[def.effect](sname, name, fname, time, sdata, flags)) do for key, val in pairs(brewing.effects[def.effect](sname, name, fname, sdata, flags)) do
item_def[name] = val item_def[key] = val
end end
for name, val in pairs(sdata.set) do for key, val in pairs(sdata.set) do
item_def[name] = val item_def[key] = val
end end
for name, val in pairs(sdata.effects) do item_def["time"] = sdata.time
item_def.potions[name] = val for key, val in pairs(sdata.effects) do
item_def.potions[key] = val
end end
minetest.register_node(fname.."_"..tps[t]..sdata.type, item_def) minetest.register_node(fname.."_"..tps[t]..sdata.type, item_def)
--potions.register_liquid(i..tps[t]..sname, name.." ("..tps[t].." "..i..")", item_def.on_use)
if minetest.get_modpath("throwing")~=nil then
brewing.register_arrow(fname.."_"..tps[t]..sdata.type, i..tps[t]..sname, name.." ("..tps[t].." "..i..")", item_def.on_use,
item_def.description, item_def.inventory_image)
end
end end
end end
end end
@ -70,20 +66,15 @@ brewing.get_craft_result = function(ingredients)
--firstly in the 2 rows --firstly in the 2 rows
for i= 1, 3, 1 do for i= 1, 3, 1 do
match = false match = false
for j = 1, 3, 1 do if (potion_craft["recipe"][i] == ingredients[i]) or (potion_craft["recipe"][i] == '') then
--minetest.chat_send_player("singleplayer", "item="..potion_craft["recipe"][i]) match = true
--minetest.chat_send_player("singleplayer", "item2=".. ingredients[j])
if (potion_craft["recipe"][i] == ingredients[j]) or (potion_craft["recipe"][i] == '') then
match = true
break
end
end end
if not match then --if an ingredient does not match if not match then --if an ingredient does not match
break break
end end
end end
if match then --if coincidence with a potion_craft if match then --if coincidence with a potion_craft
output = modname ..":" .. potion_craft["effect"] .. "_".. potion_craft["type"] .. potion_craft["level"] output = modname ..":" .. potion_craft["effect"] .. "_".. potion_craft["type"] .. math.abs(potion_craft["level"])
break break
end end
end end

View File

@ -38,15 +38,15 @@ local function create_recipe_book_form()
"button_exit[3.5,6.6;1,1;btn_exit;"..S("Close").."]" "button_exit[3.5,6.6;1,1;btn_exit;"..S("Close").."]"
--Create the cells --Create the cells
local cells = "" local cells = ""
local potion_name = ""
local potion_names = {} local potion_names = {}
local potion_idxs = "" local potion_idxs = ""
local potion_idx = 0 local potion_times = ""
local ing1_idxs = "" local ing1_idxs = ""
local ing2_idxs = "" local ing2_idxs = ""
local ing3_idxs = "" local ing3_idxs = ""
for index, potion_craft in ipairs(brewing.craft_list) do for index, potion_craft in ipairs(brewing.craft_list) do
if potion_craft["effect"] == "jumping" then local potion_name
if potion_craft["effect"] == "jump" then
potion_name = "potions_jump.png" potion_name = "potions_jump.png"
else else
potion_name = "potions_"..potion_craft["effect"]..".png" potion_name = "potions_"..potion_craft["effect"]..".png"
@ -59,6 +59,7 @@ local function create_recipe_book_form()
potion_exists = nil potion_exists = nil
end end
end end
local potion_idx
if potion_exists then if potion_exists then
potion_idx = potion_exists potion_idx = potion_exists
else else
@ -88,7 +89,15 @@ local function create_recipe_book_form()
else else
effect_type = "-" effect_type = "-"
end end
cells = cells .. potion_idx .. ","..S(uppercase(potion_craft["effect"])) .. ",".. S("lvl").. " ".. effect_type .. potion_craft["level"]..','..index..','..index..','..index local potion_name = "brewing:"..potion_craft["effect"].."_"..potion_craft["type"]..math.abs(potion_craft["level"])
--minetest.chat_send_all(potion_name)
local potion_time= minetest.registered_items[potion_name].time
if potion_time == nil then
potion_time = "-"
else
potion_time = potion_time.."s"
end
cells = cells .. potion_idx .. ","..S(uppercase(potion_craft["effect"])) .. ",".. S("lvl").. " ".. effect_type .. potion_craft["level"]..','..index..','..index..','..index..','..potion_time
if index > 1 then if index > 1 then
ing1_idxs = ing1_idxs .. ',' ing1_idxs = ing1_idxs .. ','
ing2_idxs = ing2_idxs .. ',' ing2_idxs = ing2_idxs .. ','
@ -105,9 +114,10 @@ local function create_recipe_book_form()
potion_idxs = potion_idxs .. tostring(idx).."="..value potion_idxs = potion_idxs .. tostring(idx).."="..value
end end
--minetest.chat_send_all(potion_idxs) --minetest.chat_send_all(potion_idxs)
--local def = minetest.registered_items[potion_name]
recipe_book_formspec = recipe_book_formspec =
recipe_book_formspec .. recipe_book_formspec ..
"tablecolumns[image,"..potion_idxs..";text;text;image,"..ing1_idxs..";image,"..ing2_idxs..";image,"..ing3_idxs.."]".. "tablecolumns[image,"..potion_idxs..";text;text;image,"..ing1_idxs..";image,"..ing2_idxs..";image,"..ing3_idxs..";text]"..
"table[0.375,0.375;7.2,6;table_potions;"..cells..";0]" "table[0.375,0.375;7.2,6;table_potions;"..cells..";0]"
return recipe_book_formspec return recipe_book_formspec
end end
@ -199,10 +209,11 @@ end
local function try_to_make_potion(pos, player) local function try_to_make_potion(pos, player)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local ing1, ing2, ing3, ignitor, water, flask, dst local ing1, ing2, ing3, ignitor, water, flask
local ing1_name, ing2_name, ing3_name, ignitor_name, water_name, flask_name local ing1_name, ing2_name, ing3_name, ignitor_name, water_name, flask_name
local flask_count local flask_count
local brewed local brewed
local infotext
local update = true local update = true
while update do while update do
update = false update = false
@ -219,16 +230,15 @@ local function try_to_make_potion(pos, player)
flask= inv:get_stack("flask", 1) flask= inv:get_stack("flask", 1)
flask_name = flask:get_name() flask_name = flask:get_name()
flask_count = flask:get_count() flask_count = flask:get_count()
dst= inv:get_stack("dst", 1)
--The list: {ingredient_list_name, ingredient_stack, ingredient_name, how_much_decrements_when_crafted} --The list: {ingredient_list_name, ingredient_stack, ingredient_name, how_much_decrements_when_crafted}
local ing_list = {{"ing1", ing1, ing1_name, 1}, {"ing2", ing2, ing2_name, 1}, {"ing3", ing3, ing3_name, 1}, {"ignitor", ignitor, ignitor_name, 1}, {"flask", flask, flask_name, brewing.settings.filled_flasks}} local ing_list = {{"ing1", ing1, ing1_name, 1}, {"ing2", ing2, ing2_name, 1}, {"ing3", ing3, ing3_name, 1}, {"ignitor", ignitor, ignitor_name, 1}, {"flask", flask, flask_name, brewing.settings.filled_flasks}}
local is_valid_water= is_valid_water(water_name) local valid_water= is_valid_water(water_name)
--minetest.chat_send_player("singleplayer", brewing.settings.ignitor_name) --minetest.chat_send_player("singleplayer", brewing.settings.ignitor_name)
if ignitor_name== brewing.settings.ignitor_name and is_valid_water and flask_name== brewing.settings.flask_name and flask_count >= brewing.settings.filled_flasks then if ignitor_name== brewing.settings.ignitor_name and valid_water and flask_name== brewing.settings.flask_name and flask_count >= brewing.settings.filled_flasks then
--brewed, afterbrewed = minetest.get_craft_result({method = "normal", width =3, items = {ingplus1, ingplus2, ingplus3, ingminus1, ingminus2, ingminus3, ignitor, water, flask}}) --brewed, afterbrewed = minetest.get_craft_result({method = "normal", width =3, items = {ingplus1, ingplus2, ingplus3, ingminus1, ingminus2, ingminus3, ignitor, water, flask}})
brewed = brewing.get_craft_result({ing1_name, ing2_name, ing3_name}) brewed = brewing.get_craft_result({ing1_name, ing2_name, ing3_name})
if brewed ~= nil then if brewed ~= nil then
@ -252,7 +262,7 @@ local function try_to_make_potion(pos, player)
end end
end end
end end
local infotext = "" infotext = ""
end end
-- --
-- Set meta values -- Set meta values

View File

@ -4,12 +4,12 @@ local S = ...
brewing.effects = {} brewing.effects = {}
brewing.effects.phys_override = function(sname, name, fname, time, sdata, flags) brewing.effects.phys_override = function(effect_name, description_name, potion_name, sdata, flags)
local def = { local def = {
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
brewing.make_sound("player", user, "brewing_magic_sound") brewing.make_sound("player", user, "brewing_magic_sound")
--brewing.magic_aura(user, user:get_pos(), "player", "default") --brewing.magic_aura(user, user:get_pos(), "player", "default")
brewing.grant(time, user:get_player_name(), fname.."_"..flags.type..sdata.type, name, flags) brewing.grant(user, effect_name, potion_name.."_"..flags.type..sdata.type, description_name, sdata.time or 0, flags)
itemstack:take_item() itemstack:take_item()
return itemstack return itemstack
end, end,
@ -24,7 +24,7 @@ brewing.effects.phys_override = function(sname, name, fname, time, sdata, flags)
return def return def
end end
brewing.effects.fixhp = function(sname, name, fname, time, sdata, flags) brewing.effects.fixhp = function(sname, name, fname, sdata, flags)
local def = { local def = {
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
brewing.make_sound("player", user, "brewing_magic_sound") brewing.make_sound("player", user, "brewing_magic_sound")
@ -52,7 +52,7 @@ brewing.effects.fixhp = function(sname, name, fname, time, sdata, flags)
return def return def
end end
brewing.effects.air = function(sname, name, fname, time, sdata, flags) brewing.effects.air = function(sname, name, fname, sdata, flags)
local def = { local def = {
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
brewing.make_sound("player", user, "brewing_magic_sound") brewing.make_sound("player", user, "brewing_magic_sound")
@ -82,38 +82,6 @@ brewing.effects.air = function(sname, name, fname, time, sdata, flags)
return def return def
end end
brewing.effects.blowup = function(sname, name, fname, time, sdata, flags)
local def = {
on_use = function(itemstack, user, pointed_thing)
brewing.make_sound("player", user, "brewing_magic_sound")
--brewing.magic_aura(user, user:get_pos(), "player", "default")
brewing.grant(time, user:get_player_name(), fname.."_"..flags.type..sdata.type, name, flags)
itemstack:take_item()
return itemstack
end,
potions = {
speed = 0,
jump = 0,
gravity = 0,
tnt = 0,
},
}
def.mobs = {
on_near = function(itemstack, user, pointed_thing)
local str = user:get_luaentity().brewing.exploding
if flags.inv==true then
str = math.max(0, str - sdata.power)
else
str = math.min(str + sdata.power, 250)
end
user:get_luaentity().brewing.exploding = str
itemstack:take_item()
return itemstack
end,
}
return def
end
brewing.effects.set_invisibility = function(player) -- hide player and name tag brewing.effects.set_invisibility = function(player) -- hide player and name tag
local prop = { local prop = {
visual_size = {x = 0, y = 0}, visual_size = {x = 0, y = 0},
@ -134,8 +102,9 @@ brewing.effects.set_visibility = function(player) -- show player and tag
player:set_properties(prop) player:set_properties(prop)
end end
brewing.grant = function(time, playername, potion_name, type, flags) brewing.grant = function(player, effect_name, potion_name, description_name, time, flags)
local rootdef = minetest.registered_items[potion_name] local rootdef = minetest.registered_items[potion_name]
--minetest.chat_send_all(potion_name)
if rootdef == nil then if rootdef == nil then
return return
end end
@ -152,27 +121,14 @@ brewing.grant = function(time, playername, potion_name, type, flags)
def.jump = 0 - def.jump def.jump = 0 - def.jump
def.tnt = 0 - def.tnt def.tnt = 0 - def.tnt
end end
brewing.addPrefs(playername, def.speed, def.jump, def.gravity, def.tnt) local player_name = player:get_player_name()
brewing.refresh(playername) playerphysics.add_physics_factor(player, effect_name, potion_name, def[effect_name])
minetest.chat_send_player(playername, S("You are under the effects of the").." "..type.." "..S("potion.")) minetest.chat_send_player(player_name, S("You are under the effects of the").." "..description_name.." "..S("potion."))
--minetest.chat_send_all("time="..tostring(time))
minetest.after(time, function() minetest.after(time, function()
brewing.addPrefs(playername, 0-def.speed, 0-def.jump, 0-def.gravity, 0-def.tnt) if minetest.get_player_by_name(player_name)~=nil then
brewing.refresh(playername) playerphysics.remove_physics_factor(player, effect_name, potion_name)
minetest.chat_send_player(playername, S("The effects of the").." "..type.." "..S("potion have worn off.")) minetest.chat_send_player(player_name, S("The effects of the").." "..description_name.." "..S("potion have worn off."))
end
end) end)
end end
brewing.addPrefs = function(playername, speed, jump, gravity, tnt)
local prefs = brewing.players[playername]
prefs.speed = prefs.speed + speed
prefs.jump = prefs.jump + jump
prefs.gravity = prefs.gravity + gravity
prefs.tnt = prefs.tnt + tnt
end
brewing.refresh = function(playername)
if minetest.get_player_by_name(playername)~=nil then
local prefs = brewing.players[playername]
minetest.get_player_by_name(playername):set_physics_override(prefs.speed, prefs.jump, prefs.gravity)
end
end

View File

@ -11,13 +11,13 @@ brewing.craft_list = {} --for potion crafts
brewing.effects = {} --for the player effects brewing.effects = {} --for the player effects
brewing.players = {} --for the players brewing.players = {} --for the players
assert(loadfile(modpath.. "/settings.lua"))(S, modpath) assert(loadfile(modpath.. "/settings.lua"))(modpath)
assert(loadfile(modpath.. "/api.lua"))(S, modname) assert(loadfile(modpath.. "/api.lua"))(S, modname)
assert(loadfile(modpath.. "/effects.lua"))(S) assert(loadfile(modpath.. "/effects.lua"))(S)
assert(loadfile(modpath.. "/potions.lua"))(S) assert(loadfile(modpath.. "/potions.lua"))(S)
assert(loadfile(modpath.. "/potion_crafts.lua"))() assert(loadfile(modpath.. "/potion_crafts.lua"))()
assert(loadfile(modpath.. "/cauldron.lua"))(S) assert(loadfile(modpath.. "/cauldron.lua"))(S)
assert(loadfile(modpath.. "/nodes.lua"))(S) assert(loadfile(modpath.. "/nodes.lua"))(S)
assert(loadfile(modpath.. "/player.lua"))(S) assert(loadfile(modpath.. "/player.lua"))()
assert(loadfile(modpath.. "/sound.lua"))() assert(loadfile(modpath.. "/sound.lua"))()
assert(loadfile(modpath.. "/mushroom.lua"))(S) assert(loadfile(modpath.. "/mushroom.lua"))(S)

View File

@ -6,7 +6,7 @@ Cortinarius Violaceus=Cortinarius Violaceus
Gliophorus Viridis=Gliophorus Viridis Gliophorus Viridis=Gliophorus Viridis
Green Hygrocybe=Green Hygrocybe Green Hygrocybe=Green Hygrocybe
Health=Salud Health=Salud
Jumping=Salto Jump=Salto
Leaiana Mycena=Leaiana Mycena Leaiana Mycena=Leaiana Mycena
lvl=nivel lvl=nivel
Magic Cauldron= Caldero mágico Magic Cauldron= Caldero mágico

View File

@ -1,4 +1,4 @@
name = brewing name = brewing
description = Magic Brewing System description = Magic Brewing System
depends = default, flowers depends = playerphysics, default, flowers
optional_depends = optional_depends =

View File

@ -1,5 +1,7 @@
local S = ... local S = ...
local mg_name = minetest.get_mapgen_setting("mg_name")
-- Orange Mycena -- Orange Mycena
if mg_name ~= "v6" and mg_name ~= "singlenode" then if mg_name ~= "v6" and mg_name ~= "singlenode" then

View File

@ -37,8 +37,8 @@ minetest.register_ore({
clust_scarcity = 10*10*10, clust_scarcity = 10*10*10,
clust_num_ores = 5, clust_num_ores = 5,
clust_size = 5, clust_size = 5,
y_min = -512,
y_max = -256, y_max = -256,
y_min = -512,
}) })
-- Magic Gem -- Magic Gem

View File

@ -1,25 +1,3 @@
local S = ...
minetest.register_on_joinplayer(function(player)
brewing.players[player:get_player_name()] = {
antigravity = 1,
jump = 1,
gravity = 1,
tnt = 0,
air = 0,
}
end)
minetest.register_on_joinplayer(function(player)
brewing.players[player:get_player_name()] = {
speed = 1,
jump = 1,
gravity = 1,
tnt = 0,
air = 0,
}
end)
minetest.register_chatcommand("effect", { minetest.register_chatcommand("effect", {
params = "none", params = "none",
description = "get effect info", description = "get effect info",

View File

@ -7,17 +7,17 @@ brewing.register_potion_craft({
recipe = {'brewing:cortinarius_violaceus', 'flowers:mushroom_red', 'brewing:gliophorus_viridis'} recipe = {'brewing:cortinarius_violaceus', 'flowers:mushroom_red', 'brewing:gliophorus_viridis'}
}) })
--Jumping --Jump
brewing.register_potion_craft({ brewing.register_potion_craft({
effect= "jumping", effect= "jump",
type= "add", type= "add",
level= 1, level= 1,
recipe = {'flowers:mushroom_brown', 'flowers:mushroom_red', 'brewing:gliophorus_viridis'} recipe = {'flowers:mushroom_brown', 'flowers:mushroom_red', 'brewing:gliophorus_viridis'}
}) })
brewing.register_potion_craft({ brewing.register_potion_craft({
effect= "jumping", effect= "jump",
type= "add", type= "add",
level= 2, level= 2,
recipe = {'brewing:orange_mycena', 'brewing:cortinarius_violaceus', 'brewing:gliophorus_viridis'} recipe = {'brewing:orange_mycena', 'brewing:cortinarius_violaceus', 'brewing:gliophorus_viridis'}
@ -45,3 +45,12 @@ brewing.register_potion_craft({
level= -3, level= -3,
recipe = {'flowers:mushroom_red', 'flowers:mushroom_red', 'flowers:mushroom_red'} recipe = {'flowers:mushroom_red', 'flowers:mushroom_red', 'flowers:mushroom_red'}
}) })
--Speed
brewing.register_potion_craft({
effect= "speed",
type= "add",
level= 2,
recipe = {'brewing:pluteus_chrysophaeus', 'brewing:green_hygrocybe', 'brewing:green_hygrocybe'}
})

View File

@ -1,6 +1,6 @@
local S = ... local S = ...
brewing.register_potion("speed", S("Speed"), "brewing:speed", 300, { brewing.register_potion("speed", S("Speed"), "brewing:speed", {
effect = "phys_override", effect = "phys_override",
types = { types = {
{ {
@ -9,6 +9,7 @@ brewing.register_potion("speed", S("Speed"), "brewing:speed", 300, {
effects = { effects = {
speed = 1, speed = 1,
}, },
time = 60,
}, },
{ {
type = 2, type = 2,
@ -16,6 +17,7 @@ brewing.register_potion("speed", S("Speed"), "brewing:speed", 300, {
effects = { effects = {
speed = 2, speed = 2,
}, },
time = 30,
}, },
{ {
type = 3, type = 3,
@ -23,11 +25,12 @@ brewing.register_potion("speed", S("Speed"), "brewing:speed", 300, {
effects = { effects = {
speed = 3, speed = 3,
}, },
time = 15,
}, },
} }
}) })
brewing.register_potion("antigrav", S("Anti-Gravity"), "brewing:antigravity", 300, { brewing.register_potion("antigrav", S("Anti-Gravity"), "brewing:antigravity", {
effect = "phys_override", effect = "phys_override",
types = { types = {
{ {
@ -36,6 +39,7 @@ brewing.register_potion("antigrav", S("Anti-Gravity"), "brewing:antigravity", 30
effects = { effects = {
gravity = -0.1, gravity = -0.1,
}, },
time = 60,
}, },
{ {
type = 2, type = 2,
@ -43,6 +47,7 @@ brewing.register_potion("antigrav", S("Anti-Gravity"), "brewing:antigravity", 30
effects = { effects = {
gravity = -0.2, gravity = -0.2,
}, },
time = 30,
}, },
{ {
type = 3, type = 3,
@ -50,11 +55,12 @@ brewing.register_potion("antigrav", S("Anti-Gravity"), "brewing:antigravity", 30
effects = { effects = {
gravity = -0.3, gravity = -0.3,
}, },
time = 15,
}, },
} }
}) })
brewing.register_potion("jump", S("Jumping"), "brewing:jumping", 300, { brewing.register_potion("jump", S("Jump"), "brewing:jump", {
effect = "phys_override", effect = "phys_override",
types = { types = {
{ {
@ -63,6 +69,7 @@ brewing.register_potion("jump", S("Jumping"), "brewing:jumping", 300, {
effects = { effects = {
jump = 0.5, jump = 0.5,
}, },
time = 60,
}, },
{ {
type = 2, type = 2,
@ -70,6 +77,7 @@ brewing.register_potion("jump", S("Jumping"), "brewing:jumping", 300, {
effects = { effects = {
jump = 1, jump = 1,
}, },
time = 30,
}, },
{ {
type = 3, type = 3,
@ -77,11 +85,12 @@ brewing.register_potion("jump", S("Jumping"), "brewing:jumping", 300, {
effects = { effects = {
jump = 1.5, jump = 1.5,
}, },
time = 15,
}, },
} }
}) })
brewing.register_potion("ouhealth", S("One Use Health"), "brewing:ouhealth", 300, { brewing.register_potion("ouhealth", S("One Use Health"), "brewing:ouhealth", {
effect = "fixhp", effect = "fixhp",
types = { types = {
{ {
@ -108,26 +117,26 @@ brewing.register_potion("ouhealth", S("One Use Health"), "brewing:ouhealth", 300
} }
}) })
brewing.register_potion("health", S("Health"), "brewing:health", 300, { brewing.register_potion("health", S("Health"), "brewing:health", {
effect = "fixhp", effect = "fixhp",
types = { types = {
{ {
type = 1, type = 1,
time = 60, time = 15,
set = {}, set = {},
effects = { effects = {
}, },
}, },
{ {
type = 2, type = 2,
time = 120, time = 30,
set = {}, set = {},
effects = { effects = {
}, },
}, },
{ {
type = 3, type = 3,
time = 180, time = 60,
set = {}, set = {},
effects = { effects = {
}, },
@ -135,7 +144,7 @@ brewing.register_potion("health", S("Health"), "brewing:health", 300, {
} }
}) })
brewing.register_potion("ouair", S("One Use Air"), "brewing:ouair", 300, { brewing.register_potion("ouair", S("One Use Air"), "brewing:ouair", {
effect = "air", effect = "air",
types = { types = {
{ {
@ -162,26 +171,26 @@ brewing.register_potion("ouair", S("One Use Air"), "brewing:ouair", 300, {
} }
}) })
brewing.register_potion("air", S("Air"), "brewing:air", 300, { brewing.register_potion("air", S("Air"), "brewing:air", {
effect = "air", effect = "air",
types = { types = {
{ {
type = 1, type = 1,
time = 60, time = 15,
set = {}, set = {},
effects = { effects = {
}, },
}, },
{ {
type = 2, type = 2,
time = 120, time = 30,
set = {}, set = {},
effects = { effects = {
}, },
}, },
{ {
type = 3, type = 3,
time = 180, time = 60,
set = {}, set = {},
effects = { effects = {
}, },

View File

@ -1,4 +1,4 @@
local S, modpath = ... local modpath = ...
local function split(inputstr, sep) local function split(inputstr, sep)
if sep == nil then if sep == nil then

View File

@ -1,5 +1,3 @@
farbows = {}
-- internationalization boilerplate -- internationalization boilerplate
local S = minetest.get_translator(minetest.get_current_modname()) local S = minetest.get_translator(minetest.get_current_modname())

View File

@ -1,7 +1,4 @@
jonez = {}
--Variables --Variables
local modname = "jonez"
local S = minetest.get_translator(minetest.get_current_modname()) local S = minetest.get_translator(minetest.get_current_modname())
function firstToUpper(str) function firstToUpper(str)

View File

@ -94,7 +94,7 @@ function mobkit.lq_climb(self)
pos.y = pos.y + 0.5 pos.y = pos.y + 0.5
climb_pos = pos climb_pos = pos
break break
elseif not(petz.is_tree_like(node_name)) then elseif not(petz.is_tree_like(node.name)) then
climb = false climb = false
break break
end end

View File

@ -0,0 +1,123 @@
# Player Physics API.
Version: 1.0.0
This mod makes it possible for multiple mods to modify player physics (speed, jumping strength, gravity) without conflict.
## Introduction
### For players
Mods and games in Minetest can set physical attributes of players, such as speed and jump strength. For example, player speed could be set to 200%. But the way this works makes it difficult for multiple mods to *modify* physical attributes without leading to conflicts, problems and hilarious bugs, like speed that changes often to nonsense values.
The Player Physics API aims to resolve this conflict by providing a “common ground” for mods to work together in this regard.
This mod does nothing on its own, you will only need to install it as dependency of other mods.
When you browse for mods that somehow mess with player physics (namely: speed, jump strength or gravity) and want to use more than one of them, check out if they support the Player Physics API. If they don't, it's very likely these mods will break as soon you activate more than one of them, for example, if two mods try to set the player speed. If you found such a “hilarious bug”, please report it to the developers of the mods (or games) and point them to the Player Physics API.
Of course, not all mods need the Player Physics API. Mods that don't touch player physics at all won't need this mod.
The rest of this document is directed at developers.
### For developers
The function `set_physics_override` from the Minetest Lua API allows mod authors to override physical attributes of players, such as speed or jump strength.
This function works fine as long there is only one mod that sets a particular physical attribute at a time. However, as soon as at least two different mods (that do not know each other) try to change the same player physics attribute using only this function, there will be conflicts as each mod will undo the change of the other mod, as the function sets a raw value. A classic race condition occurs. This is the case because the mods fail to communicate with each other.
This mod solves the problem of conflicts. It bans the concept of “setting the raw value directly” and replaces it with the concept of factors that mods can add and remove for each attribute. The real physical player attribute will be the product of all active factors.
## Quick start
Let's say you have a mod `example` and want to double the speed of the player (i.e. multiply it by a factor of 2), but you also don't want to break other mods that might touch the speed.
Previously, you might have written something like this:
`player:set_physics_override({speed=2})`
However, your mod broke down as soon the mod `example2` came along, which wanted to increase the speed by 50%. In the real game, the player speed randomly switched from 50% and 200% which was a very annoying bug.
In your `example` mod, you can replace the code with this:
`playerphysics.add_physics_factor(player, "speed", "my_double_speed", 2)`
Where `"my_double_speed` is an unique ID for your speed factor.
Now your `example` mod is interoperable! And now, of course, the `example2` mod has to be updated in a similar fashion.
## Precondition
There is only one precondition to using this mod, but it is important:
Mods *MUST NOT* call `set_physics_override` directly for numerical values. Instead, to modify player physics, all mods that touch player physics have to use this API.
## Functions
### `playerphysics.add_physics_factor(player, attribute, id, value)`
Adds a factor for a player physic and updates the player physics immediately.
#### Parameters
* `player`: Player object
* `attribute`: Which of the physical attributes to change. Any of the numeric values of `set_physics_override` (e.g. `"speed"`, `"jump"`, `"gravity"`)
* `id`: Unique identifier for this factor. Identifiers are stored on a per-player per-attribute type basis
* `value`: The factor to add to the list of products
If a factor for the same player, attribute and `id` already existed, it will be overwritten.
### `playerphysics.remove_physics_factor(player, attribute, id)`
Removes the physics factor of the given ID and updates the player's physics.
#### Parameters
Same as in `playerphysics.add_physics_factor`, except there is no `value` argument.
## Examples
### Speed changes
Let's assume this mod is used by 3 different mods all trying to change the speed:
Potions, Exhaustion and Electrocution.
Here's what it could look like:
Potions mod:
```
playerphysics.add_physics_factor(player, "speed", "run_potion", 2)
```
Exhaustion mod:
```
playerphysics.add_physics_factor(player, "jump", "exhausted", 0.75)
```
Electrocution mod:
```
playerphysics.add_physics_factor(player, "jump", "shocked", 0.9)
```
When the 3 mods have done their change, the real player speed is simply the product of all factors, that is:
2 * 0.75 * 0.9 = 1.35
The final player speed is thus 135%.
### Speed changes, part 2
Let's take the example above.
Now if the Electrocution mod is done with shocking the player, it just needs to call:
```
playerphysics.remove_physics_factor(player, "jump", "shocked")
```
The effect is now gone, so the new player speed will be:
2 * 0.75 = 1.5
### Sleeping
To simulate sleeping by preventing all player movement, this can be done with this easy trick:
```
playerphysics.add_physics_factor(player, "speed", "sleeping", 0)
playerphysics.add_physics_factor(player, "jump", "sleeping", 0)
```
This works regardless of the other factors because 0 times anything equals 0.
## License
This mod is free software, released under the MIT License.

View File

@ -0,0 +1 @@
This mod makes it possible for multiple mods to modify player physics (speed, jumping strength, gravity) without conflict.

View File

@ -0,0 +1,43 @@
playerphysics = {}
local function calculate_attribute_product(player, attribute)
local a = minetest.deserialize(player:get_attribute("playerphysics:physics"))
local product = 1
if a == nil or a[attribute] == nil then
return product
end
local factors = a[attribute]
if type(factors) == "table" then
for _, factor in pairs(factors) do
product = product * factor
end
end
return product
end
function playerphysics.add_physics_factor(player, attribute, id, value)
local a = minetest.deserialize(player:get_attribute("playerphysics:physics"))
if a == nil then
a = { [attribute] = { [id] = value } }
elseif a[attribute] == nil then
a[attribute] = { [id] = value }
else
a[attribute][id] = value
end
player:set_attribute("playerphysics:physics", minetest.serialize(a))
local raw_value = calculate_attribute_product(player, attribute)
player:set_physics_override({[attribute] = raw_value})
end
function playerphysics.remove_physics_factor(player, attribute, id)
local a = minetest.deserialize(player:get_attribute("playerphysics:physics"))
if a == nil or a[attribute] == nil then
-- Nothing to remove
return
else
a[attribute][id] = nil
end
player:set_attribute("playerphysics:physics", minetest.serialize(a))
local raw_value = calculate_attribute_product(player, attribute)
player:set_physics_override({[attribute] = raw_value})
end

View File

@ -0,0 +1 @@
name = playerphysics

View File

@ -28,7 +28,7 @@ function rcbows.spawn_arrow(user, strength, itemstack)
return true return true
end end
function rcbows.launch_arrow(user, user_pos, name, def, itemstack) function rcbows.launch_arrow(user, name, def, itemstack)
if not rcbows.spawn_arrow(user, def.strength, itemstack) then --throw arrow (spawn arrow entity) if not rcbows.spawn_arrow(user, def.strength, itemstack) then --throw arrow (spawn arrow entity)
return -- something failed return -- something failed
end end
@ -74,7 +74,7 @@ function rcbows.register_bow(name, def)
assert(type(def.strength) == "number") assert(type(def.strength) == "number")
assert(def.uses > 0) assert(def.uses > 0)
local function reload_bow(itemstack, user) local function reload_bow(itemstack, user, pointed_thing)
local inv = user:get_inventory() local inv = user:get_inventory()
local arrow, inventory_arrows, inventory_arrow, inv_arrow_name local arrow, inventory_arrows, inventory_arrow, inv_arrow_name
local inv_list = inv:get_list("main") local inv_list = inv:get_list("main")
@ -160,7 +160,7 @@ function rcbows.register_bow(name, def)
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
return rcbows.launch_arrow(user, user_pos, name, def, itemstack) return rcbows.launch_arrow(user, name, def, itemstack)
end, end,
on_secondary_use = function(itemstack, user, pointed_thing) --viewfinder on_secondary_use = function(itemstack, user, pointed_thing) --viewfinder

19
mods/swaz/.luacheckrc Normal file
View File

@ -0,0 +1,19 @@
unused_args = false
allow_defined_top = true
globals = {
"minetest",
"mobkit"
}
read_globals = {
string = {fields = {"split"}},
table = {fields = {"copy", "getn"}},
-- Builtin
"vector", "ItemStack",
"dump", "DIR_DELIM", "VoxelArea", "Settings",
-- MTG
"default", "sfinv", "creative",
}

View File

@ -1,7 +1,5 @@
local modname = "swaz"
local modpath = minetest.get_modpath(modname)
-- internationalization boilerplate
local S = minetest.get_translator(minetest.get_current_modname()) local S = minetest.get_translator(minetest.get_current_modname())
local mg_name = minetest.get_mapgen_setting("mg_name")
-- Register Biomes -- Register Biomes
@ -512,7 +510,6 @@ if mg_name ~= "v6" and mg_name ~= "singlenode" then
sidelen = 16, sidelen = 16,
fill_ratio = 0.008, fill_ratio = 0.008,
biomes = {"swampz"}, biomes = {"swampz"},
sidelen = 16,
noise_params = { noise_params = {
offset = 0.05, offset = 0.05,
scale = 0.008, scale = 0.008,
@ -534,7 +531,6 @@ if mg_name ~= "v6" and mg_name ~= "singlenode" then
sidelen = 16, sidelen = 16,
fill_ratio = 0.008, fill_ratio = 0.008,
biomes = {"swampz"}, biomes = {"swampz"},
sidelen = 16,
noise_params = { noise_params = {
offset = 0.005, offset = 0.005,
scale = 0.008, scale = 0.008,