]> git.lizzy.rs Git - Crafter.git/blob - mods/minecart/init.lua
Add in extremely basic prototype for minecarts
[Crafter.git] / mods / minecart / init.lua
1 local pool = {}
2
3 local dirs = {
4         {x= 1,y= 0,z= 0},
5         {x=-1,y= 0,z= 0},
6
7         {x= 1,y= 1,z= 0}, 
8         {x=-1,y= 1,z= 0},
9
10         {x= 1,y=-1,z= 0},
11         {x=-1,y=-1,z= 0},
12
13         {x= 0,y= 0,z= 1},
14         {x= 0,y= 0,z=-1},
15
16         {x= 0,y= 1,z= 1},
17         {x= 0,y= 1,z=-1},
18
19         {x= 0,y=-1,z= 1},
20         {x= 0,y=-1,z=-1},
21 }
22
23 local axis_order = {
24
25 }
26 local function data_injection(pos,data)
27         if data then
28                 pool[minetest.hash_node_position(pos)] = true
29         else
30                 pool[minetest.hash_node_position(pos)] = nil
31         end
32 end
33
34
35 local function create_axis(pos)
36         local possible_dirs = {}
37         for _,dir in pairs(dirs) do
38                 local pos2 = vector.add(pos,dir)
39                 if pool[minetest.hash_node_position(pos2)] then
40                         table.insert(possible_dirs,dir)
41                 end
42         end
43         print(dump(possible_dirs))
44 end
45
46
47
48 local minecart = {}
49
50
51
52 minecart.on_step = function(self,dtime)
53         local pos = vector.round(self.object:get_pos())
54         create_axis(pos)
55 end
56
57 minecart.on_rightclick = function(self,clicker)
58 end
59
60 --get old data
61 minecart.on_activate = function(self,staticdata, dtime_s)
62         self.object:set_armor_groups({immortal=1})
63         if string.sub(staticdata, 1, string.len("return")) ~= "return" then
64                 return
65         end
66         local data = minetest.deserialize(staticdata)
67         if type(data) ~= "table" then
68                 return
69         end
70
71 end
72
73 minecart.get_staticdata = function(self)
74         return minetest.serialize({
75         })
76 end
77
78
79
80 minecart.initial_properties = {
81         physical = false, -- otherwise going uphill breaks
82         collisionbox = {-0.4, -0.5, -0.4, 0.4, 0.45, 0.4},--{-0.5, -0.4, -0.5, 0.5, 0.25, 0.5},
83         visual = "mesh",
84         mesh = "minecart.x",
85         visual_size = {x=1, y=1},
86         textures = {"minecart.png"},
87 }
88
89
90 minecart.on_punch = function(self,puncher, time_from_last_punch, tool_capabilities, dir, damage)
91         --local obj = minetest.add_item(self.object:getpos(), "minecart:minecart")
92         --self.object:remove()
93 end
94
95         
96
97 minetest.register_entity("minecart:minecart", minecart)
98
99
100
101
102
103
104
105
106
107
108
109
110 minetest.register_craftitem("minecart:minecart", {
111         description = "Minecart",
112         inventory_image = "minecartitem.png",
113         wield_image = "minecartitem.png",
114         on_place = function(itemstack, placer, pointed_thing)
115                 if not pointed_thing.type == "node" then
116                         return
117                 end
118                 
119                 local sneak = placer:get_player_control().sneak
120                 local noddef = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name]
121                 if not sneak and noddef.on_rightclick then
122                         minetest.item_place(itemstack, placer, pointed_thing)
123                         return
124                 end
125                 
126                 if minetest.get_item_group(minetest.get_node(pointed_thing.under).name, "rail")>0 then
127                         minetest.add_entity(pointed_thing.under, "minecart:minecart")
128                 else
129                         return
130                 end
131
132                 itemstack:take_item()
133
134                 return itemstack
135         end,
136 })
137
138 minetest.register_craft({
139         output = "minecart:minecart",
140         recipe = {
141                 {"main:iron", "", "main:iron"},
142                 {"main:iron", "main:iron", "main:iron"},
143         },
144 })
145
146
147
148
149
150 minetest.register_node("minecart:rail",{
151         description = "Rail",
152         wield_image = "rail.png",
153         tiles = {
154                 "rail.png", "railcurve.png",
155                 "railt.png", "railcross.png"
156         },
157         drawtype = "raillike",
158         paramtype = "light",
159         sunlight_propagates = true,
160         is_ground_content = false,
161         walkable = false,
162         node_placement_prediction = "",
163         selection_box = {
164                 type = "fixed",
165                 fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
166         },
167         sounds = main.stoneSound(),
168         after_place_node = function(pos)
169                 data_injection(pos,true)
170         end,
171         after_destruct = function(pos)
172                 data_injection(pos)
173         end,
174         groups={stone=1,wood=1,rail=1,attached_node=1},
175 })
176
177
178 minetest.register_lbm({
179         name = "minecart:rail",
180         nodenames = {"minecart:rail"},
181         run_at_every_load = true,
182         action = function(pos)
183                 data_injection(pos,true)
184                 print("buildin dat cash")
185         end,
186 })
187
188 minetest.register_craft({
189         output = "minecart:rail 32",
190         recipe = {
191                 {"main:iron","","main:iron"},
192                 {"main:iron","main:stick","main:iron"},
193                 {"main:iron","","main:iron"}
194         }
195 })