improved fuel management. Now it can use biofuel mod from Lokrates

master
Alexsandro Percy 2021-03-27 08:54:43 -03:00
parent 8cfe7cbc0e
commit b7880950b7
2 changed files with 34 additions and 15 deletions

View File

@ -1,6 +1,8 @@
--
-- fuel
--
helicopter.fuel = {['biofuel:biofuel'] = 1,['biofuel:bottle_fuel'] = 1,['biofuel:phial_fuel'] = 0.25, ['biofuel:fuel_can'] = 10}
minetest.register_entity('helicopter:pointer',{
initial_properties = {
physical = false,
@ -24,20 +26,34 @@ end,
})
function load_fuel(self, player_name)
if self.energy < 9.5 then
local player = minetest.get_player_by_name(player_name)
local inv = player:get_inventory()
local inventory_fuel = "biofuel:biofuel"
function helicopter.contains(table, val)
for k,v in pairs(table) do
if k == val then
return v
end
end
return false
end
if inv:contains_item("main", inventory_fuel) then
local stack = ItemStack(inventory_fuel .. " 1")
function helicopter.loadFuel(self, player_name)
local player = minetest.get_player_by_name(player_name)
local inv = player:get_inventory()
local itmstck=player:get_wielded_item()
local item_name = ""
if itmstck then item_name = itmstck:get_name() end
local stack = nil
local fuel = trike.contains(helicopter.fuel, item_name)
if fuel then
stack = ItemStack(item_name .. " 1")
if self.energy < 10 then
local taken = inv:remove_item("main", stack)
self.energy = self.energy + 1
self.energy = self.energy + fuel
if self.energy > 10 then self.energy = 10 end
local energy_indicator_angle = ((self.energy * 18) - 90) * -1
local energy_indicator_angle = trike.get_gauge_angle(self.energy)
self.pointer:set_attach(self.object,'',{x=0,y=11.26,z=9.37},{x=0,y=0,z=energy_indicator_angle})
--sound and animation
@ -52,9 +68,12 @@ function load_fuel(self, player_name)
-- disable gravity
self.object:set_acceleration(vector.new())
--
end
else
print("Full tank.")
end
return true
end
return false
end

View File

@ -347,9 +347,9 @@ minetest.register_entity("helicopter:heli", {
local item_name = ""
if itmstck then item_name = itmstck:get_name() end
if is_attached == true and touching_ground and item_name == "biofuel:biofuel" then
if is_attached == true and touching_ground then
--refuel
load_fuel(self, self.owner)
helicopter.loadFuel(self, self.owner)
end
if is_attached == false then