aboutsummaryrefslogtreecommitdiff
path: root/games/minimal/mods/legacy/init.lua
blob: 98ad69be0fca3096860b56701ddf86e7bdb3ac41 (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
-- legacy (Minetest 0.4 mod)
-- Provides as much backwards-compatibility as feasible

--
-- Aliases to support loading 0.3 and old 0.4 worlds and inventories
--

minetest.register_alias("stone", "default:stone")
minetest.register_alias("stone_with_coal", "default:stone_with_coal")
minetest.register_alias("stone_with_iron", "default:stone_with_iron")
minetest.register_alias("dirt_with_grass", "default:dirt_with_grass")
minetest.register_alias("dirt_with_grass_footsteps", "default:dirt_with_grass_footsteps")
minetest.register_alias("dirt", "default:dirt")
minetest.register_alias("sand", "default:sand")
minetest.register_alias("gravel", "default:gravel")
minetest.register_alias("sandstone", "default:sandstone")
minetest.register_alias("clay", "default:clay")
minetest.register_alias("brick", "default:brick")
minetest.register_alias("tree", "default:tree")
minetest.register_alias("jungletree", "default:jungletree")
minetest.register_alias("junglegrass", "default:junglegrass")
minetest.register_alias("leaves", "default:leaves")
minetest.register_alias("cactus", "default:cactus")
minetest.register_alias("papyrus", "default:papyrus")
minetest.register_alias("bookshelf", "default:bookshelf")
minetest.register_alias("glass", "default:glass")
minetest.register_alias("wooden_fence", "default:fence_wood")
minetest.register_alias("rail", "default:rail")
minetest.register_alias("ladder", "default:ladder")
minetest.register_alias("wood", "default:wood")
minetest.register_alias("mese", "default:mese")
minetest.register_alias("cloud", "default:cloud")
minetest.register_alias("water_flowing", "default:water_flowing")
minetest.register_alias("water_source", "default:water_source")
minetest.register_alias("lava_flowing", "default:lava_flowing")
minetest.register_alias("lava_source", "default:lava_source")
minetest.register_alias("torch", "default:torch")
minetest.register_alias("sign_wall", "default:sign_wall")
minetest.register_alias("furnace", "default:furnace")
minetest.register_alias("chest", "default:chest")
minetest.register_alias("locked_chest", "default:chest_locked")
minetest.register_alias("cobble", "default:cobble")
minetest.register_alias("mossycobble", "default:mossycobble")
minetest.register_alias("steelblock", "default:steelblock")
minetest.register_alias("nyancat", "default:nyancat")
minetest.register_alias("nyancat_rainbow", "default:nyancat_rainbow")
minetest.register_alias("sapling", "default:sapling")
minetest.register_alias("apple", "default:apple")

minetest.register_alias("WPick", "default:pick_wood")
minetest.register_alias("STPick", "default:pick_stone")
minetest.register_alias("SteelPick", "default:pick_steel")
minetest.register_alias("MesePick", "default:pick_mese")
minetest.register_alias("WShovel", "default:shovel_wood")
minetest.register_alias("STShovel", "default:shovel_stone")
minetest.register_alias("SteelShovel", "default:shovel_steel")
minetest.register_alias("WAxe", "default:axe_wood")
minetest.register_alias("STAxe", "default:axe_stone")
minetest.register_alias("SteelAxe", "default:axe_steel")
minetest.register_alias("WSword", "default:sword_wood")
minetest.register_alias("STSword", "default:sword_stone")
minetest.register_alias("SteelSword", "default:sword_steel")

minetest.register_alias("Stick", "default:stick")
minetest.register_alias("paper", "default:paper")
minetest.register_alias("book", "default:book")
minetest.register_alias("lump_of_coal", "default:coal_lump")
minetest.register_alias("lump_of_iron", "default:iron_lump")
minetest.register_alias("lump_of_clay", "default:clay_lump")
minetest.register_alias("steel_ingot", "default:steel_ingot")
minetest.register_alias("clay_brick", "default:clay_brick")
minetest.register_alias("scorched_stuff", "default:scorched_stuff")

--
-- Old items
--

minetest.register_craftitem(":rat", {
	description = "Rat",
	inventory_image = "rat.png",
	on_drop = function(item, dropper, pos)
		item:take_item()
		return item
	end,
	on_place = function(item, dropped, pointed)
		pos = minetest.get_pointed_thing_position(pointed, true)
		if pos ~= nil then
			item:take_item()
			return item
		end
	end
})

minetest.register_craftitem(":cooked_rat", {
	description = "Cooked rat",
	inventory_image = "cooked_rat.png",
	on_use = minetest.item_eat(6),
})

minetest.register_craftitem(":firefly", {
	description = "Firefly",
	inventory_image = "firefly.png",
	on_drop = function(item, dropper, pos)
		item:take_item()
		return item
	end,
	on_place = function(item, dropped, pointed)
		pos = minetest.get_pointed_thing_position(pointed, true)
		if pos ~= nil then
			item:take_item()
			return item
		end
	end
})

minetest.register_craft({
	type = "cooking",
	output = "cooked_rat",
	recipe = "rat",
})

minetest.register_craft({
	type = "cooking",
	output = "scorched_stuff",
	recipe = "cooked_rat",
})

-- END
wraps degrees to the range of -360...360 NOTE: Wrapping to 0...360 is not used because pitch needs negative values. */ inline float wrapDegrees(float f) { // Take examples of f=10, f=720.5, f=-0.5, f=-360.5 // This results in // 10, 720, -1, -361 int i = floor(f); // 0, 2, 0, -1 int l = i / 360; // NOTE: This would be used for wrapping to 0...360 // 0, 2, -1, -2 /*if(i < 0) l -= 1;*/ // 0, 720, 0, -360 int k = l * 360; // 10, 0.5, -0.5, -0.5 f -= float(k); return f; } /* Wrap to 0...360 */ inline float wrapDegrees_0_360(float f) { // Take examples of f=10, f=720.5, f=-0.5, f=-360.5 // This results in // 10, 720, -1, -361 int i = floor(f); // 0, 2, 0, -1 int l = i / 360; // Wrap to 0...360 // 0, 2, -1, -2 if(i < 0) l -= 1; // 0, 720, 0, -360 int k = l * 360; // 10, 0.5, -0.5, -0.5 f -= float(k); return f; } /* Wrap to -180...180 */ inline float wrapDegrees_180(float f) { f += 180; f = wrapDegrees_0_360(f); f -= 180; return f; } /* Pseudo-random (VC++ rand() sucks) */ int myrand(void); void mysrand(unsigned seed); #define MYRAND_MAX 32767 int myrand_range(int min, int max); /* Miscellaneous functions */ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed); bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, f32 camera_fov, f32 range, f32 *distance_ptr=NULL); /* Some helper stuff */ #define MYMIN(a,b) ((a)<(b)?(a):(b)) #define MYMAX(a,b) ((a)>(b)?(a):(b)) /* Returns nearest 32-bit integer for given floating point number. <cmath> and <math.h> in VC++ don't provide round(). */ inline s32 myround(f32 f) { return floor(f + 0.5); } /* Returns integer position of node in given floating point position */ inline v3s16 floatToInt(v3f p, f32 d) { v3s16 p2( (p.X + (p.X>0 ? d/2 : -d/2))/d, (p.Y + (p.Y>0 ? d/2 : -d/2))/d, (p.Z + (p.Z>0 ? d/2 : -d/2))/d); return p2; } /* Returns floating point position of node in given integer position */ inline v3f intToFloat(v3s16 p, f32 d) { v3f p2( (f32)p.X * d, (f32)p.Y * d, (f32)p.Z * d ); return p2; } // Random helper. Usually d=BS inline core::aabbox3d<f32> getNodeBox(v3s16 p, float d) { return core::aabbox3d<f32>( (float)p.X * d - 0.5*d, (float)p.Y * d - 0.5*d, (float)p.Z * d - 0.5*d, (float)p.X * d + 0.5*d, (float)p.Y * d + 0.5*d, (float)p.Z * d + 0.5*d ); } class IntervalLimiter { public: IntervalLimiter(): m_accumulator(0) { } /* dtime: time from last call to this method wanted_interval: interval wanted return value: true: action should be skipped false: action should be done */ bool step(float dtime, float wanted_interval) { m_accumulator += dtime; if(m_accumulator < wanted_interval) return false; m_accumulator -= wanted_interval; return true; } protected: float m_accumulator; }; /* Splits a list into "pages". For example, the list [1,2,3,4,5] split into two pages would be [1,2,3],[4,5]. This function computes the minimum and maximum indices of a single page. length: Length of the list that should be split page: Page number, 1 <= page <= pagecount pagecount: The number of pages, >= 1 minindex: Receives the minimum index (inclusive). maxindex: Receives the maximum index (exclusive). Ensures 0 <= minindex <= maxindex <= length. */ inline void paging(u32 length, u32 page, u32 pagecount, u32 &minindex, u32 &maxindex) { if(length < 1 || pagecount < 1 || page < 1 || page > pagecount) { // Special cases or invalid parameters minindex = maxindex = 0; } else if(pagecount <= length) { // Less pages than entries in the list: // Each page contains at least one entry minindex = (length * (page-1) + (pagecount-1)) / pagecount; maxindex = (length * page + (pagecount-1)) / pagecount; } else { // More pages than entries in the list: // Make sure the empty pages are at the end if(page < length) { minindex = page-1; maxindex = page; } else { minindex = 0; maxindex = 0; } } } inline float cycle_shift(float value, float by = 0, float max = 1) { if (value + by < 0) return max + by + value; if (value + by > max) return value + by - max; return value + by; } #endif