Compare commits

...

5 Commits

Author SHA1 Message Date
NathanSalapat efee25f407 tweaked around plant spreading. 2019-05-11 16:00:20 -05:00
NathanSalapat fcc040daad added a few ABMs for plants. 2019-05-04 17:35:45 -05:00
NathanSalapat 40f17d3679 added grass. 2019-05-03 09:07:21 -05:00
NathanSalapat a9d1cab629 Got chests working with upgrades. 2017-06-29 22:27:53 -05:00
NathanSalapat 9896cc8203 added a chest. 2017-05-29 18:32:04 -05:00
45 changed files with 554 additions and 38 deletions

View File

@ -1,3 +1,9 @@
2019-05-03:
Added grass.
2017-05-29:
Added a chest and did some updates to the players inventory and formspecs.
2017-05-27:
Added in doors to the spawn mod. I have a feeling they are going to need lots more work.

View File

@ -1 +1 @@
name = new subgame
name = new-subgame

View File

@ -1,11 +1,11 @@
common.colbox_stair = {
common.colbox_stair = { --Stairs nodebox
type = 'fixed',
fixed = {
{-.5, -.5, -.5, .5, 0, .5},
{-.5, 0, 0, .5, .5, .5},
}}
common.colbox_1_5_slab = {
common.colbox_1_5_slab = { --1/5th height slab
type = 'fixed',
fixed = {
{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},

View File

@ -19,8 +19,7 @@ common.gui_survival_form = 'size[8,7.5]'..
common.gui_bg..
common.gui_bg_img..
common.gui_slots..
'list[current_player;main;0,3.5;8,1;]'..
'list[current_player;main;0,4.5;8,3;8]'..
'list[current_player;main;0,4;8,3;]'..
'list[current_player;craft;0,0;3,3;]'..
'list[current_player;craftpreview;4,1;1,1;]'..
'image[3,1;1,1;common_arrow.png'..

View File

@ -0,0 +1,50 @@
-- This function does random spreading of plants, designed specifically to use with grasses and weeds.
-- It's mostly self explanitory, but the fill ratio can be tricky, so I'll explain how that works.
-- Maxspread is how far the child node can be from the parent in either direction.
-- Needed_air is how much air space should be preserved. Calculate this value in the following manner.
-- Double maxspread, add one, then square. How much air do you want in that space, fill that value in the needed_air variable.
function common.plant_spread(baby_plant, parent_plant, pos, maxspread, undernode, replacing, needed_air)
local ran_num = math.random(1,8)
local spreadx = math.random(0,maxspread)
local spready = math.random(0,maxspread)
local location = {}
if ran_num == 1 then
location = {x=pos.x+spreadx, y=pos.y, z=pos.z}
elseif ran_num == 2 then
location = {x=pos.x+spreadx, y=pos.y, z=pos.z+spready}
elseif ran_num == 3 then
location = {x=pos.x, y=pos.y, z=pos.z+spready}
elseif ran_num == 4 then
location = {x=pos.x-spreadx, y=pos.y, z=pos.z+spready}
elseif ran_num == 5 then
location = {x=pos.x-spreadx, y=pos.y, z=pos.z}
elseif ran_num == 6 then
location = {x=pos.x-spreadx, y=pos.y, z=pos.z-spready}
elseif ran_num == 7 then
location = {x=pos.x, y=pos.y, z=pos.z-spready}
elseif ran_num == 8 then
location = {x=pos.x+spreadx, y=pos.y, z=pos.z-spready}
end
local under_location = ({x=location.x, y=location.y-1, z=location.z})
local under_name = minetest.get_node_or_nil(under_location)
local location_name = minetest.get_node_or_nil(location)
if under_name == nil then
print 'node does not exist'
return -- Should under_name somehow not be a node this will keep the script from crashing.
end
if under_name.name == undernode then
print 'name matches.'
if location_name.name == replacing then
local diff = maxspread
local pos1 = {x=location.x+diff, y=location.y, z=location.z+diff}
local pos0 = {x=location.x-diff, y=location.y, z=location.z-diff}
local air = minetest.find_nodes_in_area(pos0, pos1, replacing) --looking for item that is being replaced. Usually air
local open_spaces = #air
if open_spaces > needed_air then
minetest.set_node(location, {name = baby_plant})
minetest.set_node(pos, {name = parent_plant})
end
end
end
end

View File

@ -2,3 +2,4 @@ common = {}
dofile(minetest.get_modpath('common')..'/colbox.lua')
dofile(minetest.get_modpath('common')..'/formspec.lua')
dofile(minetest.get_modpath('common')..'/functions.lua')

View File

@ -45,7 +45,7 @@ function creative.update_creative_inventory(player_name, tab_content)
end
for name, def in pairs(tab_content) do
if not (def.groups.not_in_creative_inventory == 1) and
if not (def.groups.not_in_creative == 1) and
def.description and def.description ~= "" and
(def.name:find(inv.filter, 1, true) or
def.description:lower():find(inv.filter, 1, true)) then
@ -92,8 +92,7 @@ function creative.register_tab(name, title, items)
[[
image[4,3.3;1,1;creative_trash_icon.png]
listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]
list[current_player;main;0,4.7;8,1;]
list[current_player;main;0,5.85;8,3;8]
list[current_player;main;0,4.5;8,3;]
list[detached:creative_trash;main;4,3.3;1,1;]
listring[]
button[5.4,3.2;0.8,0.9;creative_prev;<]
@ -108,9 +107,8 @@ function creative.register_tab(name, title, items)
"field[0.3,3.5;2.2,1;creative_filter;;" .. minetest.formspec_escape(inv.filter) .. "]" ..
"listring[detached:creative_" .. player_name .. ";main]" ..
"list[detached:creative_" .. player_name .. ";main;0,0;8,3;" .. tostring(start_i) .. "]" ..
-- common.get_hotbar_bg(0,4.7) ..
common.gui_bg .. common.gui_bg_img .. common.gui_slots
.. creative.formspec_add, false)
.. creative.formspec_add, false, "size[8,7.25]")
end,
on_enter = function(self, player, context)
local player_name = player:get_player_name()

View File

@ -104,12 +104,13 @@ end
-- Update appearance when the player joins
minetest.register_on_joinplayer(function(player)
player:get_inventory():set_size('main', 8*3)
gamer.player_attached[player:get_player_name()] = false
gamer.player_set_model(player, 'gamer_model.b3d')
player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
-- set GUI
if not minetest.setting_getbool('creative_mode') then
if not minetest.settings:get_bool('creative_mode') then
player:set_inventory_formspec(common.gui_survival_form)
end
player:hud_set_hotbar_image('gui_hotbar.png')

29
mods/ground/ABMs.lua Normal file
View File

@ -0,0 +1,29 @@
minetest.register_abm({
label = 'grass spread',
nodenames = {'ground:dirt'},
neighbors = {'ground:dirt_with_grass'},
interval = 3,
chance = 2,
action = function(pos)
local above_node = {x=pos.x, y=pos.y+1, z=pos.z}
local above_node_name = minetest.get_node_or_nil(above_node).name
local nodedef = minetest.registered_nodes[above_node_name]
if nodedef.sunlight_propagates then
minetest.add_node(pos, {name = 'ground:dirt_with_grass'})
end
end,
})
minetest.register_abm({
nodenames = {'ground:dirt_with_grass'},
interval = 3,
chance = 2,
action = function(pos)
local above_node = {x=pos.x, y=pos.y+1, z=pos.z}
local above_node_name = minetest.get_node_or_nil(above_node).name
local nodedef = minetest.registered_nodes[above_node_name]
if not nodedef.sunlight_propagates then
minetest.add_node(pos, {name = 'ground:dirt'})
end
end,
})

View File

@ -1,2 +1,3 @@
dofile(minetest.get_modpath('ground')..'/nodes.lua')
dofile(minetest.get_modpath('ground')..'/mapgen.lua')
dofile(minetest.get_modpath('ground')..'/ABMs.lua')

View File

@ -56,9 +56,9 @@ minetest.register_biome({
minetest.register_biome({
name = "grassland_dunes",
--node_dust = "",
node_top = "ground:sand",
node_top = "ground:dirt_with_grass",
depth_top = 1,
node_filler = "ground:sand",
node_filler = "ground:dirt_with_grass",
depth_filler = 2,
--node_stone = "",
--node_water_top = "",
@ -99,11 +99,11 @@ minetest.register_biome({
depth_top = 1,
node_filler = 'ground:dirt',
depth_filler = 4,
node_stone = 'ground:desert_stone',
node_stone = 'ground:stone',
node_riverbed = 'ground:sand',
depth_riverbed = 1,
y_min = 12,
y_max = 60,
y_max = 20,
heat_point = 10,
humidity_point = 47,
})
@ -116,8 +116,24 @@ minetest.register_biome({
depth_filler = 10,
node_riverbed = 'ground:dirt',
depth_riverbed = 2,
vertical_blend = 3,
y_min = -5,
y_max = 15,
y_max = 5,
heat_point = 65,
humidity_point = 70,
})
minetest.register_biome({
name = 'stone',
node_top = 'ground:stone',
depth_top = 1,
node_filler = 'ground:stone',
depth_filler = 4,
node_stone = 'ground:stone',
node_riverbed = 'ground:stone',
depth_riverbed = 1,
y_min = 20,
y_max = 80,
heat_point = 10,
humidity_point = 47,
})

View File

@ -29,7 +29,7 @@ minetest.register_node('ground:dirt_with_grass', {
tiles = {'ground_grass.png', 'ground_dirt.png',
{name = 'ground_dirt.png^ground_grass_overlay.png',
tileable_vertical = false}},
groups = {crumbly=3, soil=1, spreading_dirt_type=1},
groups = {crumbly=3, soil=1},
drop = 'ground:dirt',
})
@ -38,7 +38,7 @@ minetest.register_node('ground:dirt_with_snow', {
tiles = {'ground_snow.png', 'ground_dirt.png',
{name = 'ground_dirt.png^ground_snow_overlay.png',
tileable_vertical = false}},
groups = {crumbly=3, soil=1, spreading_dirt_type=1},
groups = {crumbly=3,},
drop = 'ground:dirt',
})

2
mods/items/init.lua Normal file
View File

@ -0,0 +1,2 @@
dofile(minetest.get_modpath('items')..'/items.lua')
dofile(minetest.get_modpath('items')..'/recipies.lua')

4
mods/items/items.lua Normal file
View File

@ -0,0 +1,4 @@
minetest.register_craftitem("items:label", {
description = "Paper Label",
inventory_image = "items_label.png",
})

0
mods/items/recipies.lua Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

View File

@ -19,3 +19,28 @@ minetest.register_ore({
y_min = -31000,
y_max = -50,
})
minetest.register_ore({
ore_type = 'stratum',
ore = 'ground:dirt',
wherein = 'ground:stone',
clust_scarcity = 1,
y_min = 25,
y_max = 30,
noise_params = {
offset = 27,
scale = 4,
spread = {x = 100, y = 100, z = 100},
seed = 90122,
octaves = 3,
persist = 0.7
},
np_stratum_thickness = {
offset = 8,
scale = 4,
spread = {x = 100, y = 100, z = 100},
seed = 17,
octaves = 3,
persist = 0.7
},
})

View File

@ -3,7 +3,7 @@ local function is_inside(pos)
if minetest.get_node_light({x=pos.x,y=pos.y+1,z=pos.z}, 0.5) ~= 15 then
return true
end
local temp_node = minetest.get_node_or_nil({x=pos.x,y=pos.y+1,z=pos.z})
for i = 2,50 do
@ -30,8 +30,8 @@ minetest.register_globalstep(function(dtime)
end
t = 0
if minetest.get_modpath("lightning") then
if minetest.get_modpath("lightning") then
if mymonths.weather == "storm" then
lightning.strike()
end
@ -222,11 +222,11 @@ mymonths.active_particlespawners={}
--used to determine if to remove old and add new particle spawners
mymonths.last_weather2="none"
function mymonths.update_weather_particles(player)
mymonths.remove_weather_particles(player)
local name=player:get_player_name()
local minp = {x = -20, y = 7, z = -20}
local maxp = {x = 20, y = 7, z = 20}
local minps = {x =-20, y = 0, z = -20}
@ -239,9 +239,9 @@ function mymonths.update_weather_particles(player)
local acc_snow = {x = 0, y = -0.5, z = 0}
local vel_sand = {x = 1, y = -0.1, z = 0}
local acc_sand = {x = 2, y = 0, z = 0}
local l={}
if mymonths.weather2 == "storm" then
l[1] = minetest.add_particlespawner({
@ -280,7 +280,7 @@ function mymonths.update_weather_particles(player)
minsize = 25,
maxsize = 25,
collisiondetection = false,
vertical = true,
vertical = true,
texture = "weather_rain.png",
playername = name,
attached = player
@ -442,12 +442,12 @@ minetest.register_globalstep(function(dtime)
for _, player in ipairs(minetest.get_connected_players()) do
local ppos = player:getpos()
local ppos = player:get_pos()
local hp = player:get_hp()
local name = player:get_player_name()
local nodein = minetest.get_node(ppos)
local nodeu = minetest.get_node({x = ppos.x, y = ppos.y - 1, z = ppos.z})
local biome_jungle = minetest.find_node_near(ppos, 8, "default:jungletree", "default:junglegrass")
local biome_desert = minetest.find_node_near(ppos, 8, "default:desert_sand", "default:desert_stone")
local biome_snow = minetest.find_node_near(ppos, 8, "default:snow", "default:snowblock", "default:dirt_with_snow",
@ -531,12 +531,12 @@ minetest.register_globalstep(function(dtime)
else
mymonths.weather2 = mymonths.weather
end
if mymonths.weather2 ~= mymonths.last_weather2 then
mymonths.update_weather_particles(player)
mymonths.last_weather2 = mymonths.weather2
end
if mymonths.weather2 == "storm" then
if not is_inside(ppos) and mymonths.damage == true then
@ -597,7 +597,7 @@ minetest.register_globalstep(function(dtime)
for _, player in ipairs(minetest.get_connected_players()) do
local ppos = player:getpos()
local ppos = player:get_pos()
t2 = t2 + dtime

19
mods/plants/ABMs.lua Normal file
View File

@ -0,0 +1,19 @@
minetest.register_abm{
nodenames = {'group:grass'},
interval = 1,
chance = 2,
action = function(pos)
local month = mymonths.month_counter
local node_name = minetest.get_node_or_nil(pos).name
local nodedef = minetest.registered_nodes[node_name]
local thing_that_grows = nodedef.grows_to
local time_of_growing = nodedef.grows_in_month
if tonumber(month) == time_of_growing then
if thing_that_grows ~= 'spread' then
minetest.set_node(pos, {name = thing_that_grows})
elseif thing_that_grows == 'spread' then
common.plant_spread('plants:grass_1', 'plants:grass_4', pos, 2, 'ground:dirt_with_grass', 'air', 20)
end
end
end,
}

85
mods/plants/grasses.lua Normal file
View File

@ -0,0 +1,85 @@
local grasses_group = {flora=1, grass=1, dig_immediate=3, attached_node=1, flamable=3, not_in_creative=1}
minetest.register_node('plants:grass_1', {
description = 'Grass',
tiles = {'plants_grass_1.png'},
drawtype = 'plantlike',
inventory_image = "plants_grass_4.png",
wield_image = "plants_grass_4.png",
groups = grasses_group,
drop = 'plants:fiber',
waving = 1,
walkable = false,
sunlight_propagates = true,
buildable_to = true,
paramtype = 'light',
selection_box = plants.grass_sel,
grows_in_month = 5,
grows_to = 'plants:grass_2',
})
minetest.register_node('plants:grass_2', {
description = 'Grass',
tiles = {'plants_grass_2.png'},
drawtype = 'plantlike',
groups = grasses_group,
drop = 'plants:fiber',
waving = 1,
walkable = false,
sunlight_propagates = true,
buildable_to = true,
paramtype = 'light',
selection_box = plants.grass_sel,
grows_in_month = 6,
grows_to = 'plants:grass_3',
})
minetest.register_node('plants:grass_3', {
description = 'Grass',
tiles = {'plants_grass_3.png'},
drawtype = 'plantlike',
groups = grasses_group,
drop = 'plants:fiber',
waving = 1,
walkable = false,
sunlight_propagates = true,
buildable_to = true,
paramtype = 'light',
selection_box = plants.grass_sel,
grows_in_month = 7,
grows_to = 'plants:grass_4',
})
minetest.register_node('plants:grass_4', {
description = 'Grass',
tiles = {'plants_grass_4.png'},
drawtype = 'plantlike',
groups = grasses_group,
drop = 'plants:fiber',
waving = 1,
walkable = false,
sunlight_propagates = true,
buildable_to = true,
paramtype = 'light',
selection_box = plants.grass_sel,
grows_in_month = 7,
grows_to = 'plants:grass_5',
})
minetest.register_node('plants:grass_5', {
description = 'Seeding Grass',
tiles = {'plants_grass_5.png'},
drawtype = 'plantlike',
groups = grasses_group,
drop = 'plants:fiber',
waving = 1,
walkable = false,
sunlight_propagates = true,
buildable_to = true,
paramtype = 'light',
selection_box = plants.grass_sel,
grows_in_month = 8,
grows_to = 'spread',
})

7
mods/plants/init.lua Normal file
View File

@ -0,0 +1,7 @@
plants = {}
plants.grass_sel = {type = 'fixed',
fixed = {{-0.4, -0.5, -0.4, 0.4, -0.3, 0.4},}}
dofile(minetest.get_modpath('plants')..'/grasses.lua')
dofile(minetest.get_modpath('plants')..'/mapgen.lua')
dofile(minetest.get_modpath('plants')..'/ABMs.lua')

16
mods/plants/mapgen.lua Normal file
View File

@ -0,0 +1,16 @@
minetest.register_decoration({
deco_type = "simple",
place_on = {"ground:dirt_with_grass"},
sidelen = 16,
noise_params = {
offset = 0,
scale = 0.02,
spread = {x = 100, y = 100, z = 100},
seed = 219,
octaves = 3,
persist = 0.6
},
y_min = 1,
y_max = 30,
decoration = "plants:grass_1",
})

4
mods/plants/mod.conf Normal file
View File

@ -0,0 +1,4 @@
name = plants
depends = common
description = All sorts of plants.
author = Nathan

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -39,13 +39,12 @@ local theme_main = "bgcolor[#080808BB;true]" .. common.gui_bg ..
common.gui_bg_img
local theme_inv = common.gui_slots .. [[
list[current_player;main;0,3.5;8,1;]
list[current_player;main;0,4.5;8,3;8]
list[current_player;main;0,3.5;8,3;]
]]
function sfinv.make_formspec(player, context, content, show_inv, size)
local tmp = {
size or "size[8,7.5]",
size or "size[8,6.25]",
theme_main,
sfinv.get_nav_fs(player, context, context.nav_titles, context.nav_idx),
content

View File

@ -98,9 +98,9 @@ for i in ipairs (ship_parts_colors) do
{shipcol..' Walkway Edge', shipdesc..'es', 'edge_straight', '(spawn_ship_floor.png^['..shipval..')', colbox_floor_edge},
{shipcol..' Floor Angle', shipdesc..'fa', 'floor_angle', '(spawn_ship_floor_angle.png^['..shipval..')', colbox_floor_angle},
{shipcol..' Floor Square', shipdesc..'fs', 'floor_square', '(spawn_ship_floor_double.png^['..shipval..')', colbox_floor_square},
{shipcol..' Ramp Top Right', shipdesc..'r2r', 'ramp-2', '(spawn_ship_floor.png^['..shipval..')^[transform2', colbox_ramp_2},
{shipcol..' Ramp Top Right', shipdesc..'r2r', 'ramp-2', '(spawn_ship_floor.png^['..shipval..')^[transform2', common.colbox_stair},
{shipcol..' Ramp Bottom Right', shipdesc..'r1r', 'ramp-1', '(spawn_ship_floor.png^['..shipval..')^[transform2', colbox_ramp_1},
{shipcol..' Ramp Top Left', shipdesc..'r2l', 'ramp-2', '(spawn_ship_floor.png^['..shipval..')', colbox_ramp_2},
{shipcol..' Ramp Top Left', shipdesc..'r2l', 'ramp-2', '(spawn_ship_floor.png^['..shipval..')', common.colbox_stair},
{shipcol..' Ramp Bottom Left', shipdesc..'r1l', 'ramp-1', '(spawn_ship_floor.png^['..shipval..')', colbox_ramp_1}
}

View File

@ -138,6 +138,7 @@ minetest.register_node('spawn:dongle', {
mesh = 'dongle.obj',
paramtype = 'light',
paramtype2 = 'facedir',
sunlight_propagates = true,
tiles = {'dongle.png'},
groups = {spawn=1},
selection_box = {

View File

@ -7,7 +7,7 @@ formspec_owner =
'list[context;cost;2,1;1,1;]'..
'field[3.3,1.4;1,1;costa;;1]'..
'field[5.3,0.4;3,1;sname;store name;Unconfigured Vending Machine]'..
'field[0.3,2.4;8,1;desc;item description;What this item is.]'..
'field[0.3,2.4;8,1;desc;item description;What this item is.]'..
'button_exit[5,1;3,1;save;Save Vending Machine]'..
'list[current_player;main;0,3;8,4;]'

148
mods/storage/chests.lua Normal file
View File

@ -0,0 +1,148 @@
minetest.register_node('storage:wooden_chest', {
description = 'Wooden Chest',
tiles = {'storage_wooden_chest_top.png',
'storage_wooden_chest_top.png',
'storage_wooden_chest_side.png',
'storage_wooden_chest_side.png',
'storage_wooden_chest_back.png',
'storage_wooden_chest_front.png'},
groups = {choppy=2,oddly_breakable_by_hand=2},
paramtype2 = 'facedir',
-- sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string('formspec', wooden_chest_formspec)
meta:set_string('upgrade', 0)
local inv = meta:get_inventory()
inv:set_size('main', 18)
inv:set_size('sort_upgrade', 1)
inv:set_size('label_upgrade', 1)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:is_empty('main')
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if listname == 'sort_upgrade' then
if inv:is_empty('sort_upgrade') and stack:get_name() == 'ground:dirt' then
return 1
else return 0
end
elseif listname == 'label_upgrade' then
if inv:is_empty('label_upgrade') and stack:get_name() == 'items:label' then
return 1
else return 0
end
else
return 99
end
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if listname == 'sort_upgrade' then
if stack:get_name() == ('ground:dirt') then --Needs changing to something more suitable
local upgrade_val = tonumber(meta:get_string('upgrade'))
local upgrade_new = upgrade_val + 1
print ('upgrade value '..upgrade_new)
meta:set_string('upgrade', upgrade_new)
meta:set_string('formspec', storage.wooden_chest_formspec(pos))
end
end
if listname == 'label_upgrade' then
if stack:get_name() == ('items:label') then
local upgrade_val = tonumber(meta:get_string('upgrade'))
local upgrade_new = upgrade_val + 2
print ('upgrade value '..upgrade_new)
meta:set_string('upgrade', upgrade_new)
meta:set_string('formspec', storage.wooden_chest_formspec(pos))
end
end
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if listname == 'sort_upgrade' then
if stack:get_name() == ('ground:dirt') then
local upgrade_val = tonumber(meta:get_string('upgrade'))
local upgrade_new = upgrade_val - 1
print ('upgrade value '..upgrade_new)
meta:set_string('upgrade', upgrade_new)
meta:set_string('formspec', storage.wooden_chest_formspec(pos))
end
elseif listname == 'label_upgrade' then
if stack:get_name() == ('items:label') then
local upgrade_val = tonumber(meta:get_string('upgrade'))
local upgrade_new = upgrade_val - 2
print ('upgrade value '..upgrade_new)
meta:set_string('upgrade', upgrade_new)
meta:set_string('infotext', '')
meta:set_string('formspec', storage.wooden_chest_formspec(pos))
end
end
end,
allow_metadata_inventory_move = function (pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
if to_list == 'sort_upgrade' then
if inv:is_empty('sort_upgrade') and stack:get_name() == ('ground:dirt') then
return 1
else return 0
end
elseif to_list == 'label_upgrade' then
if inv:is_empty('label_upgrade') and stack:get_name() == ('items:label') then
return 1
else return 0
end
else
return 99
end
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if from_list == 'sort_upgrade' then
local upgrade_val = tonumber(meta:get_string('upgrade'))
local upgrade_new = upgrade_val - 1
print ('upgrade value '..upgrade_new)
meta:set_string('upgrade', upgrade_new)
meta:set_string('formspec', storage.wooden_chest_formspec(pos))
elseif from_list == 'label_upgrade' then
local upgrade_val = tonumber(meta:get_string('upgrade'))
local upgrade_new = upgrade_val - 2
print ('upgrade value '..upgrade_new)
meta:set_string('upgrade', upgrade_new)
meta:set_string('formspec', storage.wooden_chest_formspec(pos))
end
if to_list == 'sort_upgrade' then
local stack = inv:get_stack(to_list, to_index)
if stack:get_name() == ('ground:dirt') then
local upgrade_val = tonumber(meta:get_string('upgrade'))
local upgrade_new = upgrade_val + 1
print ('upgrade value '..upgrade_new)
meta:set_string('upgrade', upgrade_new)
meta:set_string('formspec', storage.wooden_chest_formspec(pos))
end
elseif to_list == 'label_upgrade' then
local stack = inv:get_stack(to_list, to_index)
if stack:get_name() == ('items:label') then
local upgrade_val = tonumber(meta:get_string('upgrade'))
local upgrade_new = upgrade_val + 2
print ('upgrade value '..upgrade_new)
meta:set_string('upgrade', upgrade_new)
meta:set_string('formspec', storage.wooden_chest_formspec(pos))
end
end
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
if fields ['save'] then
meta:set_string('infotext', fields.description)
meta:set_string('formspec', storage.wooden_chest_formspec(pos, fields.description))
elseif fields ['sort'] then
storage.sort_inventory(meta:get_inventory())
end
end,
})

1
mods/storage/depends.txt Normal file
View File

@ -0,0 +1 @@
common

View File

@ -0,0 +1,12 @@
wooden_chest_formspec =
'size[8,7.75]'..
common.gui_bg..
common.gui_bg_img..
common.gui_slots..
'label[.5,.25;Upgrades]'..
'image[2,0;1,1;storage_label_outline.png]'..
'list[current_name;label_upgrade;2,0;1,1]'..
'list[current_name;sort_upgrade;3,0;1,1]'..
'list[current_name;main;1,1;6,3;]'..
'list[current_player;main;0,5;8,3;]'..
'listring[]'

View File

@ -0,0 +1,88 @@
function storage.wooden_chest_formspec(pos, name)
local meta = minetest.get_meta(pos)
local existing_name = meta:get_string('infotext')
name = name or existing_name
local label = 'image[0,4;1,1;storage_label.png]'..
'field[1.3,4.3;2,1;description;;'..name..']'..
'button[3,4;1,1;save;Save]'
local sort = 'button[4,4;1,1;sort;Sort]'
local base =
'size[8,7.75]'..
common.gui_bg..
common.gui_bg_img..
common.gui_slots..
'label[.5,.25;Upgrades]'..
'image[2,0;1,1;storage_label_outline.png]'..
'list[current_name;label_upgrade;2,0;1,1]'..
'list[current_name;sort_upgrade;3,0;1,1]'..
'list[current_name;main;1,1;6,3;]'..
'list[current_player;main;0,5;8,3;]'..
'listring[]'
local upgrade_tier = tonumber(meta:get_string('upgrade'))
if upgrade_tier == 0 then
local formspec =
base
return formspec
elseif upgrade_tier == 1 then --Sorting
local formspec =
base..sort
return formspec
elseif upgrade_tier == 2 then --Labeling
local formspec =
base..label
return formspec
elseif upgrade_tier == 3 then --Sorting & Labeling
local formspec =
base..label..sort
return formspec
end
end
function storage.sort_inventory(inv) -- Copied from the Technic_chests mod.
local inlist = inv:get_list("main")
local typecnt = {}
local typekeys = {}
for _, st in ipairs(inlist) do
if not st:is_empty() then
local n = st:get_name()
local w = st:get_wear()
local m = st:get_metadata()
local k = string.format("%s %05d %s", n, w, m)
if not typecnt[k] then
typecnt[k] = {
name = n,
wear = w,
metadata = m,
stack_max = st:get_stack_max(),
count = 0,
}
table.insert(typekeys, k)
end
typecnt[k].count = typecnt[k].count + st:get_count()
end
end
table.sort(typekeys)
local outlist = {}
for _, k in ipairs(typekeys) do
local tc = typecnt[k]
while tc.count > 0 do
local c = math.min(tc.count, tc.stack_max)
table.insert(outlist, ItemStack({
name = tc.name,
wear = tc.wear,
metadata = tc.metadata,
count = c,
}))
tc.count = tc.count - c
end
end
if #outlist > #inlist then return end
while #outlist < #inlist do
table.insert(outlist, ItemStack(nil))
end
inv:set_list("main", outlist)
end

4
mods/storage/init.lua Normal file
View File

@ -0,0 +1,4 @@
storage = {}
dofile(minetest.get_modpath('storage')..'/functions.lua')
dofile(minetest.get_modpath('storage')..'/formspecs.lua')
dofile(minetest.get_modpath('storage')..'/chests.lua')

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB