17 Commits

Author SHA1 Message Date
4ed6d10a75 Merge remote-tracking branch 'upstream/master' 2025-03-20 11:34:32 +01:00
e77c1e7df1 Merge remote-tracking branch 'upstream/master' 2024-09-15 09:01:18 +02:00
98f364c0cc Merge remote-tracking branch 'upstream/master' 2023-12-13 20:57:58 +01:00
d480fee891 Merge remote-tracking branch 'upstream/master' 2023-06-05 23:34:03 +02:00
f5b2521e4b Merge remote-tracking branch 'upstream/master' 2022-08-26 14:53:49 +02:00
b36dd31f0f Merge remote-tracking branch 'upstream/master' 2021-07-24 13:05:51 +02:00
5a04699b3e Merge remote-tracking branch 'upstream/master' 2021-06-20 17:06:29 +02:00
7a5cc43280 Merge remote-tracking branch 'upstream/master' 2021-04-17 13:45:38 +02:00
327c96cba8 Merge branch 'github' 2021-03-19 22:20:48 +01:00
0aa935c271 Optimize textures to avoid use_texture_alpha warnings 2021-03-19 22:15:45 +01:00
dd8432ef34 Merge remote-tracking branch 'upstream/master' 2021-01-24 12:54:09 +01:00
c3f1b4ef41 Merge remote-tracking branch 'upstream/master' 2021-01-23 12:57:25 +01:00
45991bf124 Merge remote-tracking branch 'upstream/master' 2021-01-19 23:26:45 +01:00
4e6b34da34 Merge remote-tracking branch 'upstream/master' 2020-12-15 23:43:58 +01:00
2800b237c5 Merge remote-tracking branch 'upstream/master' 2020-10-31 12:00:29 +01:00
a6e79e6a25 Merge branch 'master' into nalc-1.2 2019-05-09 21:27:50 +02:00
0b099505eb Ajoute message de chargement du mod dans le journal "action" 2018-12-25 13:54:05 +01:00
7 changed files with 96 additions and 80 deletions

View File

