summaryrefslogtreecommitdiff
path: root/extranodes/lox.lua
blob: 3aaadee85f6644779141a2895a30fe938123a52b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
-- An small arsenal of tools to battle the lava craters


local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end

local freezing_rules = {
	["default:water_source"] = "default:ice",
	["default:water_flowing"] = "default:snowblock",
	["default:river_water_source"] = "default:ice",
	["default:river_water_flowing"] = "default:snowblock",
	["default:lava_source"] = "default:obsidian",
	["default:lava_flowing"] = "default:stone",
	["fire:basic_flame"] = "air",
	["default:dirt"] = "default:dirt_with_snow",
	["ethereal:fiery_dirt"] = "default:dirt_with_snow",
	["ethereal:mushroom_dirt"] = "default:dirt_with_snow",
}

local function freeze(user, pos, radius)

	-- if the function is used by a node: user is a string
	-- if it's called by an item, user is a PlayerRef
	
	if type(user) == 'string' then
		if minetest.is_protected(pos, user) then
			minetest.record_protection_violation(pos, user)
			return
		end
	else
		if minetest.is_protected(pos, user:get_player_name()) then
			minetest.record_protection_violation(pos, user:get_player_name())
			return
		end
	end
	
	local loc = {}
	local wrk = false
	-- R = 2,  d = 3
	-- R = 10, d = 5
	local depth = math.floor(0.25*radius+2.5)
	
	for y = 0,depth,1 do
		for x = -radius,radius,1 do
			for z = -radius,radius,1 do
				loc = {x = pos.x - x, y = pos.y - y, z = pos.z - z}
				if freezing_rules[minetest.get_node(loc).name] then
					wrk = true
					minetest.swap_node(loc, {name = freezing_rules[minetest.get_node(loc).name]})
				end
				if math.random(1,5) == 5 then
					if minetest.get_node({x = loc.x, y = loc.y+1, z = loc.z}).name == "air" 
						and minetest.get_node(loc).name ~= "air" 
						and minetest.get_node(loc).name ~= "stairs:slab_snowblock" then
						minetest.set_node({x = loc.x, y = loc.y+1, z = loc.z}, {name = "stairs:slab_snowblock"})
					end
				end
			end
		end
	end
	
	if wrk then
		minetest.sound_play("default_cool_lava", {gain = 1, pos = pos})
	end

	return true

end
		
minetest.register_craftitem(":technic:lox", {
	description = S("Liquid Oxygen"),
	tiles = {"technic_lox.png"},
	inventory_image = "technic_lox.png",
	wield_image = "technic_lox.png",
	paramtype = "light",
	is_ground_content = false,
	walkable = false,
	liquids_pointable = true,
	selection_box = {
		type = "fixed",
		fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
	},
	groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
	sounds = default.node_sound_defaults(),
	on_use = function(itemstack, user, pointed_thing)
		if pointed_thing.type ~= "node" then
			return itemstack
		end
                                            
		itemstack:take_item()
                                            
		freeze(user, pointed_thing.under, 2)
                                            
		local uinv = user:get_inventory()
		if uinv:room_for_item("main", "vessels:steel_bottle 1") then
			uinv:add_item("main", "vessels:steel_bottle 1")
		else 
			minetest.item_drop(ItemStack("vessels:steel_bottle 1"), user, user:getpos())
		end
		
		user:set_hp(user:get_hp() - 1)
                                            
		return itemstack
	end
})

minetest.register_node(":technic:fbomb", {
	description = S("F-Bomb"),
	tiles = {"technic_fbomb.png"},
	paramtype = "light",
	is_ground_content = false,
	walkable = false,
	selection_box = {
		type = "fixed",
		fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
	},
	groups = {dig_immediate = 2, falling_node = 1},
	sounds = default.node_sound_defaults(),
	on_punch = function(pos, node, player, pointed_thing)
		minetest.remove_node(pos)
		minetest.place_node(pos, {name="technic:fbombact"})
		local nm =  minetest.get_meta(pos)
		nm:set_string("player", player:get_player_name())
	end
})

minetest.register_node(":technic:fbombact", {
	description = S("F-Bomb Active"),
	tiles = {"technic_fbombact.png"},
	paramtype = "light",
	is_ground_content = false,
	walkable = false,
	light_source = 3,
	selection_box = {
		type = "fixed",
		fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
	},
	groups = {falling_node = 1, cracky = 1, not_in_creative_inventory = 1},
	sounds = default.node_sound_defaults(),
	on_construct = function(pos)
		local nm =  minetest.get_meta(pos)
		local id = minetest.add_particlespawner({
			amount = 30,
			time = 0,
			minpos = pos,
			maxpos = pos,
			minvel = {x=-2, y=0, z=-2},
			maxvel = {x=2, y=0, z=2},
			minacc = {x=0, y=0, z=0},
			maxacc = {x=0.5, y=0, z=0.5},
			minexptime = 1,
			maxexptime = 5,
			minsize = 1,
			maxsize = 4,
			collisiondetection = false,
			vertical = false,
			texture = "technic_snowflake.png",
			glow = 2
		})
		nm:set_int("id", id)
		local tm = minetest.get_node_timer(pos)
		tm:start(5)
	end,
	on_timer = function(pos, elapsed)
		local nm = minetest.get_meta(pos)
		local pn = nm:get_string("player")
		freeze(pn, pos, 10)
		minetest.remove_node(pos)
		return false
	end,
	on_destruct = function(pos)
		local nm =  minetest.get_meta(pos)
		if (nm:get_int("id")) then
			minetest.delete_particlespawner(nm:get_int("id"))
		end
	end,
	drop = "technic:fbomb"

})

minetest.register_craft({
		output = "technic:fbomb 3",
		recipe = {
			{ "technic:lox", "tnt:tnt",     "technic:lox"},
			{ "tnt:tnt",     "technic:lox", "tnt:tnt"},
			{ "technic:lox", "tnt:tnt",     "technic:lox"}
		},
	})

-- since there will be a significant surplus of snow slabs, a recipe for recycling is in order
minetest.register_craft({
		output = "default:snowblock",
		type = "shapeless",
		recipe = { "stairs:slab_snowblock", "stairs:slab_snowblock" },
	})