]> git.lizzy.rs Git - Crafter.git/commitdiff
Add nether portals
authoroilboi <47129783+oilboi@users.noreply.github.com>
Sat, 18 Apr 2020 19:48:50 +0000 (15:48 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Sat, 18 Apr 2020 19:48:50 +0000 (15:48 -0400)
README.md
mods/fire/init.lua
mods/nether/init.lua

index 746d0ddc00c3c5778bb89d0fe167d414c58dcd66..8b2ecb147df74a82881d75d053a800581c08150a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -84,7 +84,7 @@
 - Added lava
 - Added ithor weather
 - Added nether portal node and fire
-- Added in flint and steel, flint, and gravel
+- Added in flint and steel, flint, and gravel and enabled dirt and gravel spawning
 ---
 
 
index 7e0b2cac4a7d6bfc945ba29bcf36d06b1f9cea5b..05f9c87ea7917e5a96d28ea6f8121f856d6f6216 100644 (file)
@@ -20,8 +20,15 @@ minetest.register_node("fire:fire", {
     is_ground_content = false,
     light_source = 11, --debugging
     on_construct = function(pos)
+               
                local timer = minetest.get_node_timer(pos)
                timer:start(math.random(5,10))
+               
+               
+               if minetest.get_node(vector.new(pos.x,pos.y-1,pos.z)).name == "nether:obsidian" then
+                       minetest.remove_node(pos)
+                       create_nether_portal(pos)
+               end
     end,
     on_timer = function(pos, elapsed)
                minetest.remove_node(pos)
@@ -53,6 +60,7 @@ minetest.register_tool("fire:flint_and_steel", {
                        minetest.sound_play("flint_failed", {pos=pointed_thing.above})
                        return
                end
+               
                minetest.add_node(pointed_thing.above,{name="fire:fire"})
                minetest.sound_play("flint_and_steel", {pos=pointed_thing.above})
                itemstack:add_wear(100)
index 395e27b502f5125b560400fe446fd5207ae7d132..f2024f54377ed05a0276a60a3f2d2575262421fa 100644 (file)
@@ -41,9 +41,13 @@ minetest.register_node("nether:netherrack", {
 minetest.register_node("nether:obsidian", {
     description = "Obsidian",
     tiles = {"obsidian.png"},
-    groups = {stone = 5, pathable = 1},
+    --groups = {stone = 5, pathable = 1},
+    groups = {stone = 1, pathable = 1},
     sounds = main.stoneSound(),
     is_ground_content = false,
+    after_destruct = function(pos, oldnode)
+               destroy_nether_portal(pos)
+    end,
     --light_source = 7,
 })
 
@@ -256,3 +260,271 @@ minetest.register_node("nether:portal", {
        --on_destruct = destroy_portal,
 })
 
+--branch out from center
+local n_index = {}
+local portal_failure = false
+local x_failed = false
+
+--this can be used globally to create nether portals from obsidian
+function create_nether_portal(pos,origin,axis)
+       --create the origin node for stored memory
+       if not origin then
+               origin = pos
+               portal_failure = false
+       end
+       if not axis then
+               axis = "x"
+       end
+               
+       --2d virtual memory map creation (x axis)
+       if axis == "x" then
+               for x = -1,1 do
+               for y = -1,1 do
+                       --index only direct neighbors
+                       if x_failed == false and (math.abs(x)+math.abs(y) == 1) then
+                               local i = vector.add(pos,vector.new(x,y,0))
+                               
+                               local execute_collection = true
+                               
+                               if n_index[i.x] and n_index[i.x][i.y] then
+                                       if n_index[i.x][i.y][i.z] then
+                                               execute_collection = false
+                                       end
+                               end     
+                               
+                               if execute_collection == true then
+                                       --print(minetest.get_node(i).name)
+                                       --index air
+                                       if minetest.get_node(i).name == "air" then
+                                               
+                                               if vector.distance(i,origin) < 50 then
+                                                       --add data to both maps
+                                                       if not n_index[i.x] then n_index[i.x] = {} end
+                                                       if not n_index[i.x][i.y] then n_index[i.x][i.y] = {} end
+                                                       n_index[i.x][i.y][i.z] = {nether_portal=1} --get_group(i,"redstone_power")}                             
+                                                       --the data to the 3d array must be written to memory before this is executed
+                                                       --or a stack overflow occurs!!!
+                                                       --pass down info for activators
+                                                       create_nether_portal(i,origin,"x")
+                                               else
+                                                       --print("try z")
+                                                       x_failed = true
+                                                       n_index = {}
+                                                       create_nether_portal(origin,origin,"z")
+                                               end
+                                       elseif minetest.get_node(i).name ~= "nether:obsidian" then
+                                               x_failed = true
+                                               n_index = {}
+                                               create_nether_portal(origin,origin,"z")
+                                       end
+                               end
+                       end
+               end
+               end
+       --2d virtual memory map creation (z axis)
+       elseif axis == "z" then
+               for z = -1,1 do
+               for y = -1,1 do
+                       --index only direct neighbors
+                       if x_failed == true and portal_failure == false and (math.abs(z)+math.abs(y) == 1) then
+                               local i = vector.add(pos,vector.new(0,y,z))
+                               
+                               local execute_collection = true
+                               
+                               if n_index[i.x] and n_index[i.x][i.y] then
+                                       if n_index[i.x][i.y][i.z] then
+                                               execute_collection = false
+                                       end
+                               end     
+                               
+                               if execute_collection == true then
+                                       --print(minetest.get_node(i).name)
+                                       --index air
+                                       if minetest.get_node(i).name == "air" then
+                                               if vector.distance(i,origin) < 50 then
+                                                       --add data to both maps
+                                                       if not n_index[i.x] then n_index[i.x] = {} end
+                                                       if not n_index[i.x][i.y] then n_index[i.x][i.y] = {} end
+                                                       n_index[i.x][i.y][i.z] = {nether_portal=1} --get_group(i,"redstone_power")}                             
+                                                       --the data to the 3d array must be written to memory before this is executed
+                                                       --or a stack overflow occurs!!!
+                                                       --pass down info for activators
+                                                       create_nether_portal(i,origin,"z")
+                                               else
+                                                       --print("portal failed")
+                                                       portal_failure = true
+                                                       n_index = {}
+                                                       --print("try z")
+                                               end
+                                       elseif minetest.get_node(i).name ~= "nether:obsidian" then
+                                               --print("portal failed")
+                                               portal_failure = true
+                                               n_index = {}
+                                       end
+                               end
+                       end
+               end
+               end
+       end
+end
+
+--modify the map with the collected data
+local function portal_modify_map(n_copy)
+       local sorted_table = {}
+       for x,datax in pairs(n_copy) do
+               for y,datay in pairs(datax) do
+                       for z,index in pairs(datay) do
+                               table.insert(sorted_table, vector.new(x,y,z))
+                       end
+               end
+       end
+       minetest.bulk_set_node(sorted_table, {name="nether:portal"})
+end
+
+-------------------------------------------------------------------------------
+
+local destroy_n_index = {}
+local destroy_portal_failure = false
+local destroy_x_failed = false
+
+--this can be used globally to create nether portals from obsidian
+function destroy_nether_portal(pos,origin,axis)
+       --create the origin node for stored memory
+       if not origin then
+               origin = pos
+               destroy_portal_failure = false
+       end
+       if not axis then
+               axis = "x"
+       end
+               
+       --2d virtual memory map creation (x axis)
+       if axis == "x" then
+               for x = -1,1 do
+               for y = -1,1 do
+                       --index only direct neighbors
+                       if destroy_x_failed == false and (math.abs(x)+math.abs(y) == 1) then
+                               local i = vector.add(pos,vector.new(x,y,0))
+                               
+                               local execute_collection = true
+                               
+                               if destroy_n_index[i.x] and destroy_n_index[i.x][i.y] then
+                                       if destroy_n_index[i.x][i.y][i.z] then
+                                               execute_collection = false
+                                       end
+                               end     
+                               
+                               if execute_collection == true then
+                                       --print(minetest.get_node(i).name)
+                                       --index air
+                                       if minetest.get_node(i).name == "nether:portal" then
+                                               if vector.distance(i,origin) < 50 then
+                                                       --add data to both maps
+                                                       if not destroy_n_index[i.x] then destroy_n_index[i.x] = {} end
+                                                       if not destroy_n_index[i.x][i.y] then destroy_n_index[i.x][i.y] = {} end
+                                                       destroy_n_index[i.x][i.y][i.z] = {nether_portal=1} --get_group(i,"redstone_power")}                             
+                                                       --the data to the 3d array must be written to memory before this is executed
+                                                       --or a stack overflow occurs!!!
+                                                       --pass down info for activators
+                                                       destroy_nether_portal(i,origin,"x")
+                                               else
+                                                       print("try z")
+                                                       destroy_x_failed = true
+                                                       destroy_n_index = {}
+                                                       destroy_nether_portal(origin,origin,"z")
+                                               end
+                                       end
+                               end
+                       end
+               end
+               end
+       --2d virtual memory map creation (z axis)
+       elseif axis == "z" then
+               for z = -1,1 do
+               for y = -1,1 do
+                       --index only direct neighbors
+                       if destroy_x_failed == true and destroy_portal_failure == false and (math.abs(z)+math.abs(y) == 1) then
+                               local i = vector.add(pos,vector.new(0,y,z))
+                               
+                               local execute_collection = true
+                               
+                               if destroy_n_index[i.x] and destroy_n_index[i.x][i.y] then
+                                       if destroy_n_index[i.x][i.y][i.z] then
+                                               execute_collection = false
+                                       end
+                               end     
+                               
+                               if execute_collection == true then
+                                       --print(minetest.get_node(i).name)
+                                       --index air
+                                       if minetest.get_node(i).name == "nether:portal" then
+                                               if vector.distance(i,origin) < 50 then
+                                                       --add data to both maps
+                                                       if not destroy_n_index[i.x] then destroy_n_index[i.x] = {} end
+                                                       if not destroy_n_index[i.x][i.y] then destroy_n_index[i.x][i.y] = {} end
+                                                       destroy_n_index[i.x][i.y][i.z] = {nether_portal=1} --get_group(i,"redstone_power")}                             
+                                                       --the data to the 3d array must be written to memory before this is executed
+                                                       --or a stack overflow occurs!!!
+                                                       --pass down info for activators
+                                                       destroy_nether_portal(i,origin,"z")
+                                               else
+                                                       --print("portal failed")
+                                                       destroy_portal_failure = true
+                                                       destroy_n_index = {}
+                                                       --print("try z")
+                                               end
+                                       end
+                               end
+                       end
+               end
+               end
+       end
+end
+
+--modify the map with the collected data
+local function destroy_portal_modify_map(destroy_n_copy)
+       local destroy_sorted_table = {}
+       for x,datax in pairs(destroy_n_copy) do
+               for y,datay in pairs(datax) do
+                       for z,index in pairs(datay) do
+                               table.insert(destroy_sorted_table, vector.new(x,y,z))
+                       end
+               end
+       end
+       minetest.bulk_set_node(destroy_sorted_table, {name="air"})
+end
+
+minetest.register_globalstep(function(dtime)
+       --if indexes exist then calculate redstone
+       if n_index and next(n_index) and portal_failure == false then
+               --create the old version to help with deactivation calculation
+               local n_copy = table.copy(n_index)
+               portal_modify_map(n_copy)
+               portal_failure = false
+       end
+       if x_failed == true then
+               x_failed = false
+       end
+       if portal_failure == true then
+               portal_failure = false
+       end
+       --clear the index to avoid cpu looping wasting processing power
+       n_index = {}
+       
+       
+       --if indexes exist then calculate redstone
+       if destroy_n_index and next(destroy_n_index) and destroy_portal_failure == false then
+               --create the old version to help with deactivation calculation
+               local destroy_n_copy = table.copy(destroy_n_index)
+               destroy_portal_modify_map(destroy_n_copy)
+               destroy_portal_failure = false
+       end
+       if destroy_x_failed == true then
+               destroy_x_failed = false
+       end
+       if destroy_portal_failure == true then
+               destroy_portal_failure = false
+       end
+       --clear the index to avoid cpu looping wasting processing power
+       destroy_n_index = {}
+end)