@ -1,19 +1,13 @@
unused_args = false
max_line_length = 111
read_globals = {
"dump",
"core",
"minetest",
"vector",
"ItemStack",
"VoxelArea",
"screwdriver",
"minetest",
"default",
"pipeworks",
"screwdriver",
"dump",
"VoxelArea",
"ItemStack",
}
globals = {

View File

@ -3,11 +3,8 @@ Digilines
[![Build status](https://github.com/minetest-mods/digilines/workflows/build/badge.svg)](https://github.com/minetest-mods/digilines/actions)
![screenshot](screenshot.png)
This Luanti/Minetest mod is a counterpart for bus systems like I2C, SPI, RS232, USB
Engine version 5.5.0+ is required to use this mod.
- The minetest counterpart for bus systems like i2c, SPI, RS232, USB -
- Minetest 5.0.0+ is required to use this mod.
This mod adds digiline wires, an RTC (Real Time Clock), a light sensor as well as an LCD Screen.
Can be used together with the luacontroller from mesecons. See the luacontroller manual for more information.
@ -16,12 +13,5 @@ Send "GET" to RTC or light sensor to retrieve Data, send any text to LCD to disp
Select channel by right-clicking items.
License:
* Code: LGPL
* Textures: WTFPL
Documentation:
* Digiline chest: [docs/](docs/)
* API usage: https://github.com/minetest-mods/digilines/wiki/API-usage
* API examples: https://h2mm.gitlab.io/web/tutorials/digilines.html (external resource)
Code: LGPL
Textures: WTFPL

View File

@ -12,10 +12,6 @@ digilines.mcl = minetest.get_modpath("mcl_core")
if minetest.get_modpath("default") then digilines.sounds = default end
if digilines.mcl then digilines.sounds = mcl_sounds end
-- Show a more helpful error message to the player
assert(digilines.sounds,
"Digilines requires Minetest Game or a VoxeLibre (-compatible) game.")
-- Backwards compatibility code.
-- We define a proxy table whose methods can be called with the
-- `foo:bar` notation, and it will redirect the call to the
@ -107,3 +103,5 @@ end
if minetest.settings:get_bool("digilines_enable_rtc", true) ~= false then
dofile(modpath .. "/rtc.lua")
end
minetest.log("action", "[digilines] loaded.")

View File

@ -1,6 +1,3 @@
assert(core.features.dynamic_add_media_table,
"Digilines requires Luanti/Minetest >= 5.5.0 to work correctly")
local S = digilines.S
local pipeworks_enabled = minetest.get_modpath("pipeworks") ~= nil
@ -26,7 +23,7 @@ local function send_message(pos, action, stack, from_slot, to_slot, side)
end
-- Checks if the inventory has become empty and, if so, sends an empty message.
local function send_empty_if_empty(pos)
local function check_empty(pos)
if minetest.get_meta(pos):get_inventory():is_empty("main") then
send_message(pos, "empty")
end
@ -34,7 +31,7 @@ end
-- Checks if the inventory has become full for a particular type of item and,
-- if so, sends a full message.
local function send_full_if_full(pos, stack)
local function check_full(pos, stack)
local one_item_stack = ItemStack(stack)
one_item_stack:set_count(1)
if not minetest.get_meta(pos):get_inventory():room_for_item("main", one_item_stack) then
@ -45,6 +42,17 @@ end
local tubeconn = pipeworks_enabled and "^pipeworks_tube_connection_wooden.png" or ""
local tubescan = pipeworks_enabled and function(pos) pipeworks.scan_for_tube_objects(pos) end or nil
-- A place to remember things from allow_metadata_inventory_put to
-- on_metadata_inventory_put. This is a hack due to issue
-- minetest/minetest#6534 that should be removed once thats fixed.
local last_inventory_put_index
local last_inventory_put_stack
-- A place to remember things from allow_metadata_inventory_take to
-- tube.remove_items. This is a hack due to issue minetest-mods/pipeworks#205
-- that should be removed once thats fixed.
local last_inventory_take_index
local tube_can_insert = function(pos, _, stack, direction)
local ret = minetest.get_meta(pos):get_inventory():room_for_item("main", stack)
if not ret then
@ -129,7 +137,7 @@ local tube_insert_object = function(pos, _, original_stack, direction)
end
end
if any_put then
send_full_if_full(pos, original_stack)
check_full(pos, original_stack)
end
if stack_count ~= 0 then
-- Some items could not be added and bounced back. Report them.
@ -198,7 +206,6 @@ minetest.register_node("digilines:chest", {
action = function() end
}
},
-- pipeworks support
tube = {
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1},
connects = function(i,param2)
@ -207,20 +214,47 @@ minetest.register_node("digilines:chest", {
input_inventory = "main",
can_insert = tube_can_insert,
insert_object = tube_insert_object,
remove_items = function(pos, _, stack, dir, count, listname, index)
-- This is `on_metadata_inventory_take` but for pipeworks.
remove_items = function(pos, _, stack, dir, count)
-- Here, stack is the ItemStack in our own inventory that is being
-- pulled from, NOT the stack that is actually pulled out.
-- Combining it with count gives the stack that is pulled out.
-- Also, note that Pipeworks doesnt pass the index to this
-- function, so we use the one recorded in
-- allow_metadata_inventory_take; because we dont implement
-- tube.can_remove, Pipeworks will call
-- allow_metadata_inventory_take instead and will pass it the
-- index.
local taken = stack:take_item(count)
-- However! Pipeworks does not update the stack, thus we must do it.
core.get_meta(pos):get_inventory():set_stack(listname, index, stack)
send_message(pos, "ttake", taken, index, nil, dir)
send_empty_if_empty(pos)
minetest.get_meta(pos):get_inventory():set_stack("main", last_inventory_take_index, stack)
send_message(pos, "ttake", taken, last_inventory_take_index, nil, dir)
check_empty(pos)
return taken
end,
},
allow_metadata_inventory_put = function(pos, _, index, stack)
-- Remember what was in the target slot before the put; see
-- on_metadata_inventory_put for why we care.
last_inventory_put_index = index
last_inventory_put_stack = minetest.get_meta(pos):get_inventory():get_stack("main", index)
return stack:get_count()
end,
allow_metadata_inventory_take = function(_, _, index, stack)
-- Remember the index value; see tube.remove_items for why we care.
last_inventory_take_index = index
return stack:get_count()
end,
on_metadata_inventory_move = function(pos, _, from_index, _, to_index, count, player)
-- Detect stack swaps (in the same inventory) by trying to add them together.
-- See what would happen if we were to move the items back from in the
-- opposite direction. In the event of a normal move, this must
-- succeed, because a normal move subtracts some items from the from
-- stack and adds them to the to stack; the two stacks naturally must
-- be compatible and so the reverse operation must succeed. However, if
-- the user *swaps* the two stacks instead, then due to issue
-- minetest/minetest#6534, this function is only called once; however,
-- when it is called, the stack that used to be in the to stack has
-- already been moved to the from stack, so we can detect the situation
-- by the fact that the reverse move will fail due to the from stack
-- being incompatible with its former contents.
local inv = minetest.get_meta(pos):get_inventory()
local from_stack = inv:get_stack("main", from_index)
local to_stack = inv:get_stack("main", to_index)
@ -249,13 +283,43 @@ minetest.register_node("digilines:chest", {
minetest.log("action", player:get_player_name().." moves stuff in chest at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, _, index, stack, player)
-- Get what was in the target slot before the put; it has disappeared
-- by now (been replaced by the result of the put action) but we saved
-- it in allow_metadata_inventory_put. This should always work
-- (allow_metadata_inventory_put should AFAICT always be called
-- immediately before on_metadata_inventory_put), but in case of
-- something weird happening, just fall back to using an empty
-- ItemStack rather than crashing.
local old_stack
if last_inventory_put_index == index then
old_stack = last_inventory_put_stack
last_inventory_put_index = nil
last_inventory_put_stack = nil
else
old_stack = ItemStack(nil)
end
-- If the player tries to place a stack into an inventory, theres
-- already a stack there, and the existing stack is either of a
-- different item type or full, then obviously the stacks cant be
-- merged; instead the stacks are swapped. This information is not
-- reported to mods (Minetest core neither tells us that a particular
-- action was a swap, nor tells us a take followed by a put). In core,
-- the condition for swapping is that you try to add the new stack to
-- the existing stack and the leftovers are as big as the original
-- stack to put. Replicate that logic here using the old stack saved in
-- allow_metadata_inventory_put. If a swap happened, report it to the
-- Digilines network as a utake followed by a uput.
local leftovers = old_stack:add_item(stack)
if leftovers:get_count() == stack:get_count() then
send_message(pos, "utake", old_stack, index)
end
send_message(pos, "uput", stack, nil, index)
send_full_if_full(pos, stack)
check_full(pos, stack)
minetest.log("action", player:get_player_name().." puts stuff into chest at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, _, index, stack, player)
send_message(pos, "utake", stack, index)
send_empty_if_empty(pos)
check_empty(pos)
minetest.log("action", player:get_player_name().." takes stuff from chest at "..minetest.pos_to_string(pos))
end
})
@ -267,7 +331,7 @@ if minetest.global_exists("tubelib") then
send_message(passed_speculative_pull.pos, "ttake", passed_speculative_pull.taken,
passed_speculative_pull.index, nil, vector.multiply(passed_speculative_pull.dir, -1))
send_empty_if_empty(passed_speculative_pull.pos)
check_empty(passed_speculative_pull.pos)
end
local function tube_side(pos, side)
if side == "U" then return {x=0,y=-1,z=0}

View File

@ -162,11 +162,7 @@ local generate_line = function(s, ypos)
end
local generate_texture = function(lines)
-- Active Mip Mapping ruins the text due to nearby transparent pixels at a distance.
-- Using `lcd_anyside.png` as base image fixes this (see issue #58)
local texture = ("lcd_anyside.png^[resize:%dx%d^[combine:%dx%d"):format(
LCD_WIDTH, LCD_WIDTH, LCD_WIDTH, LCD_WIDTH
)
local texture = "[combine:"..LCD_WIDTH.."x"..LCD_WIDTH
local ypos = math.floor((LCD_WIDTH - LINE_HEIGHT*NUMBER_OF_LINES) / 2)
for i = 1, #lines do
texture = texture..generate_line(lines[i], ypos)

View File

@ -1,23 +0,0 @@
# textdomain: digilines
### inventory.lua ###
Channel=Kanal
Digiline Chest=Digiline-Truhe
### lcd.lua ###
Digiline LCD=Digiline-LCD
### lightsensor.lua ###
Digiline Lightsensor=Digiline-Lichtsensor
### rtc.lua ###
Digiline Real Time Clock (RTC)=Digiline-Echtzeituhr (RTC)
### wire_std.lua ###
Digiline=Digiline

View File

@ -2,9 +2,6 @@ name = digilines
depends =
optional_depends = mcl_core, mcl_sounds, default, tubelib, tubelib2
description = """
This mod adds digiline wires, an RTC (Real Time Clock), a light sensor as well as an LCD Screen.
This mod adds digiline wires, an RTC (Real Time Clock), a light sensor as well as an LCD Screen.
Can be used together with the luacontroller from mesecons.
"""
# Required due to https://github.com/luanti-org/luanti/issues/6534 (inventory callbacks)
min_minetest_version = 5.4