Merge remote-tracking branch 'origin/testing' into compatibility

This commit is contained in:
kay27 2022-02-09 16:52:01 +04:00
commit 148ecdf29f
12 changed files with 232 additions and 71 deletions

View File

@ -27,6 +27,11 @@ local mcl_item_entity = {}
local item_drop_settings = {} --settings table
item_drop_settings.dug_buffer = 0.65 -- the warm up period before a dug item can be collected
item_drop_settings.age = 1.0 --how old a dropped item (_insta_collect==false) has to be before collecting
item_drop_settings.fluid_flow_rate = 1.39 --the speed of a flowing fluid, used when computing push and drag forces of water on items; default is tuned to Minecraft
item_drop_settings.fluid_drag = 1.8 --how much drag water has on items (how quickly an item's motion will settle onto the water's flow speed)
item_drop_settings.ground_drag = 3.0 --how much friction with the ground slows items sliding on it
item_drop_settings.slippery_drag_factor = 0.25 --scales item friction with the ground on slippery floors (e.g. ice)
item_drop_settings.slippery_fluid_drag_factor = 0.4 --scales item drag with waterflow on slippery floors (e.g. ice)
item_drop_settings.radius_magnet = 2.0 --radius of item magnet. MUST BE LARGER THAN radius_collect!
item_drop_settings.xp_radius_magnet = 7.25 --radius of xp magnet. MUST BE LARGER THAN radius_collect!
item_drop_settings.radius_collect = 0.2 --radius of collection
@ -780,11 +785,35 @@ minetest.register_entity(":__builtin:item", {
-- Just to make sure we don't manipulate the speed for no reason
if vec.x ~= 0 or vec.y ~= 0 or vec.z ~= 0 then
-- Minecraft Wiki: Flowing speed is "about 1.39 meters per second"
local f = 1.39
-- Set new item moving speed into the direciton of the liquid
local newv = vector.multiply(vec, f)
local f = item_drop_settings.fluid_flow_rate --1.39
-- Apply the force of the flowing liquid onto the item's velocity
local newv = vector.multiply(vec, f)
self.object:set_acceleration({x = 0, y = 0, z = 0})
self.object:set_velocity({x = newv.x, y = -0.22, z = newv.z})
local oldvel = self.object:get_velocity() -- v is vector, vel is velocity
-- drag
local fluid_drag = item_drop_settings.fluid_drag
local floornn = minetest.get_node({x=p.x, y=p.y-0.5, z=p.z}).name
local floornode = floornn and minetest.registered_nodes[floornn]
if floornode and minetest.get_item_group(floornode.name, "slippery") then
-- scale fluid drag on slippery floors
fluid_drag = fluid_drag * item_drop_settings.slippery_fluid_drag_factor
end
newv.x = newv.x - (oldvel.x - newv.x) * fluid_drag * dtime
newv.y = newv.y - (oldvel.y - newv.y) * fluid_drag * dtime
newv.z = newv.z - (oldvel.z - newv.z) * fluid_drag * dtime
newv.y = newv.y + -0.22 -- (keep slight downward thrust from previous version of code)
-- NOTE: is there any particular reason we have this, anyway?
-- since fluid drag is now on, we could as well just
-- apply gravity here; drag will slow down the fall
-- realistically
self.object:set_velocity({x = oldvel.x + newv.x * dtime, y = oldvel.y + newv.y * dtime, z = oldvel.z + newv.z * dtime})
self.physical_state = true
self._flowing = true
@ -796,15 +825,17 @@ minetest.register_entity(":__builtin:item", {
elseif self._flowing == true then
-- Disable flowing physics if not on/in flowing liquid
self._flowing = false
enable_physics(self.object, self, true)
--enable_physics(self.object, self, true) -- do not reset velocity upon leaving water!
self.object:set_acceleration({x=0,y=-get_gravity(),z=0}) -- resume applying gravity
return
end
-- If node is not registered or node is walkably solid and resting on nodebox
local nn = minetest.get_node({x=p.x, y=p.y-0.5, z=p.z}).name
local v = self.object:get_velocity()
local node = nn and minetest.registered_nodes[nn]
if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable and v.y == 0 then
if not node or node.walkable and v.y == 0 then
if self.physical_state then
local own_stack = ItemStack(self.object:get_luaentity().itemstring)
-- Merge with close entities of the same item
@ -817,7 +848,28 @@ minetest.register_entity(":__builtin:item", {
end
end
end
disable_physics(self.object, self)
--disable_physics(self.object, self)
-- apply ground drag
local oldvel = self.object:get_velocity()
-- ignore momentum if it's tiny
if math.abs(oldvel.x) < 0.05 and math.abs(oldvel.z) < 0.05 then
disable_physics(self.object, self)
return
end
local ground_drag = item_drop_settings.ground_drag
if node and minetest.get_item_group(node.name, "slippery") ~= 0 then
ground_drag = ground_drag * item_drop_settings.slippery_drag_factor
end
local newvel = {
x = oldvel.x - oldvel.x * ground_drag * dtime,
y = 0,
z = oldvel.z - oldvel.z * ground_drag * dtime
}
self.object:set_velocity(newvel)
end
else
if self._magnet_active == false then

View File

@ -260,9 +260,22 @@ local dispenserdef = {
end
else
-- Drop item otherwise
minetest.add_item(droppos, dropitem)
stack:take_item()
inv:set_stack("main", stack_id, stack)
-- Drop item normally
local dropitemobj = minetest.add_item(droppos, dropitem)
stack:take_item()
inv:set_stack("main", stack_id, stack)
-- Set item velocity (overrides the default random drop direction)
local shoot_force = 1.3
local newv = minetest.facedir_to_dir(node.param2)
newv = {
x = newv.x * shoot_force,
y = newv.y * shoot_force,
z = newv.z * shoot_force
}
dropitemobj:set_velocity(newv)
end
end

View File

@ -134,9 +134,21 @@ local dropperdef = {
-- No container?
if not dropped and not dropnodedef.groups.container then
-- Drop item normally
minetest.add_item(droppos, dropitem)
local dropitemobj = minetest.add_item(droppos, dropitem)
stack:take_item()
inv:set_stack("main", stack_id, stack)
-- Set item velocity (overrides the default random drop direction)
local shoot_force = 1.3
local newv = minetest.facedir_to_dir(node.param2)
newv = {
x = -newv.x * shoot_force,
y = -newv.y * shoot_force,
z = -newv.z * shoot_force
}
dropitemobj:set_velocity(newv)
end
end
end,

View File

@ -1,4 +1,6 @@
local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape
local C = minetest.colorize
local mod_doc = minetest.get_modpath("doc")
-- Chest Entity
@ -174,7 +176,7 @@ end]]
local function player_chest_open(player, pos, node_name, textures, param2, double, sound, mesh, shulker)
local name = player:get_player_name()
open_chests[name] = {pos = pos, node_name = node_name, textures = textures, param2 = param2, double = double, sound = sound, mesh = mesh, shulker = shulker}
if animate_chests then
if animate_chests and not string.find(node_name, "barrel") then
local dir = minetest.facedir_to_dir(param2)
find_or_create_entity(pos, node_name, textures, param2, double, sound, mesh, shulker and "shulker" or "chest", dir):open(name)
end
@ -226,6 +228,8 @@ local function chest_update_after_close(pos)
minetest.swap_node(pos_other, {name="mcl_chests:trapped_chest_left", param2 = node.param2})
find_or_create_entity(pos_other, "mcl_chests:trapped_chest_left", {"mcl_chests_trapped_double.png"}, node.param2, true, "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_left")
mesecon.receptor_off(pos_other, trapped_chest_mesecons_rules)
elseif node.name == "mcl_chests:barrel_open" then
minetest.swap_node(pos, {name = "mcl_chests:barrel", param2 = node.param2})
end
end
@ -236,7 +240,7 @@ local function player_chest_close(player)
if open_chest == nil then
return
end
if animate_chests then
if animate_chests and not string.find(open_chest.node_name, "barrel") then
find_or_create_entity(open_chest.pos, open_chest.node_name, open_chest.textures, open_chest.param2, open_chest.double, open_chest.sound, open_chest.mesh, open_chest.shulker and "shulker" or "chest"):close(name)
end
chest_update_after_close(open_chest.pos)
@ -291,27 +295,40 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile
end
end
local function drop_items_chest(pos, oldnode, oldmetadata)
local meta = minetest.get_meta(pos)
local meta2 = meta:to_table()
if oldmetadata then
meta:from_table(oldmetadata)
end
local inv = meta:get_inventory()
for i=1,inv:get_size("main") do
local stack = inv:get_stack("main", i)
if not stack:is_empty() then
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
minetest.add_item(p, stack)
end
end
meta:from_table(meta2)
local function drop_item_stack(pos, stack)
if not stack or stack:is_empty() then return end
local drop_offset = vector.new(math.random() - 0.5, 0, math.random() - 0.5)
minetest.add_item(vector.add(pos, drop_offset), stack)
end
local function on_chest_blast(pos)
local function drop_items_chest(pos, oldnode, oldmetadata, digger)
if oldmetadata and oldmetadata.inventory then
-- process after_dig_node callback
local main = oldmetadata.inventory.main
if not main then return end
for _, stack in pairs(main) do
drop_item_stack(pos, stack)
end
else
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
for i = 1, inv:get_size("main") do
drop_item_stack(pos, inv:get_stack("main", i))
end
meta:from_table()
end
end
local function on_chest_blast(pos, intensity)
local node = minetest.get_node(pos)
drop_items_chest(pos, node)
minetest.remove_node(pos)
-- drop node itself with some probability depended on explosion intensity (1 for TNT):
if math.random(1, math.floor((intensity or 1) * 2)) ~= 1 then return end
local node_def = minetest.registered_nodes[node.name]
if not node_def then return end
local node_name = node_def.drop or node_def.name
drop_item_stack(pos, ItemStack(node_name))
end
local function limit_put_list(stack, list)
@ -478,10 +495,10 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile
minetest.show_formspec(clicker:get_player_name(),
"mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z,
"size[9,8.75]"..
"label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", name)).."]"..
"label[0,0;"..F(C("#313131", name)).."]"..
"list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,0.5,9,3)..
"label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]"..
"label[0,4.0;"..F(C("#313131", S("Inventory"))).."]"..
"list[current_player;main;0,4.5;9,3;9]"..
mcl_formspec.get_itemslot_bg(0,4.5,9,3)..
"list[current_player;main;0,7.74;9,1;]"..
@ -629,12 +646,12 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile
minetest.show_formspec(clicker:get_player_name(),
"mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z,
"size[9,11.5]"..
"label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", name)).."]"..
"label[0,0;"..F(C("#313131", name)).."]"..
"list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,0.5,9,3)..
"list[nodemeta:"..pos_other.x..","..pos_other.y..","..pos_other.z..";main;0,3.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,3.5,9,3)..
"label[0,7;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]"..
"label[0,7;"..F(C("#313131", S("Inventory"))).."]"..
"list[current_player;main;0,7.5;9,3;9]"..
mcl_formspec.get_itemslot_bg(0,7.5,9,3)..
"list[current_player;main;0,10.75;9,1;]"..
@ -777,12 +794,12 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile
"mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z,
"size[9,11.5]"..
"label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", name)).."]"..
"label[0,0;"..F(C("#313131", name)).."]"..
"list[nodemeta:"..pos_other.x..","..pos_other.y..","..pos_other.z..";main;0,0.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,0.5,9,3)..
"list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,3.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,3.5,9,3)..
"label[0,7;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]"..
"label[0,7;"..F(C("#313131", S("Inventory"))).."]"..
"list[current_player;main;0,7.5;9,3;9]"..
mcl_formspec.get_itemslot_bg(0,7.5,9,3)..
"list[current_player;main;0,10.75;9,1;]"..
@ -902,38 +919,6 @@ register_chest("trapped_chest_on",
"trapped_chest"
)
--[[local function close_if_trapped_chest(pos, player)
local node = minetest.get_node(pos)
if node.name == "mcl_chests:trapped_chest_on_small" then
minetest.swap_node(pos, {name="mcl_chests:trapped_chest_small", param2 = node.param2})
find_or_create_entity(pos, "mcl_chests:trapped_chest_small", {"mcl_chests_trapped.png"}, node.param2, false, "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_small")
mesecon.receptor_off(pos, trapped_chest_mesecons_rules)
player_chest_close(player)
elseif node.name == "mcl_chests:trapped_chest_on_left" then
minetest.swap_node(pos, {name="mcl_chests:trapped_chest_left", param2 = node.param2})
find_or_create_entity(pos, "mcl_chests:trapped_chest_left", {"mcl_chests_trapped_double.png"}, node.param2, true, "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_left")
mesecon.receptor_off(pos, trapped_chest_mesecons_rules)
local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "left")
minetest.swap_node(pos_other, {name="mcl_chests:trapped_chest_right", param2 = node.param2})
mesecon.receptor_off(pos_other, trapped_chest_mesecons_rules)
player_chest_close(player)
elseif node.name == "mcl_chests:trapped_chest_on_right" then
minetest.swap_node(pos, {name="mcl_chests:trapped_chest_right", param2 = node.param2})
mesecon.receptor_off(pos, trapped_chest_mesecons_rules)
local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right")
minetest.swap_node(pos_other, {name="mcl_chests:trapped_chest_left", param2 = node.param2})
find_or_create_entity(pos_other, "mcl_chests:trapped_chest_left", {"mcl_chests_trapped_double.png"}, node.param2, true, "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_left")
mesecon.receptor_off(pos_other, trapped_chest_mesecons_rules)
player_chest_close(player)
end
end]]
-- Disable chest when it has been closed
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname:find("mcl_chests:") == 1 then
@ -990,10 +975,10 @@ minetest.register_node("mcl_chests:ender_chest", {
})
local formspec_ender_chest = "size[9,8.75]"..
"label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Ender Chest"))).."]"..
"label[0,0;"..F(C("#313131", S("Ender Chest"))).."]"..
"list[current_player;enderchest;0,0.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,0.5,9,3)..
"label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]"..
"label[0,4.0;"..F(C("#313131", S("Inventory"))).."]"..
"list[current_player;main;0,4.5;9,3;9]"..
mcl_formspec.get_itemslot_bg(0,4.5,9,3)..
"list[current_player;main;0,7.74;9,1;]"..
@ -1125,10 +1110,10 @@ local function formspec_shulker_box(name)
name = S("Shulker Box")
end
return "size[9,8.75]"..
"label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", name)).."]"..
"label[0,0;"..F(C("#313131", name)).."]"..
"list[context;main;0,0.5;9,3;]"..
mcl_formspec.get_itemslot_bg(0,0.5,9,3)..
"label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]"..
"label[0,4.0;"..F(C("#313131", S("Inventory"))).."]"..
"list[current_player;main;0,4.5;9,3;9]"..
mcl_formspec.get_itemslot_bg(0,4.5,9,3)..
"list[current_player;main;0,7.74;9,1;]"..
@ -1436,3 +1421,95 @@ minetest.register_lbm({
minetest.get_meta(pos):set_string("formspec", "")
end,
})
local function barrel_open(pos, node, clicker)
local name = minetest.get_meta(pos):get_string("name")
if name == "" then
name = S("Barrel")
end
local playername = clicker:get_player_name()
minetest.show_formspec(playername,
"mcl_chests:barrel_"..pos.x.."_"..pos.y.."_"..pos.z,
table.concat({
"size[9,8.75]",
"label[0,0;"..F(C("#313131", name)).."]",
"list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]",
mcl_formspec.get_itemslot_bg(0, 0.5, 9, 3),
"label[0,4.0;"..F(C("#313131", S("Inventory"))).."]",
"list[current_player;main;0,4.5;9,3;9]",
mcl_formspec.get_itemslot_bg(0, 4.5, 9, 3),
"list[current_player;main;0,7.74;9,1;]",
mcl_formspec.get_itemslot_bg(0, 7.74, 9, 1),
"listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main]",
"listring[current_player;main]",
})
)
minetest.swap_node(pos, { name = "mcl_chests:barrel_open", param2 = node.param2 })
player_chest_open(clicker, pos, "mcl_chests:barrel")
end
minetest.register_node("mcl_chests:barrel", {
description = S("Barrel"),
_tt_help = S("27 inventory slots"),
_doc_items_longdesc = S("Barrels are containers which provide 27 inventory slots."),
_doc_items_usagehelp = S("To access its inventory, rightclick it. When broken, the items will drop out."),
tiles = {"mcl_barrels_barrel_top.png", "mcl_barrels_barrel_bottom.png", "mcl_barrels_barrel_side.png"},
paramtype = "light",
paramtype2 = "facedir",
on_place = function(itemstack, placer, pointed_thing)
minetest.rotate_and_place(itemstack, placer, pointed_thing, minetest.is_creative_enabled(placer:get_player_name()), {}, false)
return itemstack
end,
stack_max = 64,
sounds = mcl_sounds.node_sound_wood_defaults(),
groups = {handy = 1, axey = 1, container = 2, material_wood = 1, flammable = -1, deco_block = 1},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("main", 9*3)
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name"))
end,
after_dig_node = drop_items_chest,
on_blast = on_blast,
on_rightclick = barrel_open,
on_destruct = close_forms,
_mcl_blast_resistance = 2.5,
_mcl_hardness = 2.5,
})
minetest.register_node("mcl_chests:barrel_open", {
description = S("Barrel Open"),
_tt_help = S("27 inventory slots"),
_doc_items_longdesc = S("Barrels are containers which provide 27 inventory slots."),
_doc_items_usagehelp = S("To access its inventory, rightclick it. When broken, the items will drop out."),
_doc_items_create_entry = false,
tiles = {"mcl_barrels_barrel_top_open.png", "mcl_barrels_barrel_bottom.png", "mcl_barrels_barrel_side.png"},
paramtype = "light",
paramtype2 = "facedir",
drop = "mcl_chests:barrel",
stack_max = 64,
sounds = mcl_sounds.node_sound_wood_defaults(),
groups = {handy = 1, axey = 1, container = 2, material_wood = 1, flammable = -1, deco_block = 1, not_in_creative_inventory = 1},
after_dig_node = drop_items_chest,
on_blast = on_blast,
on_rightclick = barrel_open,
on_destruct = close_forms,
_mcl_blast_resistance = 2.5,
_mcl_hardness = 2.5,
})
--Minecraft Java Edition craft
minetest.register_craft({
output = "mcl_chests:barrel",
recipe = {
{"group:wood", "group:wood_slab", "group:wood"},
{"group:wood", "", "group:wood"},
{"group:wood", "group:wood_slab", "group:wood"},
}
})

