Use fuel to power ufos; add ufo charging device (ufo_furnace)

master
Zeg9 2013-04-02 19:04:05 +02:00
parent fe1a55caf3
commit 9a6156dfbc
18 changed files with 224 additions and 31 deletions

105
ufos/furnace.lua Normal file
View File

@ -0,0 +1,105 @@
ufos.fuel = "default:obsidian_shard"
ufos.fuel_time = 10
ufos.furnace_inactive_formspec =
"size[8,5.5]"..
"list[current_name;fuel;3.5,0;1,1;]"..
"list[current_player;main;0,1.5;8,4;]"..
"label[4.5,0;Fuel needed: "..ufos.fuel.."]"..
"label[0,1;Press run (E) inside your UFO.]"..
"label[4,1;You need to park it next to this.]"
minetest.register_node("ufos:furnace", {
description = "UFO charging device",
tiles = {"ufos_furnace_top.png", "ufos_furnace_bottom.png", "ufos_furnace_side.png",
"ufos_furnace_side.png", "ufos_furnace_side.png", "ufos_furnace_front.png"},
paramtype2 = "facedir",
groups = {cracky=2},
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", ufos.furnace_inactive_formspec)
meta:set_string("infotext", "UFO charging device")
local inv = meta:get_inventory()
inv:set_size("fuel", 1)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("fuel") then
return false
end
return true
end,
})
minetest.register_node("ufos:furnace_active", {
description = "UFO charging device",
tiles = {"ufos_furnace_top.png", "ufos_furnace_bottom.png", "ufos_furnace_side.png",
"ufos_furnace_side.png", "ufos_furnace_side.png", "ufos_furnace_front_active.png"},
paramtype2 = "facedir",
light_source = 8,
drop = "ufos:furnace",
groups = {cracky=2, not_in_creative_inventory=1},
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", ufos.furnace_inactive_formspec)
meta:set_string("infotext", "UFO charging device")
local inv = meta:get_inventory()
inv:set_size("fuel", 1)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("fuel") then
return false
end
return true
end,
})
function hacky_swap_node(pos,name)
local node = minetest.env:get_node(pos)
local meta = minetest.env:get_meta(pos)
local meta0 = meta:to_table()
if node.name == name then
return
end
node.name = name
local meta0 = meta:to_table()
minetest.env:set_node(pos,node)
meta = minetest.env:get_meta(pos)
meta:from_table(meta0)
end
minetest.register_abm({
nodenames = {"ufos:furnace","ufos:furnace_active"},
interval = .25,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack("fuel",1)
if stack:get_name() == ufos.fuel then
inv:remove_item("fuel",ItemStack(ufos.fuel))
meta:set_int("charge",meta:get_int("charge")+1)
meta:set_string("formspec", ufos.furnace_inactive_formspec
.. "label[0,0;Charge: "..meta:get_int("charge"))
end
end,
})
minetest.register_craft( {
output = 'ufos:furnace',
recipe = {
{ "default:steel_ingot", "default:obsidian", "default:steel_ingot"},
{ "default:obsidian", "default:furnace", "default:obsidian"},
{ "default:steel_ingot", "default:obsidian", "default:steel_ingot"},
},
})

View File

