From a714751f8b692d1da7b5e6449b1ec88b08801067 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 17 Dec 2019 19:52:19 +0100 Subject: [PATCH] Add seagrass on dirt --- mods/ITEMS/mcl_ocean/init.lua | 3 + mods/ITEMS/mcl_ocean/seagrass.lua | 98 ++++++++++++++++++ .../mcl_ocean/textures/mcl_ocean_seagrass.png | Bin 0 -> 1547 bytes 3 files changed, 101 insertions(+) create mode 100644 mods/ITEMS/mcl_ocean/seagrass.lua create mode 100644 mods/ITEMS/mcl_ocean/textures/mcl_ocean_seagrass.png diff --git a/mods/ITEMS/mcl_ocean/init.lua b/mods/ITEMS/mcl_ocean/init.lua index ee19cab3..aee7ead1 100644 --- a/mods/ITEMS/mcl_ocean/init.lua +++ b/mods/ITEMS/mcl_ocean/init.lua @@ -3,3 +3,6 @@ dofile(minetest.get_modpath(minetest.get_current_modname()).."/prismarine.lua") -- Corals dofile(minetest.get_modpath(minetest.get_current_modname()).."/corals.lua") + +-- Seagrass +dofile(minetest.get_modpath(minetest.get_current_modname()).."/seagrass.lua") diff --git a/mods/ITEMS/mcl_ocean/seagrass.lua b/mods/ITEMS/mcl_ocean/seagrass.lua new file mode 100644 index 00000000..7c16870a --- /dev/null +++ b/mods/ITEMS/mcl_ocean/seagrass.lua @@ -0,0 +1,98 @@ +local S = minetest.get_translator("mcl_ocean") + +local function seagrass_on_place(itemstack, placer, pointed_thing) + if pointed_thing.type ~= "node" or not placer then + return itemstack + end + + local player_name = placer:get_player_name() + local pos_under = pointed_thing.under + local pos_above = pointed_thing.above + local node_under = minetest.get_node(pos_under) + local node_above = minetest.get_node(pos_above) + local def_under = minetest.registered_nodes[node_under.name] + local def_above = minetest.registered_nodes[node_above.name] + + if def_under and def_under.on_rightclick and not placer:get_player_control().sneak then + return def_under.on_rightclick(pos_under, node_under, + placer, itemstack, pointed_thing) or itemstack + end + + if pos_under.y >= pos_above.y then + return itemstack + end + + -- Placement rules: + -- Seagrass can only be placed on top of dirt inside water + local g_above_water = minetest.get_item_group(node_above.name, "water") + if not (g_above_water ~= 0 and def_above.liquidtype == "source") then + return itemstack + end + + if minetest.is_protected(pos_under, player_name) or + minetest.is_protected(pos_above, player_name) then + minetest.log("action", player_name + .. " tried to place " .. itemstack:get_name() + .. " at protected position " + .. minetest.pos_to_string(pos_under)) + minetest.record_protection_violation(pos_under, player_name) + return itemstack + end + + if node_under.name ~= "mcl_core:dirt" then + return itemstack + end + node_under.name = "mcl_ocean:seagrass_dirt" + node_under.param2 = minetest.registered_items[itemstack:get_name()].place_param2 or 3 + if node_under.param2 < 8 and math.random(1,2) == 1 then + -- Random horizontal displacement + node_under.param2 = node_under.param2 + 8 + end + minetest.set_node(pos_under, node_under) + if not (minetest.settings:get_bool("creative_mode")) then + itemstack:take_item() + end + + return itemstack +end + +-- Seagrass on dirt + +minetest.register_node("mcl_ocean:seagrass_dirt", { + description = S("Seagrass"), + drawtype = "plantlike_rooted", + paramtype = "light", + paramtype2 = "meshoptions", + place_param2 = 3, + tiles = { "default_dirt.png" }, + special_tiles = { + { + image = "mcl_ocean_seagrass.png", + animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length=1.0}, + } + }, + inventory_image = "mcl_ocean_seagrass.png^[verticalframe:12:0", + wield_image = "mcl_ocean_seagrass.png^[verticalframe:12:0", + selection_box = { + type = "fixed", + fixed = { + { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }, + { -6/16, -8/16, -6/16, 6/16, 4/16, 6/16 }, + }, + }, + groups = { dig_immediate = 3, deco_block = 1, plant = 1, seagrass = 1, }, + sounds = mcl_sounds.node_sound_leaves_defaults({footstep = mcl_sounds.node_sound_dirt_defaults().footstep}), + node_placement_prediction = "", + node_dig_prediction = "mcl_core:dirt", + on_place = seagrass_on_place, + after_destruct = function(pos) + local node = minetest.get_node(pos) + if minetest.get_item_group(node.name, "seagrass") == 0 then + minetest.set_node(pos, {name="mcl_core:dirt"}) + end + end, + drop = "", + _mcl_shears_drop = true, + _mcl_hardness = 0, + _mcl_blast_resistance = 0, +}) diff --git a/mods/ITEMS/mcl_ocean/textures/mcl_ocean_seagrass.png b/mods/ITEMS/mcl_ocean/textures/mcl_ocean_seagrass.png new file mode 100644 index 0000000000000000000000000000000000000000..216d25312f56abe40681a2935ffe50b622aaae0f GIT binary patch literal 1547 zcmeAS@N?(olHy`uVBq!ia0y~yU=UznU^u|R1`;{@*pGpMfhFD1*O7r?V?XzwL{o+UC{LA zk@F?rIr)!-8e0DRc)p(dNJM$|%maT8%iH%er7_%yKI`eUK{!lK<={@&#wMW+4nD`e zX+GvI@a2@AHTjG1rRme|s5QM4pV;tT=fESDZ3`I0HwrJ`OcGZe=hZIg)Su(1$LP_~@8)qVDnVU%MrGr#?cK(jicH(uJq`9d zy%tMTKapGZJ+`=8%=&wQ@J42Z$sd1O?Ngro{EnK;ts~oR%rDrsUsvpbQW?_>+4e`% zyT8fGU;8%i{fjj}#I7*EedoB{O8CHvbBqVxF*_TpI3C*_eR_S!$$o~bi+8dbH2(Y~ zc|K{QmdEU^pUgNWwVXY8w&6|M&R(B+f3wau-cJ!Si$A_CL(i|igF!cI@)Y~$k`1;l z0SzT@SPZONYUO{HeEw-CbUpaq$Jn`yc?Uf|1gy@z)5KxXyy4p2D9)D)7sl3{(0}vp z&nMj-?ut8mjSGai^^C&LN7P@ev4{*1)!&{NR4&eN_si04Weh1B{Vf@PmZrT`oV;td zuG{AOE(*~qn)Tf2c=vAE)h)~c6U;srO|Vc?icb{V zDa&a4HCC-`yJq*?-t8?ROwaVsAAKf!#A%zyB>TsEI)xG@vWlr5uyDTded6-@k0(z1 z{kLPC!gf1{OYb)1G47E(R>K!A%g6cR-37gSQ&J|CeUD>$b}b{;gP%8a<0jLZxTNyg zUKyc1&r<$A6)?Uit}$hY@!d1gxn2ybx_T|EUhVdIm1n(V=Zqh7%#Sd=HO%HV^ou*x zR_6LkGF_)(`YGuXA3dIm+D@IYd2d{u3q$g~V{iFbOUhpeF4(nAw&Km+-M&t{Zig^& z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