From 62a3e2aa4069fda674d00e2167ef7fb9bd5ee3d1 Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Wed, 6 Mar 2024 19:21:36 +0100 Subject: [PATCH] Fix Rubber Sapling not growing in MCL --- mapgen.lua | 2 +- mod.conf | 4 +-- nodes.lua | 91 ++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 67 insertions(+), 30 deletions(-) diff --git a/mapgen.lua b/mapgen.lua index d8e7ee4..3380a44 100644 --- a/mapgen.lua +++ b/mapgen.lua @@ -21,6 +21,6 @@ minetest.register_on_generated(function(minp,maxp,seed) local center=vector.new((maxp.x-minp.x)/2+ minp.x,(maxp.y-minp.y)/2+minp.y,(maxp.z-minp.z)/2+minp.z) local pos=minetest.find_node_near(center,maxp.x-minp.x,{industrialtest.elementKeys.grassBlock}) if pos then - industrialtest.makeRubberTree(pos) + industrialtest.internal.makeRubberTree(pos) end end) diff --git a/mod.conf b/mod.conf index 543305a..a2b2165 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name=industrialtest description=Adds various machinery -optional_depends=default,bucket,3d_armor,mcl_core,mcl_copper,mcl_armor,mcl_deepslate,mcl_nether,mcl_buckets,pipeworks +optional_depends=default,bucket,3d_armor,mcl_core,mcl_copper,mcl_armor,mcl_deepslate,mcl_nether,mcl_buckets,mcl_util,mcl_dye,mcl_rubber,pipeworks author=IndustrialTest Team -title=IndustrialTest \ No newline at end of file +title=IndustrialTest diff --git a/nodes.lua b/nodes.lua index e8e1fc3..78f683a 100644 --- a/nodes.lua +++ b/nodes.lua @@ -239,7 +239,7 @@ if not industrialtest.mods.mclRubber then definition._mcl_silk_touch_drop={"industrialtest:rubber_leaves"} minetest.register_node("industrialtest:rubber_leaves_orphan",definition) end - industrialtest.makeRubberTree=function(pos) + industrialtest.internal.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 local height=industrialtest.random:next(4,5) @@ -308,32 +308,7 @@ if not industrialtest.mods.mclRubber then 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 + waving=1 } if industrialtest.mtgAvailable then definition.sounds=default.node_sound_leaves_defaults() @@ -344,6 +319,16 @@ if not industrialtest.mods.mclRubber then definition.on_construct=function(pos) minetest.get_node_timer(pos):start(industrialtest.random:next(300,1500)) end + definition.on_timer=function(pos) + if not default.can_grow(pos) then + minetest.get_node_timer(pos):start(300) + return false + end + + industrialtest.internal.makeRubberTree(pos) + + return false + end elseif industrialtest.mclAvailable then definition.sounds=mcl_sounds.node_sound_leaves_defaults() definition.groups={ @@ -359,6 +344,58 @@ if not industrialtest.mods.mclRubber then local meta=minetest.get_meta(pos) meta:set_int("stage",0) end + definition.on_place=mcl_util.generate_on_place_plant_function(function(pos,node) + local nodeBelow = minetest.get_node_or_nil(vector.new(pos.x,pos.y-1,pos.z)) + if not nodeBelow then + return false + end + local name = nodeBelow.name + return minetest.get_item_group(name,"grass_block")==1 or + name=="mcl_core:podzol" or name=="mcl_core:podzol_snow" or + name=="mcl_core:dirt" or name=="mcl_core:mycelium" or name=="mcl_core:coarse_dirt" + end) + minetest.register_abm({ + label="Rubber sapling growing", + nodenames={"industrialtest:rubber_sapling"}, + interval=120, + chance=1, + catch_up=false, + action=function(pos) + local under=minetest.get_node_or_nil(vector.offset(pos,0,-1,0)) + if not under or minetest.get_item_group(under.name,"soil")==0 then + return + end + local lightLevel=minetest.get_node_light(pos) + if not lightLevel or lightLevel<13 then + return + end + local meta=minetest.get_meta(pos) + local stage=meta:get_int("stage") or 0 + stage=stage+1 + if stage>=3 then + industrialtest.internal.makeRubberTree(pos) + else + meta:set_int("stage",stage) + end + end + }) + mcl_dye.register_on_bone_meal_apply(function(pointed) + local node=minetest.get_node(pointed.under) + if node.name~="industrialtest:rubber_sapling" then + return + end + if industrialtest.random:next(1,100)>45 then + return + end + local meta=minetest.get_meta(pointed.under) + local stage=meta:get_int("stage") or 0 + stage=stage+1 + if stage>=3 then + industrialtest.internal.makeRubberTree(pointed.under) + else + meta:set_int("stage",stage) + end + end) end definition.groups.attached_node=1 definition.groups.dig_immediate=3