Compare commits
3 Commits
a15e6ab8c0
...
5fec39dd86
Author | SHA1 | Date |
---|---|---|
Pascal Abresch | 5fec39dd86 | |
Pascal Abresch | d4a02d7b16 | |
Pascal Abresch | e6c6682ec0 |
|
@ -1,36 +1,70 @@
|
|||
orion.craft = {}
|
||||
orion.craft.type = {}
|
||||
|
||||
|
||||
orion.craft.register = function(craft_type, inputs, outputs)
|
||||
--local err, craft_type, recipe, output = orion.args(3, "craft_type", "inputs", "outputs", arg)
|
||||
--if err then return false, err end
|
||||
orion.craft.register = function(craft_type, inputs, output)
|
||||
-- example
|
||||
-- inputs = { "orionworld:stone": 3, "orioncraft:stick": 1 }
|
||||
-- outpus = { "orionworld:fire": 1}
|
||||
|
||||
if #inputs > 32 then return false, "Maximum 32 inputs for recipe" end
|
||||
if #outputs > 32 then return false, "Maximum 32 outputs for recipe" end
|
||||
|
||||
inputs = table.sort(inputs)
|
||||
|
||||
if not orion.craft.type[craft_type] then orion.craft.type[craft_type] = {} end
|
||||
local present = false
|
||||
for i in pairs(orion.craft.type[craft_type]) do
|
||||
present = true
|
||||
for x = 1, #i do
|
||||
if i[x] ~= inputs[x] then
|
||||
present = false
|
||||
break
|
||||
end
|
||||
if present then break end
|
||||
end
|
||||
end
|
||||
if present then
|
||||
return false, "recipe already asigned!"
|
||||
end
|
||||
table.insert(orion.craft.type[craft_type], table)
|
||||
-- Make sure there are no duplicates... later
|
||||
|
||||
table.insert(orion.craft.type[craft_type], { inputs = inputs, output = output})
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
local getItemInListCount = function(inventoryList, itemNameSearch)
|
||||
local count = 0
|
||||
for index, item in pairs(inventoryList) do
|
||||
local itemNameInventory = item:get_name()
|
||||
if itemNameSearch == itemNameInventory then
|
||||
count = count + item:get_count()
|
||||
end
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
|
||||
orion.get_possible_crafts = function(craft_type, inventoryList)
|
||||
local craftTable = orion.craft.type[craft_type]
|
||||
-- craftTable = {{ inputs = inputs, outputs = outputs}, { inputs = inputs, outputs = outputs}}
|
||||
if not craftTable then return {} end
|
||||
local resultsTable = {}
|
||||
-- search through the table I guess
|
||||
for _, entry in pairs(craftTable) do
|
||||
-- entry = { inputs = inputs, output = output}
|
||||
local validCount = nil
|
||||
for craftName, craftItemStack in pairs(entry["inputs"]) do
|
||||
local count = math.floor(getItemInListCount(inventoryList, craftName) / craftItemStack)
|
||||
if validCount == nil then validCount = count else
|
||||
validCount = math.min(validCount, count)
|
||||
end
|
||||
end
|
||||
-- 4 sticks 3 steine
|
||||
-- 12 sticks und 20 steins
|
||||
-- 12 sticks / 4 sticks = 3 resultate
|
||||
-- 20 steine / 3 steine = 6,irgendwass
|
||||
-- min(beiden)
|
||||
|
||||
-- output = { "mynode:blah" = 1 }
|
||||
if validCount >= 1 then
|
||||
local newItemStack
|
||||
for stackName, stackCount in pairs(entry["output"]) do
|
||||
newItemStack = ItemStack(stackName .. " " .. validCount * stackCount)
|
||||
end
|
||||
|
||||
table.insert(resultsTable, newItemStack)
|
||||
print(dump2(resultsTable))
|
||||
end
|
||||
end
|
||||
return resultsTable
|
||||
end
|
||||
|
||||
|
||||
|
||||
orion.register_craftitem = function(name, description)
|
||||
minetest.register_craftitem(NAME .. ":" .. name, {
|
||||
description = description,
|
||||
|
|
|
@ -224,3 +224,21 @@ orion.register_slab_node = function(name, definition)
|
|||
opaqueNodes[name] = definition
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local decoslab_enabled = minetest.settings:get("orion_world_gen_decoslabs")
|
||||
function orion.worldgen_register_decoration_slab(name)
|
||||
if decoslab_enabled then
|
||||
minetest.register_decoration({
|
||||
deco_type = "simple",
|
||||
check_offset = 0,
|
||||
num_spawn_by = 1,
|
||||
place_on = NAME .. ":" .. name,
|
||||
spawn_by = NAME .. ":" .. name,
|
||||
decoration = NAME .. ":".. name .."_lower",
|
||||
name = NAME .. ":".. name .."_lower",
|
||||
height = 1,
|
||||
fill_ratio = 10,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,12 +18,11 @@ end
|
|||
|
||||
|
||||
orion.register_smeltable = function(mod, name, recipe)
|
||||
minetest.register_craft({
|
||||
output = mod .. ":" .. name,
|
||||
type = "cooking",
|
||||
cooktime = 4,
|
||||
recipe = recipe
|
||||
})
|
||||
local newRecipe = {}
|
||||
newRecipe[recipe] = 1
|
||||
local newResult = {}
|
||||
newResult[mod .. ":" .. name] = 1
|
||||
orion.craft.register("hand", newRecipe, newResult)
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ minetest.register_tool(NAME .. ":hatchet", {
|
|||
times = {
|
||||
[1] = 2 ,
|
||||
[2] = 3.2,
|
||||
[3] = 5,
|
||||
[3] = 5
|
||||
},
|
||||
maxlevel = 3
|
||||
},
|
||||
|
@ -43,20 +43,8 @@ minetest.register_craftitem(NAME .. ":rope" , {
|
|||
})
|
||||
|
||||
|
||||
orion.craft.register("hand", {FLORA .. ":flax"}, {NAME .. ":rope"})
|
||||
minetest.register_craft({
|
||||
output = NAME .. ":rope";
|
||||
type = "shapeless";
|
||||
recipe = {FLORA .. ":flax"};
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = NAME .. ":hatchet",
|
||||
type = "shapeless",
|
||||
recipe = {
|
||||
NAME .. ":rope",
|
||||
FLORA .. ":stick",
|
||||
NAME .. ":rock"
|
||||
}
|
||||
})
|
||||
local input = {}
|
||||
input[FLORA .. ":flax"] = 1
|
||||
local output = {}
|
||||
output[NAME .. ":rope"] = 1
|
||||
orion.craft.register("hand", input, output)
|
||||
|
|
|
@ -17,6 +17,7 @@ minetest.register_node(NAME .. ":grass_top", {
|
|||
},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_decoration({
|
||||
deco_type = "simple",
|
||||
place_on = "orionworld:grass",
|
||||
|
|
|
@ -36,7 +36,7 @@ local function update_scale(player, scale)
|
|||
},
|
||||
collisionbox = { -0.4125 * scale, 0.0, -0.415 * scale, 0.4125 * scale , 1.7 * scale, 0.4125 * scale }
|
||||
})
|
||||
|
||||
|
||||
player:set_physics_override({
|
||||
jump= 0.9 * scale,
|
||||
gravity= 0.9,
|
||||
|
@ -62,7 +62,7 @@ minetest.register_chatcommand("scale", {
|
|||
local playerObj = nil
|
||||
if #params == 1 then
|
||||
playerObj = minetest.get_player_by_name(name)
|
||||
scale = tonumber(params[1])
|
||||
scale = tonumber(params[1])
|
||||
else
|
||||
playerObj = minetest.get_player_by_name(params[1])
|
||||
scale = tonumber(params[2])
|
||||
|
@ -122,6 +122,30 @@ local function populateCreativeInventory(player)
|
|||
end
|
||||
|
||||
|
||||
function populateSurvivalInventory(player)
|
||||
local inventory = player:get_inventory()
|
||||
local mainInventory = inventory:get_list("main")
|
||||
inventory:set_list("crafting", nil)
|
||||
local newList = orion.get_possible_crafts("hand", mainInventory)
|
||||
local listCount = 0
|
||||
if newList then listCount = #newList end
|
||||
inventory:set_size("crafting", listCount)
|
||||
inventory:set_list("crafting", newList)
|
||||
end
|
||||
|
||||
minetest.register_on_item_pickup(function(itemstack, picker, pointed_thing, time_from_last_punch)
|
||||
populateSurvivalInventory(picker)
|
||||
end)
|
||||
|
||||
minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv)
|
||||
populateSurvivalInventory(player)
|
||||
end)
|
||||
|
||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||
populateSurvivalInventory(digger)
|
||||
end)
|
||||
|
||||
|
||||
minetest.register_allow_player_inventory_action(function(player, action, inventory, inventory_info)
|
||||
-- action can be "move" "put" "take", the later two ONLY when NOT dealing with player-owned inventories
|
||||
--
|
||||
|
@ -238,6 +262,8 @@ minetest.register_on_joinplayer(function(player)
|
|||
--player:set_lighting({shadows = { intensity = 0.33} })
|
||||
if minetest.is_creative_enabled(player) then
|
||||
populateCreativeInventory(player)
|
||||
else
|
||||
populateSurvivalInventory(player)
|
||||
end
|
||||
-- TODO: survival crafting
|
||||
local lists = inventory:get_lists()
|
||||
|
|
|
@ -3,19 +3,7 @@ NAME = minetest:get_current_modname()
|
|||
minetest.register_alias("mapgen_stone", NAME .. ":stone")
|
||||
minetest.register_alias("mapgen_dirt", NAME .. ":dirt")
|
||||
|
||||
local decoslab_enabled = minetest.settings:get("orion_world_gen_decoslabs")
|
||||
local function register_decoration_slab(name)
|
||||
minetest.register_decoration({
|
||||
deco_type = "simple",
|
||||
num_spawn_by = 9,
|
||||
place_on = NAME .. ":" .. name,
|
||||
spawn_by = NAME .. ":" .. name,
|
||||
decoration = NAME .. ":".. name .."_lower",
|
||||
name = NAME .. ":".. name .."_lower",
|
||||
height = 1,
|
||||
fill_ratio = 10,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
local function register_plain_node(name, description, groups)
|
||||
|
@ -25,9 +13,7 @@ local function register_plain_node(name, description, groups)
|
|||
groups = groups,
|
||||
sounds = { footstep = {name = NAME .. "_" .. name } }
|
||||
})
|
||||
if decoslab_enabled then
|
||||
register_decoration_slab(name)
|
||||
end
|
||||
orion.worldgen_register_decoration_slab(name)
|
||||
end
|
||||
|
||||
|
||||
|
@ -40,6 +26,7 @@ orion.register_slab_node(NAME .. ":ice", {
|
|||
drawtype = "glasslike",
|
||||
inventory_image = NAME .. "_ice_icon.png"
|
||||
})
|
||||
orion.worldgen_register_decoration_slab(NAME .. ":ice")
|
||||
|
||||
|
||||
orion.register_slab_node(NAME .. ":glass", {
|
||||
|
|
Loading…
Reference in New Issue