diff --git a/doc/en/scripting/builtins/libinventory.md b/doc/en/scripting/builtins/libinventory.md index 344840f1..ccb7be20 100644 --- a/doc/en/scripting/builtins/libinventory.md +++ b/doc/en/scripting/builtins/libinventory.md @@ -55,8 +55,21 @@ inventory.create(size: int) -> int -- Create inventory copy. Returns the created copy ID. inventory.clone(invid: int) -> int --- Move item from slotA of invA to slotB of invB. +-- Move an item from slotA of invA to slotB of invB. -- invA may be the same as invB. -- If slotB will be chosen automaticly if argument is not specified. +-- The move may be incomplete if the available slot has no enough stack space. inventory.move(invA: int, slotA: int, invB: int, slotB: int) + +-- Moves an item from slotA of inventory invA to a suitable slot(s) +-- in the specified range of inventory invB. +-- invA may be the same as invB. +-- The move may be incomplete if the available slots are filled. +inventory.move( + invA: int, + slotA: int, + invB: int, + rangeBegin: int, + [optional] rangeEnd: int +) ``` diff --git a/doc/en/xml-ui-layouts.md b/doc/en/xml-ui-layouts.md index 788814e5..d598faa2 100644 --- a/doc/en/xml-ui-layouts.md +++ b/doc/en/xml-ui-layouts.md @@ -142,6 +142,8 @@ Element must be in direct sub-element of *inventory*. - `sharefunc` - Lua event called on LMB + Shift. Inventory id and slot index passed as arguments. - `updatefunc` - Lua event called on slot content update.Inventory id and slot index passed as arguments. - `onrightclick` - Lua event called on RMB click. Inventory id and slot index passed as arguments. +- `taking` - the ability to take an item from a slot. +- `placing` - the ability to put an item in a slot. ## *slots-grid* @@ -154,4 +156,5 @@ Element must be in direct sub-element of *inventory*. - `sharefunc` - Lua event called on LMB + Shift. Inventory id and slot index passed as arguments. - `updatefunc` - Lua event called on slot content update.Inventory id and slot index passed as arguments. - `onrightclick` - Lua event called on RMB click. Inventory id and slot index passed as arguments. - +- `taking` - the ability to take an item from a slot. +- `placing` - the ability to put an item in a slot. diff --git a/doc/ru/scripting/builtins/libinventory.md b/doc/ru/scripting/builtins/libinventory.md index 01ecc5cc..7f3cf26e 100644 --- a/doc/ru/scripting/builtins/libinventory.md +++ b/doc/ru/scripting/builtins/libinventory.md @@ -66,5 +66,20 @@ inventory.clone(invid: int) -> int -- Перемещает предмет из slotA инвентаря invA в slotB инвентаря invB. -- invA и invB могут указывать на один инвентарь. -- slotB будет выбран автоматически, если не указывать явно. +-- Перемещение может быть неполным, если стек слота заполнится. inventory.move(invA: int, slotA: int, invB: int, slotB: int) + +-- Перемещает предмет из slotA инвентаря invA в подходящий слот, находящийся в +-- указанном отрезке инвентаря invB. +-- invA и invB могут указывать на один инвентарь. +-- rangeBegin - начало отрезка. +-- rangeEnd - конец отрезка. +-- Перемещение может быть неполным, если доступные слоты будут заполнены. +inventory.move_range( + invA: int, + slotA: int, + invB: int, + rangeBegin: int, + [опционально] rangeEnd: int +) ``` diff --git a/doc/ru/xml-ui-layouts.md b/doc/ru/xml-ui-layouts.md index 28777950..f4502a94 100644 --- a/doc/ru/xml-ui-layouts.md +++ b/doc/ru/xml-ui-layouts.md @@ -143,6 +143,8 @@ - `sharefunc` - lua событие вызываемое при использовании ЛКМ + Shift. Передается id инвентаря и индекс слота - `updatefunc` - lua событие вызываемое при изменении содержимого слота - `onrightclick` - lua событие вызываемое при использовании ПКМ. Передается id инвентаря и индекс слота +- `taking` - возможность взять предмет из слота. +- `placing` - возможность положить предмет в слот. ## Сетка слотов - *slots-grid* @@ -156,3 +158,5 @@ - `sharefunc` - lua событие вызываемое при использовании ЛКМ + Shift. Передается id инвентаря и индекс слота - `updatefunc` - lua событие вызываемое при изменении содержимого слота - `onrightclick` - lua событие вызываемое при использовании ПКМ. Передается id инвентаря и индекс слота +- `taking` - возможность взять предмет из слота. +- `placing` - возможность положить предмет в слот. diff --git a/res/content/base/blocks/bazalt.json b/res/content/base/blocks/bazalt.json index 94afd36e..bb941a81 100644 --- a/res/content/base/blocks/bazalt.json +++ b/res/content/base/blocks/bazalt.json @@ -1,4 +1,4 @@ { "texture": "bazalt", "breakable": false -} \ No newline at end of file +} diff --git a/res/content/base/blocks/blue_lamp.json b/res/content/base/blocks/blue_lamp.json index cfded63b..88437145 100644 --- a/res/content/base/blocks/blue_lamp.json +++ b/res/content/base/blocks/blue_lamp.json @@ -2,5 +2,6 @@ "texture": "blue_lamp", "emission": [0, 0, 15], "shadeless": true, - "material": "base:glass" + "material": "base:glass", + "base:durability": 0.3 } diff --git a/res/content/base/blocks/brick.json b/res/content/base/blocks/brick.json index e20d9e1d..3b4ecabf 100644 --- a/res/content/base/blocks/brick.json +++ b/res/content/base/blocks/brick.json @@ -1,3 +1,4 @@ { - "texture": "brick" -} \ No newline at end of file + "texture": "brick", + "base:durability": 10.5 +} diff --git a/res/content/base/blocks/coal_ore.json b/res/content/base/blocks/coal_ore.json index 23c050c6..c73998ec 100644 --- a/res/content/base/blocks/coal_ore.json +++ b/res/content/base/blocks/coal_ore.json @@ -1,3 +1,4 @@ { - "texture": "coal_ore" + "texture": "coal_ore", + "base:durability": 16.0 } diff --git a/res/content/base/blocks/dirt.json b/res/content/base/blocks/dirt.json index 81453c4b..ff512254 100644 --- a/res/content/base/blocks/dirt.json +++ b/res/content/base/blocks/dirt.json @@ -1,5 +1,6 @@ { "texture": "dirt", "material": "base:ground", - "surface-replacement": "base:grass_block" + "surface-replacement": "base:grass_block", + "base:durability": 1.0 } diff --git a/res/content/base/blocks/flower.json b/res/content/base/blocks/flower.json index db0609f8..94c06903 100644 --- a/res/content/base/blocks/flower.json +++ b/res/content/base/blocks/flower.json @@ -7,5 +7,6 @@ "replaceable": true, "grounded": true, "model": "X", - "hitbox": [0.15, 0.0, 0.15, 0.7, 0.7, 0.7] + "hitbox": [0.15, 0.0, 0.15, 0.7, 0.7, 0.7], + "base:durability": 0.0 } diff --git a/res/content/base/blocks/glass.json b/res/content/base/blocks/glass.json index 9bd4f021..77f1e3f7 100644 --- a/res/content/base/blocks/glass.json +++ b/res/content/base/blocks/glass.json @@ -4,5 +4,6 @@ "draw-group": 2, "light-passing": true, "sky-light-passing": true, - "translucent": true + "translucent": true, + "base:durability": 0.36 } diff --git a/res/content/base/blocks/grass.json b/res/content/base/blocks/grass.json index 59388ee5..7308d1a1 100644 --- a/res/content/base/blocks/grass.json +++ b/res/content/base/blocks/grass.json @@ -8,5 +8,6 @@ "replaceable": true, "grounded": true, "model": "X", - "hitbox": [0.15, 0.0, 0.15, 0.7, 0.7, 0.7] + "hitbox": [0.15, 0.0, 0.15, 0.7, 0.7, 0.7], + "base:durability": 0.0 } diff --git a/res/content/base/blocks/grass_block.json b/res/content/base/blocks/grass_block.json index c0f6fa48..a6087afc 100644 --- a/res/content/base/blocks/grass_block.json +++ b/res/content/base/blocks/grass_block.json @@ -7,5 +7,6 @@ "grass_top", "grass_side", "grass_side" - ] -} \ No newline at end of file + ], + "base:durability": 1.3 +} diff --git a/res/content/base/blocks/green_lamp.json b/res/content/base/blocks/green_lamp.json index 55264976..b28cae0d 100644 --- a/res/content/base/blocks/green_lamp.json +++ b/res/content/base/blocks/green_lamp.json @@ -2,5 +2,6 @@ "texture": "green_lamp", "emission": [0, 15, 0], "shadeless": true, - "material": "base:glass" + "material": "base:glass", + "base:durability": 0.3 } diff --git a/res/content/base/blocks/ice.json b/res/content/base/blocks/ice.json index 19d9af12..c25c12d3 100644 --- a/res/content/base/blocks/ice.json +++ b/res/content/base/blocks/ice.json @@ -3,5 +3,6 @@ "material": "base:glass", "draw-group": 4, "light-passing": true, - "translucent": true + "translucent": true, + "base:durability": 0.3 } diff --git a/res/content/base/blocks/lamp.json b/res/content/base/blocks/lamp.json index 7d79c1a1..4a1f1ce7 100644 --- a/res/content/base/blocks/lamp.json +++ b/res/content/base/blocks/lamp.json @@ -1,5 +1,6 @@ { "texture": "lamp", "emission": [15, 14, 13], - "shadeless": true + "shadeless": true, + "base:durability": 0.3 } diff --git a/res/content/base/blocks/leaves.json b/res/content/base/blocks/leaves.json index d8731480..cdf9f014 100644 --- a/res/content/base/blocks/leaves.json +++ b/res/content/base/blocks/leaves.json @@ -1,4 +1,5 @@ { "texture": "leaves", - "material": "base:grass" -} \ No newline at end of file + "material": "base:grass", + "base:durability": 0.7 +} diff --git a/res/content/base/blocks/lightbulb.json b/res/content/base/blocks/lightbulb.json index 7a1ca235..ae06aeab 100644 --- a/res/content/base/blocks/lightbulb.json +++ b/res/content/base/blocks/lightbulb.json @@ -8,5 +8,6 @@ "light-passing": true, "sky-light-passing": true, "shadeless": true, - "material": "base:glass" + "material": "base:glass", + "base:durability": 0.2 } diff --git a/res/content/base/blocks/metal.json b/res/content/base/blocks/metal.json index c52d79a2..40542be1 100644 --- a/res/content/base/blocks/metal.json +++ b/res/content/base/blocks/metal.json @@ -1,4 +1,5 @@ { "texture": "metal", - "material": "base:metal" + "material": "base:metal", + "base:durability": 10.0 } diff --git a/res/content/base/blocks/pane.json b/res/content/base/blocks/pane.json index 0eebec49..f3dcf93a 100644 --- a/res/content/base/blocks/pane.json +++ b/res/content/base/blocks/pane.json @@ -12,5 +12,6 @@ "hitbox": [0.0, 0.0, 0.0, 1.0, 1.0, 0.2], "light-passing": true, "sky-light-passing": true, - "rotation": "pane" + "rotation": "pane", + "base:durability": 2.5 } diff --git a/res/content/base/blocks/pipe.json b/res/content/base/blocks/pipe.json index ad297987..b3eb2f25 100644 --- a/res/content/base/blocks/pipe.json +++ b/res/content/base/blocks/pipe.json @@ -11,5 +11,6 @@ "hitbox": [0.25, 0.0, 0.25, 0.5, 1.0, 0.5], "light-passing": true, "rotation": "pipe", - "material": "base:metal" + "material": "base:metal", + "base:durability": 4.7 } diff --git a/res/content/base/blocks/planks.json b/res/content/base/blocks/planks.json index 508fac23..28e80486 100644 --- a/res/content/base/blocks/planks.json +++ b/res/content/base/blocks/planks.json @@ -1,4 +1,5 @@ { "texture": "planks", - "material": "base:wood" -} \ No newline at end of file + "material": "base:wood", + "base:durability": 5.0 +} diff --git a/res/content/base/blocks/red_lamp.json b/res/content/base/blocks/red_lamp.json index 06617a21..ab1a6d15 100644 --- a/res/content/base/blocks/red_lamp.json +++ b/res/content/base/blocks/red_lamp.json @@ -2,5 +2,6 @@ "texture": "red_lamp", "emission": [15, 0, 0], "shadeless": true, - "material": "base:glass" + "material": "base:glass", + "base:durability": 0.3 } diff --git a/res/content/base/blocks/rust.json b/res/content/base/blocks/rust.json index 90e19363..20a8e684 100644 --- a/res/content/base/blocks/rust.json +++ b/res/content/base/blocks/rust.json @@ -1,4 +1,5 @@ { "texture": "rust", - "material": "base:metal" + "material": "base:metal", + "base:durability": 6.6 } diff --git a/res/content/base/blocks/sand.json b/res/content/base/blocks/sand.json index 08a7d4f4..97b4cd02 100644 --- a/res/content/base/blocks/sand.json +++ b/res/content/base/blocks/sand.json @@ -1,4 +1,5 @@ { "texture": "sand", - "material": "base:sand" -} \ No newline at end of file + "material": "base:sand", + "base:durability": 0.7 +} diff --git a/res/content/base/blocks/stone.json b/res/content/base/blocks/stone.json index 3fab36ef..3bd8f6c8 100644 --- a/res/content/base/blocks/stone.json +++ b/res/content/base/blocks/stone.json @@ -1,3 +1,4 @@ { - "texture": "stone" -} \ No newline at end of file + "texture": "stone", + "base:durability": 12.0 +} diff --git a/res/content/base/blocks/torch.json b/res/content/base/blocks/torch.json index 47f02790..cf26bfec 100644 --- a/res/content/base/blocks/torch.json +++ b/res/content/base/blocks/torch.json @@ -31,5 +31,6 @@ "particles:smoke_0", "particles:smoke_1" ] - } + }, + "base:durability": 0.1 } diff --git a/res/content/base/blocks/wood.json b/res/content/base/blocks/wood.json index db77a6bc..0719e060 100644 --- a/res/content/base/blocks/wood.json +++ b/res/content/base/blocks/wood.json @@ -8,5 +8,6 @@ "wood", "wood" ], - "rotation": "pipe" -} \ No newline at end of file + "rotation": "pipe", + "base:durability": 6.0 +} diff --git a/res/content/base/blocks/wooden_door.json b/res/content/base/blocks/wooden_door.json index 59d192b5..8b2103bc 100644 --- a/res/content/base/blocks/wooden_door.json +++ b/res/content/base/blocks/wooden_door.json @@ -14,5 +14,6 @@ "rotation": "pane", "model": "aabb", "hitbox": [0.0, 0.0, 0.8, 1.0, 2.0, 0.2], - "ambient-occlusion": false + "ambient-occlusion": false, + "base:durability": 5.9 } diff --git a/res/content/base/config/user-props.toml b/res/content/base/config/user-props.toml new file mode 100644 index 00000000..b7306ba1 --- /dev/null +++ b/res/content/base/config/user-props.toml @@ -0,0 +1 @@ +"base:durability" = {} diff --git a/res/content/base/entities/drop.json b/res/content/base/entities/drop.json index 9577eb7e..4c5e064f 100644 --- a/res/content/base/entities/drop.json +++ b/res/content/base/entities/drop.json @@ -4,7 +4,7 @@ ], "hitbox": [0.4, 0.25, 0.4], "sensors": [ - ["aabb", -0.2, -0.2, -0.2, 0.2, 0.2, 0.2], + ["radius", 0.3], ["radius", 1.6] ], "blocking": false diff --git a/res/content/base/modules/util.lua b/res/content/base/modules/util.lua new file mode 100644 index 00000000..a4519b53 --- /dev/null +++ b/res/content/base/modules/util.lua @@ -0,0 +1,11 @@ +local base_entities = {} + +function base_entities.drop(ppos, itemid, count, pickup_delay) + return entities.spawn("base:drop", ppos, {base__drop={ + id=itemid, + count=count, + pickup_delay=pickup_delay + }}) +end + +return base_entities diff --git a/res/content/base/scripts/components/drop.lua b/res/content/base/scripts/components/drop.lua index 195c5270..12e16265 100644 --- a/res/content/base/scripts/components/drop.lua +++ b/res/content/base/scripts/components/drop.lua @@ -3,10 +3,13 @@ local body = entity.rigidbody local rig = entity.skeleton inair = true -ready = false target = -1 +timer = 0.3 local dropitem = ARGS +if dropitem then + timer = dropitem.pickup_delay or timer +end if SAVED_DATA.item then dropitem.id = item.index(SAVED_DATA.item) dropitem.count = SAVED_DATA.count @@ -40,7 +43,6 @@ function on_grounded(force) mat4.scale(matrix, scale, matrix) rig:set_matrix(0, matrix) inair = false - ready = true end function on_fall() @@ -50,12 +52,12 @@ end function on_sensor_enter(index, oid) local playerid = hud.get_player() local playerentity = player.get_entity(playerid) - if ready and oid == playerentity and index == 0 then + if timer < 0.0 and oid == playerentity and index == 0 then entity:despawn() inventory.add(player.get_inventory(playerid), dropitem.id, dropitem.count) audio.play_sound_2d("events/pickup", 0.5, 0.8+math.random()*0.4, "regular") end - if index == 1 and ready and oid == playerentity then + if index == 1 and oid == playerentity then target = oid end end @@ -80,8 +82,12 @@ function on_render() end end -function on_update() +function on_update(tps) + timer = timer - 1.0/tps if target ~= -1 then + if timer > 0.0 then + return + end local dir = vec3.sub(entities.get(target).transform:get_pos(), tsf:get_pos()) vec3.normalize(dir, dir) vec3.mul(dir, 10.0, dir) diff --git a/res/content/base/scripts/hud.lua b/res/content/base/scripts/hud.lua index 694ff847..31125631 100644 --- a/res/content/base/scripts/hud.lua +++ b/res/content/base/scripts/hud.lua @@ -1,3 +1,5 @@ +local base_util = require "util" + local DROP_FORCE = 8 local DROP_INIT_VEL = {0, 3, 0} @@ -17,10 +19,7 @@ function on_hud_open() local pvel = {player.get_vel(pid)} local ppos = vec3.add({player.get_pos(pid)}, {0, 0.7, 0}) local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE) - local drop = entities.spawn("base:drop", ppos, {base__drop={ - id=itemid, - count=1 - }}) + local drop = base_util.drop(ppos, itemid, 1, 1.5) local velocity = vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)) drop.rigidbody:set_vel(velocity) end) diff --git a/res/content/base/textures/blocks/grass.png b/res/content/base/textures/blocks/grass.png index d43769ca..98dbda01 100644 Binary files a/res/content/base/textures/blocks/grass.png and b/res/content/base/textures/blocks/grass.png differ diff --git a/res/content/base/textures/cracks/cracks_0.png b/res/content/base/textures/cracks/cracks_0.png index 84d56c43..b8dd094e 100644 Binary files a/res/content/base/textures/cracks/cracks_0.png and b/res/content/base/textures/cracks/cracks_0.png differ diff --git a/res/content/base/textures/cracks/cracks_1.png b/res/content/base/textures/cracks/cracks_1.png index 40bd0ce8..8d0eacb8 100644 Binary files a/res/content/base/textures/cracks/cracks_1.png and b/res/content/base/textures/cracks/cracks_1.png differ diff --git a/res/content/base/textures/cracks/cracks_10.png b/res/content/base/textures/cracks/cracks_10.png index 8253dd6d..3fccd3a2 100644 Binary files a/res/content/base/textures/cracks/cracks_10.png and b/res/content/base/textures/cracks/cracks_10.png differ diff --git a/res/content/base/textures/cracks/cracks_2.png b/res/content/base/textures/cracks/cracks_2.png index d13052d2..dcfba20d 100644 Binary files a/res/content/base/textures/cracks/cracks_2.png and b/res/content/base/textures/cracks/cracks_2.png differ diff --git a/res/content/base/textures/cracks/cracks_3.png b/res/content/base/textures/cracks/cracks_3.png index 40275992..cfb98594 100644 Binary files a/res/content/base/textures/cracks/cracks_3.png and b/res/content/base/textures/cracks/cracks_3.png differ diff --git a/res/content/base/textures/cracks/cracks_4.png b/res/content/base/textures/cracks/cracks_4.png index ced0d189..efd9e4ab 100644 Binary files a/res/content/base/textures/cracks/cracks_4.png and b/res/content/base/textures/cracks/cracks_4.png differ diff --git a/res/content/base/textures/cracks/cracks_5.png b/res/content/base/textures/cracks/cracks_5.png index 3db95bf4..bbe1a6c6 100644 Binary files a/res/content/base/textures/cracks/cracks_5.png and b/res/content/base/textures/cracks/cracks_5.png differ diff --git a/res/content/base/textures/cracks/cracks_6.png b/res/content/base/textures/cracks/cracks_6.png index 1eda5a64..29c14e6b 100644 Binary files a/res/content/base/textures/cracks/cracks_6.png and b/res/content/base/textures/cracks/cracks_6.png differ diff --git a/res/content/base/textures/cracks/cracks_7.png b/res/content/base/textures/cracks/cracks_7.png index a9b9092d..0b3ca2d1 100644 Binary files a/res/content/base/textures/cracks/cracks_7.png and b/res/content/base/textures/cracks/cracks_7.png differ diff --git a/res/content/base/textures/cracks/cracks_8.png b/res/content/base/textures/cracks/cracks_8.png index 79669ab1..cb22e506 100644 Binary files a/res/content/base/textures/cracks/cracks_8.png and b/res/content/base/textures/cracks/cracks_8.png differ diff --git a/res/content/base/textures/cracks/cracks_9.png b/res/content/base/textures/cracks/cracks_9.png index 18eb1a53..5ff395d6 100644 Binary files a/res/content/base/textures/cracks/cracks_9.png and b/res/content/base/textures/cracks/cracks_9.png differ diff --git a/res/layouts/console.xml.lua b/res/layouts/console.xml.lua index 7d4c2771..11d7bd14 100644 --- a/res/layouts/console.xml.lua +++ b/res/layouts/console.xml.lua @@ -84,13 +84,11 @@ events.on("core:open_traceback", function(traceback_b64) framestr = framestr.."("..tostring(frame.name)..")" end local color = "#FFFFFF" - if frame.source:starts_with("core:") then - color = "#C0D0C5" - end tb_list:add(gui.template("stack_frame", { location=framestr, color=color, - callback=callback + callback=callback, + enabled=file.exists(frame.source) })) end tb_list.size = srcsize diff --git a/res/layouts/inventory.xml.lua b/res/layouts/inventory.xml.lua index c2280f15..9f836223 100644 --- a/res/layouts/inventory.xml.lua +++ b/res/layouts/inventory.xml.lua @@ -2,7 +2,11 @@ function inventory_share_func(invid, slotid) local blockinv = hud.get_block_inventory() if blockinv ~= 0 then inventory.move(invid, slotid, blockinv) - else + elseif rules.get("allow-content-access") then inventory.set(invid, slotid, 0, 0) + elseif slotid < 10 then + inventory.move_range(invid, slotid, invid, 10) + else + inventory.move_range(invid, slotid, invid, 0, 9) end end diff --git a/res/layouts/templates/stack_frame.xml b/res/layouts/templates/stack_frame.xml index c73890bb..16f2571c 100644 --- a/res/layouts/templates/stack_frame.xml +++ b/res/layouts/templates/stack_frame.xml @@ -1,3 +1,3 @@ -