diff --git a/compatibility.lua b/compatibility.lua index 8478975..f2cc441 100644 --- a/compatibility.lua +++ b/compatibility.lua @@ -479,6 +479,7 @@ if industrialtest.mclAvailable then industrialtest.gameTexturePrefix="mcl" -- assign element keys for elements that are required later industrialtest.elementKeys.stick="mcl_core:stick" + industrialtest.elementKeys.junglePlanks="mcl_core:junglewood" industrialtest.elementKeys.ironIngot="mcl_core:iron_ingot" industrialtest.elementKeys.copperIngot="mcl_copper:copper_ingot" industrialtest.elementKeys.powerCarrier="mesecons:mesecon" @@ -645,6 +646,7 @@ elseif industrialtest.mtgAvailable then industrialtest.elementKeys.ironIngot="default:steel_ingot" industrialtest.elementKeys.copperIngot="default:copper_ingot" industrialtest.elementKeys.stick="default:stick" + industrialtest.elementKeys.junglePlanks="default:junglewood" industrialtest.elementKeys.powerCarrier="default:mese_crystal_fragment" industrialtest.elementKeys.furnace="default:furnace" else diff --git a/init.lua b/init.lua index 72e038c..b7e824a 100644 --- a/init.lua +++ b/init.lua @@ -24,6 +24,9 @@ industrialtest={} industrialtest.updateDelay=1 -- Note: Make this value smaller to make machines update more frequently (it may make server more laggy) industrialtest.developerMode=true -- Enables additional utils useful when developing mod +-- Others +industrialtest.random=PseudoRandom(os.time()) + -- load other lua files dofile(modpath.."/compatibility.lua") dofile(modpath.."/api.lua") @@ -35,3 +38,4 @@ if industrialtest.developerMode then dofile(modpath.."/utils.lua") end dofile(modpath.."/cables.lua") +dofile(modpath.."/mapgen.lua") diff --git a/mapgen.lua b/mapgen.lua new file mode 100644 index 0000000..af5b4fb --- /dev/null +++ b/mapgen.lua @@ -0,0 +1,58 @@ +-- IndustrialTest +-- Copyright (C) 2023 mrkubax10 + +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +local definition={ + name="industrialtest:rubber_tree", + deco_type="schematic", + sidelen=16, + noise_params={ + offset=0.024, + scale=0.015, + spread={x=250,y=250,z=250}, + seed=2, + octaves=3, + persist=0.66 + }, + schematic={ + size=vector.new(1,1,1), + data={ + { + name="industrialtest:rubber_sapling", + param2=1 + } + } + }, + flags="place_center_x, place_center_z" +} +if industrialtest.mtgAvailable then + definition.place_on={"default:dirt_with_grass"} + definition.biomes={"deciduous_forest"} + definition.y_max=31000 + definition.y_min=1 +end +minetest.register_decoration(definition) +minetest.register_lbm({ + label="Make rubber trees", + name="industrialtest:make_rubber_trees", + nodenames={"industrialtest:rubber_sapling"}, + run_at_every_load=false, + action=function(pos) + local node=minetest.get_node(pos) + if node.param2==1 then + industrialtest.makeRubberTree(pos) + end + end +}) diff --git a/nodes.lua b/nodes.lua index d53e783..a5e5225 100644 --- a/nodes.lua +++ b/nodes.lua @@ -21,10 +21,10 @@ local definition={ tiles={"industrialtest_machine_block.png"}, } if industrialtest.mtgAvailable then - definition.sound=default.node_sound_metal_defaults() + definition.sounds=default.node_sound_metal_defaults() definition.groups={cracky=1,level=2} elseif industrialtest.mclAvailable then - definition.sound=mcl_sounds.node_sound_metal_defaults() + definition.sounds=mcl_sounds.node_sound_metal_defaults() definition._mcl_blast_resistance=6 definition._mcl_hardness=5 end @@ -39,6 +39,313 @@ minetest.register_craft({ } }) +definition={ + description=S("Rubber Wood"), + tiles={ + "industrialtest_rubber_wood_top.png", + "industrialtest_rubber_wood_top.png", + "industrialtest_rubber_wood_side.png" + }, + paramtype2="4dir" +} +if industrialtest.mtgAvailable then + definition.sounds=default.node_sound_wood_defaults() + definition.groups={ + tree=1, + choppy=2, + oddly_breakable_by_hand=1, + flammable=2 + } +elseif industrialtest.mclAvailable then + definition.sounds=mcl_sounds.node_sound_wood_defaults() + definition.groups={ + handy=1, + axey=1, + tree=1, + flammable=2, + building_block=1, + material_wood=1, + fire_encouragement=5, + fire_flammability=5 + } + definition.after_destruct=mcl_core.update_leaves + definition._mcl_blast_resistance=1.8 + definition._mcl_hardness=1.8 +end +definition.groups._industrialtest_rubberWood=1 +minetest.register_node("industrialtest:rubber_wood",definition) +definition=table.copy(definition) +definition.description=nil +definition.tiles={ + "industrialtest_rubber_wood_top.png", + "industrialtest_rubber_wood_top.png", + "industrialtest_rubber_wood_side.png", + "industrialtest_rubber_wood_side.png", + "industrialtest_rubber_wood_side_with_rubber.png", + "industrialtest_rubber_wood_side.png" +} +definition.drop="industrialtest:rubber_wood" +if industrialtest.mclAvailable then + definition.groups.not_in_creative_inventory=1 + definition._doc_items_create_entry=false +end +minetest.register_node("industrialtest:rubber_wood_with_rubber",definition) +minetest.register_abm({ + label="Rubber forming", + nodenames={"industrialtest:rubber_wood"}, + interval=120, + chance=2, + action=function(pos) + local neighbourPositions={ + vector.offset(pos,-1,0,0), + vector.offset(pos,1,0,0), + vector.offset(pos,0,-1,0), + vector.offset(pos,0,1,0), + vector.offset(pos,0,0,-1), + vector.offset(pos,0,0,1) + } + for _,value in ipairs(neighbourPositions) do + if minetest.get_node(value).name=="industrialtest:rubber_wood_with_rubber" then + return + end + end + minetest.set_node(pos,{ + name="industrialtest:rubber_wood_with_rubber", + param2=industrialtest.random:next(0,3) + }) + end +}) +minetest.register_craft({ + type="shapeless", + output=industrialtest.elementKeys.junglePlanks.." 3", + recipe={"group:_industrialtest_rubberWood"} +}) +definition={ + description=S("Rubber Leaves"), + drawtype="allfaces_optional", + tiles={"industrialtest_rubber_leaves.png"}, + special_tiles={"industrialtest_rubber_leaves_simple.png"}, + paramtype="light", + sunlight_propagates=true, + waving=1 +} +if industrialtest.mtgAvailable then + definition.sounds=default.node_sound_leaves_defaults() + definition.groups={ + snappy=3, + leafdecay=3, + flammable=2, + leaves=1 + } + definition.drop={ + max_items=1, + items={ + { + items={"industrialtest:rubber_sapling"}, + rarity=20 + }, + {items={"industrialtest:rubber_leaves"}} + } + } + definition.after_place_node=default.after_place_leaves +elseif industrialtest.mclAvailable then + local saplingChances={20,16,12,10} + local stickChances={50,45,30,35,10} + -- Taken and adapted from https://git.minetest.land/MineClone2/MineClone2/src/branch/master/mods/ITEMS/mcl_core/nodes_trees.lua#L157 + local function getDrops(fortuneLevel) + local drop = { + max_items=1, + items = { + { + items = {"industrialtest:rubber_sapling"}, + rarity = saplingChances[fortuneLevel+1] or saplingChances[fortuneLevel] + }, + { + items = {"mcl_core:stick 1"}, + rarity = stickChances[fortuneLevel+1] + }, + { + items = {"mcl_core:stick 2"}, + rarity = stickChances[fortuneLevel+1] + }, + } + } + return drop + end + definition.sounds=mcl_sounds.node_sound_leaves_defaults() + definition.groups={ + handy=1, + hoey=1, + shearsy=1, + swordy=1, + dig_by_piston=1, + flammable=2, + fire_encouragement=30, + fire_flammability=60, + leaves=1, + deco_block=1, + compostability=30 + } + definition.drop=getDrops(0) + definition.after_place_node=mcl_core.make_player_leaves + definition._mcl_shears_drop=true + definition._mcl_blast_resistance=0.2 + definition._mcl_hardness=0.2 + definition._mcl_silk_touch_drop=true + definition._mcl_fortune_drop={getDrops(1),getDrops(2),getDrops(3),getDrops(4)} +end +minetest.register_node("industrialtest:rubber_leaves",definition) +if industrialtest.mtgAvailable then + default.register_leafdecay({ + trunks={"industrialtest:rubber_wood"}, + leaves={"industrialtest:rubber_leaves"}, + radius=2 + }) +end +if industrialtest.mclAvailable then + definition=table.copy(definition) + definition._doc_items_create_entry=false + definition.groups.not_in_creative_inventory=1 + definition.groups.orphan_leaves=1 + definition._mcl_shears_drop={"industrialtest:rubber_leaves"} + definition._mcl_silk_touch_drop={"industrialtest:rubber_leaves"} + minetest.register_node("industrialtest:rubber_leaves_orphan",definition) +end +industrialtest.makeRubberTree=function(pos) + -- FIXME: Replace this with placing schematic + -- Taken and adapted from https://github.com/minetest/minetest_game/blob/master/mods/default/trees.lua#L182 + minetest.chat_send_all("Making rubber sapling") + local height=industrialtest.random:next(4,5) + local tree=minetest.get_content_id("industrialtest:rubber_wood") + local leaves=minetest.get_content_id("industrialtest:rubber_leaves") + local air=minetest.get_content_id("air") + local ignore=minetest.get_content_id("ignore") + + local manip=minetest.get_voxel_manip() + local minp,maxp=manip:read_from_map(vector.new(pos.x-2,pos.y,pos.z),vector.new(pos.x+2,pos.y+height+1,pos.z+2)) + local area=VoxelArea:new({ + MinEdge=minp, + MaxEdge=maxp + }) + local data=manip:get_data() + + -- Trunk + data[area:index(pos.x,pos.y,pos.z)]=tree + for y=pos.y+1,pos.y+height-1 do + local index=area:index(pos.x,y,pos.z) + local id=data[index] + if id==air or id==ignore or id==leaves then + data[index]=tree + end + end + -- Force leaves near the trunk + for dz=-1,1 do + for dy=-2,1 do + local index=area:index(pos.x-1,pos.y+height+dy,pos.z+dz) + for dx=-1,1 do + if data[index]==air or data[index]==ignore then + data[index]=leaves + end + index=index+1 + end + end + end + -- Randomly add leaves in 2x2x2 clusters. + for i=1,8 do + local x=pos.x+industrialtest.random:next(-2,1) + local y=pos.y+height+industrialtest.random:next(-2,0) + local z=pos.z+industrialtest.random:next(-2,1) + for dx=0,1 do + for dy=0,1 do + for dz=0,1 do + local index=area:index(x+dx,y+dy,z+dz) + if data[index]==air or data[index]==ignore then + data[index]=leaves + end + end + end + end + end + + manip:set_data(data) + manip:write_to_map() + manip:update_map() +end +definition={ + description=S("Rubber Sapling"), + inventory_image="industrialtest_rubber_sapling.png", + wield_image="industrialtest_rubber_sapling.png", + drawtype="plantlike", + tiles={"industrialtest_rubber_sapling.png"}, + paramtype="light", + sunlight_propagates=true, + walkable=false, + waving=1, + on_timer=function(pos) + -- Use MTG can_grow function if available + local canGrow + if industrialtest.mtgAvailable then + canGrow=default.can_grow + elseif industrialtest.mclAvailable then + canGrow=function(pos) + local under=minetest.get_node_or_nil(vector.offset(pos,0,-1,0)) + if not under then + return false + end + local lightLevel=minetest.get_node_light(pos) + return (minetest.get_item_group(under.name,"soil")>0 and lightLevel and lightLevel>=13) + end + end + + if not canGrow(pos) then + minetest.get_node_timer(pos):start(300) + return false + end + + industrialtest.makeRubberTree(pos) + + return false + end +} +if industrialtest.mtgAvailable then + definition.sounds=default.node_sound_leaves_defaults() + definition.groups={ + snappy=2, + flammable=2 + } + definition.on_construct=function(pos) + minetest.get_node_timer(pos):start(industrialtest.random:next(300,1500)) + end +elseif industrialtest.mclAvailable then + definition.sounds=mcl_sounds.node_sound_leaves_defaults() + definition.groups={ + plant=1, + non_mycelium_plant=1, + deco_block=1, + dig_by_water=1, + dig_by_piston=1, + destroy_by_lava_flow=1, + compostability=40 + } + definition.on_construct=function(pos) + local meta=minetest.get_meta(pos) + meta:set_int("stage",0) + end +end +definition.groups.attached_node=1 +definition.groups.dig_immediate=3 +definition.groups.sapling=1 +minetest.register_node("industrialtest:rubber_sapling",definition) +if industrialtest.mtgAvailable then + minetest.register_lbm({ + name="industrialtest:rubber_sapling_lbm", + nodenames={"industrialtest:rubber_sapling"}, + action=function(pos) + minetest.get_node_timer(pos):start(industrialtest.random:next(300,1500)) + end + }) +end + -- Node callbacks minetest.register_on_placenode(function(pos,newNode) local def=minetest.registered_nodes[newNode.name]