@ -1,18 +1,67 @@
local UFO_SPEED = 10
ufos = {}
local UFO_SPEED = 1
local UFO_TURN_SPEED = 2
local UFO_MAX_SPEED = 10
local UFO_FUEL_USE = .01
local ufo = {
ufos.fuel_from_wear = function(wear)
local fuel
if wear == 0 then
fuel = 0
else
fuel = (65535-(wear-1))*100/65535
end
return fuel
end
ufos.wear_from_fuel = function(fuel)
local wear = (100-(fuel))*65535/100+1
if wear > 65535 then wear = 0 end
return wear
end
ufos.get_fuel = function(self)
--return self.object:get_hp()
return self.fuel
end
ufos.set_fuel = function(self,fuel,object)
--[[if not object then object = self.object end
object:set_hp(fuel)]]
self.fuel = fuel
end
ufos.ufo_to_item = function(self)
local wear = ufos.wear_from_fuel(ufos.get_fuel(self))
return {name="ufos:ufo",wear=wear}
end
ufos.ufo_from_item = function(itemstack,placer,pointed_thing)
-- restore the fuel inside the item
local wear = itemstack:get_wear()
ufos.set_fuel(ufos.ufo,ufos.fuel_from_wear(wear))
-- add the entity
e = minetest.env:add_entity(pointed_thing.above, "ufos:ufo")
-- remove the item
itemstack:take_item()
end
ufos.ufo = {
physical = true,
collisionbox = {-1.5,-.5,-1.5, 1.5,2,1.5},
visual = "mesh",
mesh = "ufo.x",
textures = {"ufo.png"},
textures = {"ufo_0.png"},
driver = nil,
v = 0
v = 0,
fuel = 0,
fueli = 0
}
function ufo:on_rightclick (clicker)
function ufos.ufo:on_rightclick (clicker)
if not clicker or not clicker:is_player() then
return
end
@ -25,65 +74,102 @@ function ufo:on_rightclick (clicker)
end
end
function ufo:on_activate (staticdata, dtime_s)
function ufos.ufo:on_activate (staticdata, dtime_s)
self.object:set_armor_groups({immortal=1})
end
function ufo:on_punch (puncher, time_from_last_punch, tool_capabilities, direction)
function ufos.ufo:on_punch (puncher, time_from_last_punch, tool_capabilities, direction)
self.object:remove()
if puncher and puncher:is_player() then
puncher:get_inventory():add_item("main", "ufos:ufo")
-- wear: save the fuel inside the itemstack
puncher:get_inventory():add_item("main", ufos.ufo_to_item(self))
end
end
function ufo:on_step (dtime)
function ufos.ufo:on_step (dtime)
local fuel = ufos.get_fuel(self)
if self.driver then
local ctrl = self.driver:get_player_control()
local vel = self.object:getvelocity()
local acc = self.object:getacceleration()
if ctrl.up then
acc.x = math.cos(self.object:getyaw()+math.pi/2)*UFO_SPEED
acc.z = math.sin(self.object:getyaw()+math.pi/2)*UFO_SPEED
if fuel == nil then fuel = 0 end
if fuel > 0 and ctrl.up then
vel.x = vel.x + math.cos(self.object:getyaw()+math.pi/2)*UFO_SPEED
vel.z = vel.z + math.sin(self.object:getyaw()+math.pi/2)*UFO_SPEED
fuel = fuel - UFO_FUEL_USE
else
acc.x = -vel.x/5
acc.z = -vel.z/5
vel.x = vel.x*.99
vel.z = vel.z*.99
end
if ctrl.down then
acc.x = -vel.x
acc.z = -vel.z
vel.x = vel.x*.9
vel.z = vel.z*.9
end
if ctrl.jump then
vel.y = UFO_SPEED
elseif ctrl.sneak then
vel.y = -UFO_SPEED
if fuel > 0 and ctrl.jump then
vel.y = vel.y+UFO_SPEED
fuel = fuel - UFO_FUEL_USE
elseif fuel > 0 and ctrl.sneak then
vel.y = vel.y-UFO_SPEED
fuel = fuel - UFO_FUEL_USE
else
acc.y = -vel.y/2
vel.y = vel.y*.9
end
if vel.x > UFO_MAX_SPEED then vel.x = UFO_MAX_SPEED end
if vel.x < -UFO_MAX_SPEED then vel.x = -UFO_MAX_SPEED end
if vel.y > UFO_MAX_SPEED then vel.y = UFO_MAX_SPEED end
if vel.y < -UFO_MAX_SPEED then vel.y = -UFO_MAX_SPEED end
if vel.z > UFO_MAX_SPEED then vel.z = UFO_MAX_SPEED end
if vel.z < -UFO_MAX_SPEED then vel.z = -UFO_MAX_SPEED end
self.object:setvelocity(vel)
self.object:setacceleration(acc)
if ctrl.left then
self.object:setyaw(self.object:getyaw()+math.pi/120*UFO_TURN_SPEED)
end
if ctrl.right then
self.object:setyaw(self.object:getyaw()-math.pi/120*UFO_TURN_SPEED)
end
if ctrl.aux1 then
local pos = self.object:getpos()
local t = {{x=2,z=0},{x=-2,z=0},{x=0,z=2},{x=0,z=-2}}
for _, i in ipairs(t) do
pos.x = pos.x + i.x; pos.z = pos.z + i.z;
if minetest.env:get_node(pos).name == "ufos:furnace" then
meta = minetest.env:get_meta(pos)
if fuel < 100 and meta:get_int("charge") > 0 then
fuel = fuel + 1
meta:set_int("charge",meta:get_int("charge")-1)
meta:set_string("formspec", ufos.furnace_inactive_formspec
.. "label[0,0;Charge: "..meta:get_int("charge"))
end
end
pos.x = pos.x - i.x; pos.z = pos.z - i.z;
end
end
end
if fuel < 0 then fuel = 0 end
if fuel > 100 then fuel = 100 end
if self.fueli ~= math.floor(fuel*8/100) then
self.fueli = math.floor(fuel*8/100)
print(self.fueli)
self.textures = {"ufo_"..self.fueli..".png"}
self.object:set_properties(self)
end
ufos.set_fuel(self,fuel)
end
minetest.register_entity("ufos:ufo", ufo)
minetest.register_entity("ufos:ufo", ufos.ufo)
minetest.register_craftitem("ufos:ufo", {
minetest.register_tool("ufos:ufo", {
description = "ufo",
inventory_image = "ufo_inventory.png",
wield_image = "ufo_inventory.png",
inventory_image = "ufos_inventory.png",
wield_image = "ufos_inventory.png",
tool_capabilities = {load=0,max_drop_level=0, groupcaps={fleshy={times={}, uses=100, maxlevel=0}}},
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return
end
minetest.env:add_entity(pointed_thing.above, "ufos:ufo")
itemstack:take_item()
ufos.ufo_from_item(itemstack,placer,pointed_thing)
return itemstack
end,
})
@ -92,8 +178,10 @@ minetest.register_craft( {
output = 'ufos:ufo',
recipe = {
{ "", "default:glass", ""},
{ "default:mese_crystal_fragment", "default:stone", "default:mese_crystal_fragment"},
{ "default:steel_ingot", "default:mese_crystal", "default:steel_ingot"},
{ "default:mese_crystal_fragment", "", "default:mese_crystal_fragment"},
{ "default:steelblock", "default:mese", "default:steelblock"},
},
})
dofile(minetest.get_modpath("ufos").."/furnace.lua")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
ufos/models/ufo_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
ufos/models/ufo_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
ufos/models/ufo_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
ufos/models/ufo_3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
ufos/models/ufo_4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
ufos/models/ufo_5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
ufos/models/ufo_6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
ufos/models/ufo_7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
ufos/models/ufo_8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB