-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
101 lines (96 loc) · 2.93 KB
/
init.lua
File metadata and controls
101 lines (96 loc) · 2.93 KB
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
local update = function(obj)
core.chat_send_all("Updating wind turbine...")
local wind = {
velocity = 1,
direction = 45
}
local wind_vel = wind.velocity
local wind_dir = wind.direction
if wind_vel > 0 then
local arm = obj:get_bone_override('fan')
if not arm then
return
end
core.chat_send_all("Current arm bone override: " .. dump(arm))
local yawRad = arm.rotation and arm.rotation.vec.y or 0
local yawDeg = math.deg(yawRad)
yawDeg = ((yawDeg + wind_dir) / 2) % 360
local rot_arm = {
x = 0,
y = math.rad(yawDeg),
z = 0
}
local speed = math.min(200, 100 * (wind_vel * 1))
local rotor = obj:get_bone_override('rotor')
if not rotor then
return
end
core.chat_send_all("Current rotor bone override: " .. dump(rotor))
local rollRad = rotor.rotation and rotor.rotation.vec.z or 0
local rollDeg = math.deg(rollRad)
rollDeg = (rollDeg + speed) % 360
local rot_rotor = {
x = 0,
y = 0,
z = math.rad(rollDeg)
}
obj:set_bone_override("fan", {
rotation = {
vec = rot_arm,
absolute = true,
interpolation = 1.0
}
})
obj:set_bone_override("rotor", {
rotation = {
vec = rot_rotor,
absolute = true,
interpolation = 1.05
}
})
end
end
local entity_def = {
initial_properties = {
physical = true,
collide_with_objects = true,
collisionbox = { -0.75, -0.5, -0.75, 0.75, 1.45, 0.75 },
selectionbox = { -0.75, -0.5, -0.75, 0.75, 1.45, 0.75 },
hp = 10,
hp_max = 10,
visual = "mesh",
mesh = "minimal_example_wind_turbine.gltf",
static_save = true,
textures = { "minimal_example_wind_turbine.png" },
use_texture_alpha = true,
visual_size = {
x = 0.667,
y = 0.667
},
glow = 2,
},
on_step = function(self, dtime, moveresult)
self.timer = (self.timer or 0) + dtime
if self.timer >= 1 then
self.timer = 0
update(self.object)
end
end,
}
local item_def = {
description = "Wind Turbine",
inventory_image = "minimal_example_structure.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return itemstack
end
local pos = pointed_thing.above
local obj = core.add_entity(pos, "minimal_example:wind_turbine")
if obj and placer then
obj:set_yaw(placer:get_look_horizontal())
end
return itemstack
end
}
core.register_entity("minimal_example:wind_turbine", entity_def)
core.register_craftitem("minimal_example:wind_turbine", item_def)