Compare commits

...

6 Commits

Author SHA1 Message Date
loosewheel
0d27b384a2 Add files via upload 2021-11-14 01:52:55 +10:00
loosewheel
7b6b0176a7 Add files via upload 2021-11-14 00:17:20 +10:00
loosewheel
f475b498e5 Add files via upload 2021-11-14 00:16:22 +10:00
loosewheel
3adc0fcf70 Add files via upload 2021-11-13 23:12:12 +10:00
loosewheel
7ed06d7e94 Add files via upload 2021-11-13 23:11:13 +10:00
loosewheel
35ec093f88 Add files via upload 2021-11-13 23:09:34 +10:00
14 changed files with 453 additions and 11 deletions

View File

@@ -15,3 +15,14 @@ v0.1.2
* Added support for hopper as optional dependency for droppers, dispensers * Added support for hopper as optional dependency for droppers, dispensers
and collectors. and collectors.
* Added digilines message to punchers when something is punched. * Added digilines message to punchers when something is punched.
v0.1.3
* Added hp and height info from detector.
* Added dispensers spawn if spawner with optional dependency on mobs mod.
If mobs:egg is dispensed 10% change a chicken is dispensed instead.
* Added player_button.
v0.1.4
* Bug fix to spawning owned mobs.

View File

@@ -121,6 +121,21 @@ end -- utils.digilines_supported
if utils.digilines_supported and utils.digistuff_supported then
minetest.register_craft({
output = "lwcomponents:player_button",
recipe = {
{ "mesecons_button:button_off", "digilines:wire_std_00000000" }
},
})
end -- utils.digilines_supported and utils.digistuff_supported
if utils.mesecon_supported and mesecon.mvps_push then if utils.mesecon_supported and mesecon.mvps_push then
minetest.register_craft ({ minetest.register_craft ({

View File

@@ -5,3 +5,5 @@ digilines?
unifieddyes? unifieddyes?
intllib? intllib?
hopper? hopper?
mobs?
digistuff?

View File

@@ -60,7 +60,7 @@ end
local function send_detect_message (pos, item_type, name, label, item_pos, count) local function send_detect_message (pos, item_type, name, label, item_pos, count, hp, height)
if utils.digilines_supported then if utils.digilines_supported then
local meta = minetest.get_meta (pos) local meta = minetest.get_meta (pos)
@@ -76,7 +76,9 @@ local function send_detect_message (pos, item_type, name, label, item_pos, count
name = name, name = name,
label = label, label = label,
pos = to_relative_coords (pos, item_pos), pos = to_relative_coords (pos, item_pos),
count = count }) count = count,
hp = hp,
height = height })
end end
end end
end end
@@ -132,6 +134,33 @@ end
local function get_entity_height (objref)
if objref.get_luaentity then
entity = objref:get_luaentity ()
if entity and entity.name then
def = minetest.registered_entities[entity.name]
if def and type (def.collisionbox) == "table" and
type (def.collisionbox[5]) == "number" then
return def.collisionbox[5]
end
end
end
local props = objref:get_properties ()
if props and props.collisionbox and type (props.collisionbox) == "table" and
type (props.collisionbox[5]) == "number" then
return props.collisionbox[5]
end
return 0
end
local function detect (pos) local function detect (pos)
local meta = minetest.get_meta (pos) local meta = minetest.get_meta (pos)
local detected = false local detected = false
@@ -153,7 +182,9 @@ local function detect (pos)
object[i]:get_player_name (), object[i]:get_player_name (),
object[i]:get_player_name (), object[i]:get_player_name (),
object[i]:get_pos (), object[i]:get_pos (),
1) 1,
object[i]:get_hp (),
get_entity_height (object[i]))
detected = true detected = true
end end
@@ -174,7 +205,9 @@ local function detect (pos)
stack:get_name (), stack:get_name (),
stack:get_name (), stack:get_name (),
object[i]:get_pos (), object[i]:get_pos (),
stack:get_count ()) stack:get_count (),
0,
0)
detected = true detected = true
end end
@@ -203,7 +236,9 @@ local function detect (pos)
name, name,
label, label,
object[i]:get_pos (), object[i]:get_pos (),
1) 1,
object[i]:get_hp (),
get_entity_height (object[i]))
detected = true detected = true
@@ -228,7 +263,9 @@ local function detect (pos)
node.name, node.name,
node.name, node.name,
testpos, testpos,
1) 1,
0,
0)
detected = true detected = true
end end

View File

@@ -64,6 +64,90 @@ end
local function try_spawn (pos, node, item)
if utils.mobs_supported then
local mob = item:get_name ()
local item_def = minetest.registered_craftitems[mob]
local spawn_pos = dispense_pos (pos, node)
if item_def and item_def.groups and item_def.groups.spawn_egg then
if mob:sub (mob:len () - 3) == "_set" then
mob = mob:sub (1, mob:len () - 4)
if minetest.registered_entities[mob] then
local data = item:get_metadata ()
local smob = minetest.add_entity (spawn_pos, mob, data)
local ent = smob and smob:get_luaentity ()
if ent then
local meta = minetest.get_meta (pos)
if meta then
local owner = meta:get_string ("owner")
-- set owner if not a monster
if owner:len () > 0 and ent.type ~= "monster" then
ent.owner = owner
ent.tamed = true
end
end
end
return smob
end
else
if minetest.registered_entities[mob] then
local smob = minetest.add_entity (spawn_pos, mob)
local ent = smob and smob:get_luaentity ()
if ent then
local meta = minetest.get_meta (pos)
if meta then
local owner = meta:get_string ("owner")
-- set owner if not a monster
if owner:len () > 0 and ent.type ~= "monster" then
ent.owner = owner
ent.tamed = true
end
end
end
return smob
end
end
elseif mob == "mobs:egg" then
if math.random (1, 10) == 1 then
local smob = minetest.add_entity (spawn_pos, "mobs_animal:chicken")
local ent = smob and smob:get_luaentity ()
if ent then
local meta = minetest.get_meta (pos)
if meta then
local owner = meta:get_string ("owner")
-- set owner if not a monster
if owner:len () > 0 and ent.type ~= "monster" then
ent.owner = owner
ent.tamed = true
end
end
end
return smob
end
end
end
return nil
end
-- slot: -- slot:
-- nil - next item, no dispense if empty -- nil - next item, no dispense if empty
-- number - 1 item from slot, no dispense if empty -- number - 1 item from slot, no dispense if empty
@@ -119,7 +203,11 @@ local function dispense_item (pos, node, slot)
if item then if item then
item:set_count (1) item:set_count (1)
local obj = minetest.add_item (dispense_pos (pos, node), item) local obj = try_spawn (pos, node, item)
if not obj then
obj = minetest.add_item (dispense_pos (pos, node), item)
end
if obj then if obj then
obj:set_velocity (dispense_velocity (node)) obj:set_velocity (dispense_velocity (node))

View File

@@ -1,4 +1,4 @@
local version = "0.1.2" local version = "0.1.4"
local mod_storage = minetest.get_mod_storage () local mod_storage = minetest.get_mod_storage ()
@@ -22,6 +22,7 @@ loadfile (modpath.."/dispenser.lua") (utils)
loadfile (modpath.."/detector.lua") (utils) loadfile (modpath.."/detector.lua") (utils)
loadfile (modpath.."/siren.lua") (utils) loadfile (modpath.."/siren.lua") (utils)
loadfile (modpath.."/puncher.lua") (utils) loadfile (modpath.."/puncher.lua") (utils)
loadfile (modpath.."/player_button.lua") (utils)
loadfile (modpath.."/extras.lua") (utils) loadfile (modpath.."/extras.lua") (utils)
loadfile (modpath.."/digiswitch.lua") (utils) loadfile (modpath.."/digiswitch.lua") (utils)
loadfile (modpath.."/movefloor.lua") (utils) loadfile (modpath.."/movefloor.lua") (utils)

View File

@@ -64,6 +64,8 @@ Media license
siren images derived from images from https://openclipart.org, which is siren images derived from images from https://openclipart.org, which is
public domain. public domain.
player button images derived from mesecons button image.
All other media, or media not covered by a licence, is licensed All other media, or media not covered by a licence, is licensed
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)

View File

@@ -3,4 +3,4 @@ description = Various components for mesecons and digilines.
title = LWComponents title = LWComponents
name = lwcomponents name = lwcomponents
depends = default depends = default
optional_depends = lwdrops, mesecons, digilines, unifieddyes, intllib, hopper optional_depends = lwdrops, mesecons, digilines, unifieddyes, intllib, hopper, mobs, digistuff

232
player_button.lua Normal file
View File