View File

@ -34,3 +34,5 @@ Can be combined to a large chest=Peut être combiné à un grand coffre
27 interdimensional inventory slots=27 emplacements d'inventaire interdimensionnels
Put items inside, retrieve them from any ender chest=Mettez des objets à l'intérieur, récupérez-les dans n'importe quel coffre
Emits a redstone signal when opened=Émet un signal redstone à l'ouverture
Barrel=Tonneau
Barrels are containers which provide 27 inventory slots.=Les tonneaux sont des conteneurs qui offrent 27 emplacements d'inventaire.

View File

@ -34,3 +34,5 @@ Can be combined to a large chest=Можно объединить в большо
27 interdimensional inventory slots=27 межпространственных отсеков инвентаря
Put items inside, retrieve them from any ender chest=Положите внутрь предмет и получите его из любого сундука Предела
Emits a redstone signal when opened=Подаёт сигнал редстоуна, будучи открытым
Barrel=Бочка
Barrels are containers which provide 27 inventory slots.=Бочки это хранилища, предоставляющие 27 отсеков инвентаря.

View File

@ -34,3 +34,5 @@ Can be combined to a large chest=
27 interdimensional inventory slots=
Put items inside, retrieve them from any ender chest=
Emits a redstone signal when opened=
Barrel=
Barrels are containers which provide 27 inventory slots.=

View File

@ -1,3 +1,4 @@
name = mcl_chests
author = Wuzzy, Fleckenstein, AFCMS
depends = mcl_init, mcl_formspec, mcl_core, mcl_sounds, mcl_end, mesecons
optional_depends = doc, screwdriver

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 566 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 421 B