Moved to Github.

This commit is contained in:
rdococ 2017-07-30 21:24:43 +01:00
commit 31cf39aa38
14 changed files with 301 additions and 0 deletions

24
UNLICENSE.txt Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

94
conveyor.lua Normal file
View File

@ -0,0 +1,94 @@
local rmod_conveyor_top_animated = {
name = "rmod_conveyor_top_animated.png",
backface_culling = true,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1/8, -- it takes 1 second to move 16 pixels, thus 1/16 seconds to move one pixel. but this animation is two pixels per runthrough.
},
}
local rmod_conveyor_top_animated_2 = {
name = "rmod_conveyor_top_animated_2.png", -- Higher resolution version with 4 frames as opposed to 2.
backface_culling = true,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 1/8, -- it takes 1 second to move 16 pixels, thus 1/16 seconds to move one pixel. but this animation is two pixels per runthrough.
},
}
local rmod_conveyor_top_animated_2_reversed = { -- Reversed animation for the Z+ face.
name = "rmod_conveyor_top_animated_2_reversed.png", -- Higher resolution version with 4 frames as opposed to 2.
backface_culling = true,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 1/8, -- it takes 1 second to move 16 pixels, thus 1/16 seconds to move one pixel. but this animation is two pixels per runthrough.
},
}
minetest.register_node("rmod:conveyor", {
description = "Conveyor",
--[[tiles = {"rmod_conveyor_top.png", "rmod_conveyor_top.png", "rmod_conveyor_side.png", "rmod_conveyor_side.png", "rmod_conveyor_top.png", "rmod_conveyor_top.png"},]]
tiles = {
rmod_conveyor_top_animated_2, rmod_conveyor_top_animated_2,
"rmod_conveyor_side.png", "rmod_conveyor_side.png",
rmod_conveyor_top_animated_2_reversed, rmod_conveyor_top_animated_2 -- You have to reverse one of the faces to go UP, not DOWN.
},
groups = {oddly_breakable_by_hand = 1},
use_texture_alpha = true,
paramtype2 = "facedir",
})
local queue = {}
local entity_queue = {}
minetest.register_abm({
label = "Conveyor Step",
nodenames = {"rmod:conveyor"},
neighbors = {},
interval = 1,
chance = 1,
action = function (pos, node)
entity_queue = {}
queue[pos] = node
end,
})
minetest.register_globalstep(function (dtime)
for pos,node in pairs(queue) do
local facedir = minetest.facedir_to_dir(node.param2)
for _,entity in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if entity and not entity_queue[entity] then
local offset = vector.subtract(entity:getpos(), pos)
local movementDir = vector.multiply(facedir, {x=-1,y=-1,z=-1})
if math.abs(offset.x) < 0.8 and math.abs(offset.z) < 0.8 and offset.y > 0 then
local new_pos = vector.add(entity:getpos(), movementDir)
local rounded_pos = {x=math.floor(new_pos.x+0.5),y=math.floor(new_pos.y+0.5),z=math.floor(new_pos.z+0.5)}
if not minetest.registered_nodes[minetest.get_node(rounded_pos).name].walkable then
entity:setpos(new_pos)
end
entity_queue[entity] = true
queue[pos] = nil
elseif math.abs(offset.x) < 2 and math.abs(offset.z) < 2 and offset.y < 0 then
-- Take the movementDir, and subtract it from my position. Then subtract y=0.5. Players here should move UP.
-- No checking for nodes there is required, because then the player's head would already be in a node.
local moveUpPos = vector.subtract(vector.subtract(pos, movementDir), {x=0,y=0.5,z=0})
local offset = vector.subtract(entity:getpos(), moveUpPos)
local new_pos = vector.add(vector.add(entity:getpos(), {x=0,y=1,z=0}), movementDir)
if math.abs(offset.x) < 0.5 and math.abs(offset.z) < 0.5 and math.abs(offset.y) < 0.5 then
entity:setpos(new_pos)
entity_queue[entity] = true
queue[pos] = nil
end
end
end
end
end
queue = {}
end)

68
crate.lua Normal file
View File