@@ -0,0 +1,232 @@
local utils = ...
local S = utils.S
if utils.digilines_supported and utils.digistuff_supported then
local function on_contruct (pos)
local meta = minetest.get_meta(pos)
local spec =
"size[7.5,3]"..
"field[1,1;6,2;channel;Channel;${channel}]"..
"button_exit[2.5,2;3,1;submit;Set]"
meta:set_string("formspec", spec)
end
local function on_receive_fields (pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
if fields.submit then
if fields.channel ~= "" then
meta:set_string ("channel", fields.channel)
meta:set_string ("formspec", "")
minetest.swap_node (pos, { name = "lwcomponents:player_button_off",
param2 = minetest.get_node(pos).param2 })
else
minetest.chat_send_player (sender:get_player_name(), "Please set a channel!")
end
end
end
local function player_button_push (pos, node, player)
local meta = minetest.get_meta (pos)
if player and player:is_player () then
local channel = meta:get_string ("channel")
local formspec = meta:get_string ("formspec")
if channel:len () > 0 and formspec:len () == 0 then
utils.digilines_receptor_send (pos,
digistuff.button_get_rules (node),
channel,
{ action = "player",
name = player:get_player_name () })
end
end
if node.name == "lwcomponents:player_button_off" then
node.name = "lwcomponents:player_button_on"
minetest.swap_node(pos, node)
if digistuff.mesecons_installed then
minetest.sound_play ("mesecons_button_push", { pos = pos })
end
minetest.get_node_timer (pos):start (0.25)
end
end
local function player_button_turnoff (pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
if node.name == "lwcomponents:player_button_on" then
node.name = "lwcomponents:player_button_off"
minetest.swap_node (pos, node)
if digistuff.mesecons_installed then
minetest.sound_play ("mesecons_button_pop", { pos = pos })
end
end
end
minetest.register_node ("lwcomponents:player_button", {
description = "Player Button",
drawtype = "nodebox",
tiles = {
"lwplayer_button_side.png",
"lwplayer_button_side.png",
"lwplayer_button_side.png",
"lwplayer_button_side.png",
"lwplayer_button_side.png",
"lwplayer_button.png"
},
paramtype = "light",
paramtype2 = "facedir",
legacy_wallmounted = true,
walkable = false,
sunlight_propagates = true,
drop = "lwcomponents:player_button",
selection_box = {
type = "fixed",
fixed = { -6/16, -6/16, 5/16, 6/16, 6/16, 8/16 }
},
node_box = {
type = "fixed",
fixed = {
{ -6/16, -6/16, 6/16, 6/16, 6/16, 8/16 }, -- the thin plate behind the button
{ -4/16, -2/16, 4/16, 4/16, 2/16, 6/16 } -- the button itself
}
},
groups = { dig_immediate = 2, digiline_receiver = 1 },
_digistuff_channelcopier_fieldname = "channel",
sounds = default and default.node_sound_stone_defaults(),
digiline =
{
receptor = {},
wire = {
rules = digistuff.button_get_rules,
},
},
on_construct = on_contruct,
after_place_node = digistuff.place_receiver,
after_destruct = digistuff.remove_receiver,
on_receive_fields = on_receive_fields,
})
minetest.register_node ("lwcomponents:player_button_off", {
description = "Player Button",
drawtype = "nodebox",
tiles = {
"lwplayer_button_side.png",
"lwplayer_button_side.png",
"lwplayer_button_side.png",
"lwplayer_button_side.png",
"lwplayer_button_side.png",
"lwplayer_button.png"
},
paramtype = "light",
paramtype2 = "facedir",
legacy_wallmounted = true,
walkable = false,
sunlight_propagates = true,
drop = "lwcomponents:player_button",
selection_box = {
type = "fixed",
fixed = { -6/16, -6/16, 5/16, 6/16, 6/16, 8/16 }
},
node_box = {
type = "fixed",
fixed = {
{ -6/16, -6/16, 6/16, 6/16, 6/16, 8/16 }, -- the thin plate behind the button
{ -4/16, -2/16, 4/16, 4/16, 2/16, 6/16 } -- the button itself
}
},
groups = { dig_immediate = 2, digiline_receiver = 1, not_in_creative_inventory = 1 },
_digistuff_channelcopier_fieldname = "channel",
sounds = default and default.node_sound_stone_defaults(),
digiline =
{
receptor = {},
wire = {
rules = digistuff.button_get_rules,
},
effector = {
action = digistuff.button_handle_digilines,
},
},
after_destruct = digistuff.remove_receiver,
on_rightclick = player_button_push,
})
minetest.register_node ("lwcomponents:player_button_on", {
description = "Player Button",
drawtype = "nodebox",
tiles = {
"lwplayer_button_side.png",
"lwplayer_button_side.png",
"lwplayer_button_side.png",
"lwplayer_button_side.png",
"lwplayer_button_side.png",
"lwplayer_button_on.png"
},
paramtype = "light",
paramtype2 = "facedir",
legacy_wallmounted = true,
walkable = false,
sunlight_propagates = true,
light_source = 7,
drop = "lwcomponents:player_button",
selection_box = {
type = "fixed",
fixed = { -6/16, -6/16, 5/16, 6/16, 6/16, 8/16 }
},
node_box = {
type = "fixed",
fixed = {
{ -6/16, -6/16, 6/16, 6/16, 6/16, 8/16 },
{ -4/16, -2/16, 11/32, 4/16, 2/16, 6/16 }
}
},
groups = { dig_immediate = 2, digiline_receiver = 1, not_in_creative_inventory = 1 },
_digistuff_channelcopier_fieldname = "channel",
sounds = default and default.node_sound_stone_defaults(),
digiline =
{
receptor = {},
wire = {
rules = digistuff.button_get_rules,
},
},
after_destruct = digistuff.remove_receiver,
-- on_rightclick = player_button_push,
on_timer = player_button_turnoff,
})
end -- utils.digilines_supported and utils.digistuff_supported

View File

@@ -13,7 +13,7 @@ CC BY-SA 3.0
Version Version
======= =======
0.1.2 0.1.4
Minetest Version Minetest Version
@@ -34,6 +34,8 @@ digilines
unifieddyes unifieddyes
intllib intllib
hopper hopper
mobs
digistuff
Installation Installation
@@ -101,6 +103,12 @@ Contains an inventory and dispenses (with velocity) an item on command.
Also acts as a digilines conductor. If the hopper mod is loaded, will take Also acts as a digilines conductor. If the hopper mod is loaded, will take
items from the top and sides, and release them from the bottom. items from the top and sides, and release them from the bottom.
Dispensers support mobs mod if loaded. Will spawn the entity from an 'egg'
if possible, or the 'egg' is dispensed. If a chicken egg is dispensed a
10% chance a chicken is dispensed instead. If the spawned entity can be
owned (or tamed) and the dispenser is owned the owner of the dispenser is
set as the owner of the entity.
UI UI
Channel - digilines channel of dispenser. Channel - digilines channel of dispenser.
@@ -234,7 +242,9 @@ message is a table with the following keys:
name = "<name>", name = "<name>",
label = "<label>", label = "<label>",
pos = { x = n, y = n, z = n }, pos = { x = n, y = n, z = n },
count = <count> count = <count>,
hp = <number>,
height = <number>
} }
type type
@@ -265,6 +275,12 @@ pos
count count
The count of items for a "drop", or 1 for everything else. The count of items for a "drop", or 1 for everything else.
hp
Health points for players and entities. Zero for everything else.
height
Height for players and entities. Zero for everything else. This is simply
the top position of the object's collision box.
Siren Siren
@@ -383,6 +399,26 @@ label
Player Button
-------------
* This block is only available if both digilines and digistuff are loaded.
When pressed sends a digilines message with the name of the player that
pressed the button.
The first time the button is right clicked a form opens to set the
digilines channel. After that right click presses the button. The
digilines cannot be changed after its set.
When the button is pressed a digilines message is sent with the button's
channel in the form:
{
action = "player",
name = <player name>
}
DigiSwitch DigiSwitch
---------- ----------
* This block is only available if both digilines and mesecons are loaded. * This block is only available if both digilines and mesecons are loaded.

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 431 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

View File

@@ -129,6 +129,24 @@ end
-- check for mobs
if minetest.global_exists ("mobs") then
utils.mobs_supported = true
else
utils.mobs_supported = false
end
-- check for digistuff
if minetest.global_exists ("digistuff") then
utils.digistuff_supported = true
else
utils.digistuff_supported = false
end
function utils.can_interact_with_node (pos, player) function utils.can_interact_with_node (pos, player)
if not player or not player:is_player () then if not player or not player:is_player () then
return false return false