@ -0,0 +1,68 @@
minetest.register_node("rmod:crate", {
description = "Crate",
on_construct = function (pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local item_meta = minetest.deserialize(itemstack:get_meta():get_string("inv"))
local node_meta = minetest.get_meta(pos)
node_meta:set_string("formspec", [[size[8, 9]
list[context;main;0,0;8,4;]
list[current_player;main;0,5;8,4;]
]])
local infotext = "Empty Crate"
if item_meta and item_meta ~= {} then
infotext = "Crate containing:"
for _,istack in pairs(item_meta) do
node_meta:get_inventory():add_item("main", ItemStack(istack))
infotext = infotext .. "\n" .. ItemStack(istack):to_string()
end
end
node_meta:set_string("infotext", infotext)
print(dump(item_meta))
end,
on_receive_fields = function(pos)
local node_meta = minetest.get_meta(pos)
local string_inventory = {}
for _,istack in pairs(node_meta:get_inventory():get_list("main")) do
table.insert(string_inventory, istack:to_table())
end
local infotext = "Empty Crate"
if string_inventory ~= {} then
infotext = "Crate containing:"
for _,istack in pairs(string_inventory) do
infotext = infotext .. "\n" .. ItemStack(istack):to_string()
end
end
node_meta:set_string("infotext", infotext)
end,
on_dig = function(pos, node, player)
local node_meta = minetest.get_meta(pos)
local inv = player:get_inventory()
local stack = ItemStack( {name="rmod:crate", count=1, wear=0} )
local string_inventory = {}
for _,istack in pairs(node_meta:get_inventory():get_list("main")) do
table.insert(string_inventory, istack:to_table())
end
stack:get_meta():set_string("inv", minetest.serialize(string_inventory) )
print(dump(node_meta:to_table().inventory))
inv:add_item("main", stack)
minetest.remove_node(pos)
end,
tiles = {"rmod_crate.png"},
groups = {oddly_breakable_by_hand = 2, choppy = 2},
})

82
grate.lua Normal file
View File

@ -0,0 +1,82 @@
minetest.register_node("rmod:grate", {
description = "Grate",
tiles = {"rmod_grate.png"},
groups = {oddly_breakable_by_hand = 1},
use_texture_alpha = true,
drawtype = "glasslike",
paramtype = "light",
})
local function grate_step(pos, offset)
local neigh = vector.add(pos, offset)
local neigh_node = minetest.get_node(neigh)
local neigh_name
if neigh_node then neigh_name = neigh_node.name else return end
local neigh_def = minetest.registered_nodes[neigh_name]
if not neigh_def then return end -- Unknown nodes can't flow.
if not neigh_def.liquidtype then return end -- Non-liquids can't flow at all.
print("Neighbor is liquid.")
-- Check its level.
local level = neigh_node.param2 % 16
if level < 8 then level = level * 2 end
if neigh_def.liquidtype == "source" then level = 16 end
if level < 2 then return end -- Level < 2 water stops flowing within two blocks.
print("Neighbor is high enough level.")
-- Check the opposing neighbor.
local opposite = vector.subtract(pos, offset)
local opposite_node = minetest.get_node(opposite)
local opposite_name
if opposite_node then opposite_name = opposite_node.name else return end
local opposite_def = minetest.registered_nodes[opposite_name]
if not opposite_def then return end
if not opposite_def.floodable then
if not opposite_def.liquidtype then return end
if opposite_def.walkable then return end
local opposite_level = opposite_node.param2 % 16
if opposite_level < 8 then opposite_level = opposite_level * 2 end
if opposite_def.liquidtype == "source" then opposite_level = 16 end
if opposite_level > level - 2 or opposite_def.liquidtype == "source" then return end
end -- Liquids can't flow into higher level liquids.
print("Opposite is floodable.")
local neigh_flowing = neigh_def.liquid_alternative_flowing
if not neigh_flowing then return end -- Improperly configured liquids can't flow.
print("Liquid is configured properly.")
minetest.set_node(opposite, {
name = neigh_flowing,
param1 = neigh_node.param1,
param2 = neigh_node.param2 == 0 and 6 or neigh_node.param2 - 2
})
end
minetest.register_abm({
label = "Grate Step",
nodenames = {"rmod:grate"},
neighbors = {},
interval = 1,
chance = 1,
action = function (pos, node)
for i=1,6 do -- For each of our 6 neighbors,
-- Calculate where our neighbor is
local offset = {x=0,y=0,z=0}
if i == 1 then offset.y = 1 end
if i == 2 then offset.y = -1 end
if i == 3 then offset.x = 1 end
if i == 4 then offset.x = -1 end
if i == 5 then offset.z = 1 end
if i == 6 then offset.z = -1 end
-- Then run the checking code
grate_step(pos, offset)
end
end,
})

5
init.lua Normal file
View File

@ -0,0 +1,5 @@
local modpath = minetest.get_modpath("rmod")
dofile(modpath .. "/grate.lua")
dofile(modpath .. "/conveyor.lua")
dofile(modpath .. "/crate.lua")

14
mud.lua Normal file
View File

@ -0,0 +1,14 @@
minetest.register_node("rmod:mud", {
drawtype = "flowingliquid",
tiles = {"rmod_mud.png"},
groups = {oddly_breakable_by_hand = 1},
use_texture_alpha = true,
walkable = false,
after_place_node = function (pos)
local node = minetest.get_node(pos)
node.param2 = 0
minetest.set_node(pos, node)
end
})

14
test.lua Normal file
View File

@ -0,0 +1,14 @@
minetest.register_node("rmod:mud", {
drawtype = "flowingliquid",
tiles = {"rmod_mud.png"},
groups = {oddly_breakable_by_hand = 1},
use_texture_alpha = true,
walkable = false
after_place_node = function (pos)
local node = minetest.get_node(pos)
node.param2 = 0
minetest.set_node(pos, node)
end
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

BIN
textures/rmod_crate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

BIN
textures/rmod_grate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B