2016-10-30 05:59:50 -07:00
|
|
|
--
|
2017-08-09 13:18:37 -07:00
|
|
|
-- Init
|
2016-10-30 05:59:50 -07:00
|
|
|
--
|
|
|
|
|
|
|
|
dofile(minetest.get_modpath("obsidianmese").."/api.lua")
|
|
|
|
dofile(minetest.get_modpath("obsidianmese").."/obsidianmese_chest.lua")
|
|
|
|
|
2016-10-16 03:28:49 -07:00
|
|
|
--
|
2017-08-09 13:18:37 -07:00
|
|
|
-- Tools
|
2016-10-16 03:28:49 -07:00
|
|
|
--
|
|
|
|
|
2017-08-09 13:18:37 -07:00
|
|
|
-- sword - mese
|
2016-10-16 03:28:49 -07:00
|
|
|
minetest.register_tool("obsidianmese:sword", {
|
|
|
|
description = "Obsidian Mese Sword",
|
|
|
|
inventory_image = "obsidianmese_sword.png",
|
|
|
|
tool_capabilities = {
|
|
|
|
full_punch_interval = 0.45,
|
|
|
|
max_drop_level=1,
|
|
|
|
groupcaps={
|
2016-11-21 00:13:17 -08:00
|
|
|
fleshy={times={[1]=2.00, [2]=0.65, [3]=0.25}, uses=400, maxlevel=3},
|
|
|
|
snappy={times={[1]=1.90, [2]=0.70, [3]=0.25}, uses=350, maxlevel=3},
|
|
|
|
choppy={times={[3]=0.65}, uses=300, maxlevel=0}
|
2016-10-16 03:28:49 -07:00
|
|
|
},
|
2016-11-21 00:13:17 -08:00
|
|
|
damage_groups = {fleshy=8},
|
|
|
|
sound = {breaks = "default_tool_breaks"},
|
2016-10-16 03:28:49 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-08-09 13:18:37 -07:00
|
|
|
-- sword - engraved
|
|
|
|
-- check if within physical map limits (-30911 to 30927)
|
|
|
|
local fired_table = {}
|
|
|
|
|
|
|
|
local within_limits = function(pos, radius)
|
|
|
|
|
|
|
|
if (pos.x - radius) > -30913
|
|
|
|
and (pos.x + radius) < 30928
|
|
|
|
and (pos.y - radius) > -30913
|
|
|
|
and (pos.y + radius) < 30928
|
|
|
|
and (pos.z - radius) > -30913
|
|
|
|
and (pos.z + radius) < 30928 then
|
|
|
|
return true -- within limits
|
|
|
|
end
|
|
|
|
|
|
|
|
return false -- beyond limits
|
|
|
|
end
|
|
|
|
|
|
|
|
local sync_table = function(owner)
|
|
|
|
|
|
|
|
if fired_table[owner] ~= nil then
|
|
|
|
|
|
|
|
fired_table[owner] = fired_table[owner] - 1
|
|
|
|
|
|
|
|
-- print(minetest.serialize(fired_table))
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_entity("obsidianmese:sword_bullet", {
|
|
|
|
physical = false,
|
|
|
|
visual = "sprite",
|
|
|
|
visual_size = { x = 1, y = 1 },
|
|
|
|
textures = { "obsidianmese_shard.png" },
|
|
|
|
collisionbox = {0.25, 0.25, 0.25, -0.25, -0.25, -0.25},
|
|
|
|
timer = 0,
|
|
|
|
speed = 8,
|
|
|
|
owner = "",
|
|
|
|
|
|
|
|
on_activate = function(self, staticdata, dtime_s)
|
|
|
|
self.object:set_armor_groups({ immortal = 1 })
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_punch = function (self, puncher, time_from_last_punch, tool_capabilities, dir)
|
|
|
|
|
|
|
|
if time_from_last_punch < 0.5 then return end
|
|
|
|
|
|
|
|
local name = puncher:get_player_name()
|
|
|
|
local pos = self.object:getpos()
|
|
|
|
local v = math.random(1, 8)
|
|
|
|
local velocity = dir
|
|
|
|
|
|
|
|
velocity.x = velocity.x * v
|
|
|
|
velocity.y = velocity.y * v
|
|
|
|
velocity.z = velocity.z * v
|
|
|
|
self.object:setvelocity(velocity)
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_step = function(self, dtime)
|
|
|
|
local pos = self.object:getpos()
|
|
|
|
local node = minetest.get_node_or_nil(pos)
|
|
|
|
|
|
|
|
self.timer = self.timer + 1
|
|
|
|
|
|
|
|
|
|
|
|
if self.timer > 50
|
|
|
|
or not within_limits(pos, 0) then
|
|
|
|
sync_table(self.owner)
|
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- hit node
|
|
|
|
if node
|
|
|
|
and minetest.registered_nodes[node.name]
|
|
|
|
and minetest.registered_nodes[node.name].walkable then
|
|
|
|
sync_table(self.owner)
|
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- hit player or mob
|
|
|
|
for _,player in pairs(minetest.get_objects_inside_radius(pos, 1.0)) do
|
|
|
|
|
|
|
|
if player:is_player() then
|
|
|
|
|
|
|
|
player:punch(self.object, 1.0, {
|
|
|
|
full_punch_interval = 1.0,
|
|
|
|
damage_groups = {fleshy = 8},
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
sync_table(self.owner)
|
|
|
|
self.object:remove()
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local entity = player:get_luaentity()
|
|
|
|
|
|
|
|
if entity
|
|
|
|
and entity._cmi_is_mob == true
|
|
|
|
and entity.name ~= self.object:get_luaentity().name then
|
|
|
|
|
|
|
|
player:punch(self.object, 1.0, {
|
|
|
|
full_punch_interval = 1.0,
|
|
|
|
damage_groups = {fleshy = 8},
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
sync_table(self.owner)
|
|
|
|
self.object:remove()
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self.lastpos = pos
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
function fire_sword(itemstack, user, pointed_thing)
|
|
|
|
local speed = 8
|
|
|
|
local pos = user:getpos()
|
|
|
|
local v = user:get_look_dir()
|
|
|
|
local player_name = user:get_player_name()
|
|
|
|
|
|
|
|
if fired_table[player_name] ~= nil then
|
|
|
|
|
|
|
|
if fired_table[player_name] >= 1 then
|
|
|
|
minetest.chat_send_player(player_name, "You can shoot 1 shot at the same time!")
|
|
|
|
return
|
|
|
|
else
|
|
|
|
fired_table[player_name] = fired_table[player_name] + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
fired_table[player_name] = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
-- print(minetest.serialize(fired_table))
|
|
|
|
|
|
|
|
pos.x = pos.x + v.x
|
|
|
|
pos.z = pos.z + v.z
|
|
|
|
if v.y > 0.4 or v.y < -0.4 then
|
|
|
|
pos.y = pos.y + v.y
|
|
|
|
else
|
|
|
|
pos.y = pos.y + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
-- play shoot attack sound
|
|
|
|
minetest.sound_play("throwing_sound", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0, -- default
|
|
|
|
max_hear_distance = 32, -- default, uses an euclidean metric
|
|
|
|
})
|
|
|
|
|
|
|
|
local obj = minetest.add_entity(pos, "obsidianmese:sword_bullet")
|
|
|
|
local ent = obj:get_luaentity()
|
|
|
|
ent.owner = player_name or ""
|
|
|
|
|
|
|
|
if ent then
|
|
|
|
v.x = v.x * speed
|
|
|
|
v.y = v.y * speed
|
|
|
|
v.z = v.z * speed
|
|
|
|
|
|
|
|
obj:setvelocity(v)
|
|
|
|
else
|
|
|
|
obj:remove() -- arrow entity does not exist
|
|
|
|
end
|
|
|
|
|
|
|
|
-- wear tool
|
|
|
|
local wdef = itemstack:get_definition()
|
|
|
|
itemstack:add_wear(65535 / (150 - 1))
|
|
|
|
-- Tool break sound
|
|
|
|
if itemstack:get_count() == 0 and wdef.sound and wdef.sound.breaks then
|
|
|
|
minetest.sound_play(wdef.sound.breaks, {pos = pointed_thing.above, gain = 0.5})
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_tool("obsidianmese:sword_engraved", {
|
|
|
|
description = "Obsidian Mese Sword Engraved - right click shoot 1 shot",
|
|
|
|
inventory_image = "obsidianmese_sword_diamond_engraved.png",
|
|
|
|
tool_capabilities = {
|
|
|
|
full_punch_interval = 0.6,
|
|
|
|
max_drop_level=1,
|
|
|
|
groupcaps={
|
|
|
|
snappy={times={[1]=1.90, [2]=0.90, [3]=0.30}, uses=300, maxlevel=3},
|
|
|
|
},
|
|
|
|
damage_groups = {fleshy=8},
|
|
|
|
sound = {breaks = "default_tool_breaks"},
|
|
|
|
},
|
|
|
|
on_secondary_use = function(itemstack, user, pointed_thing)
|
|
|
|
if user:get_player_control().RMB then
|
|
|
|
return fire_sword(itemstack, user, pointed_thing)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-10-16 03:28:49 -07:00
|
|
|
-- pick axe
|
|
|
|
minetest.register_tool("obsidianmese:pick", {
|
|
|
|
description = "Obsidian Mese Pickaxe",
|
|
|
|
inventory_image = "obsidianmese_pick.png",
|
|
|
|
tool_capabilities = {
|
|
|
|
full_punch_interval = 0.9,
|
|
|
|
max_drop_level=3,
|
|
|
|
groupcaps={
|
2017-08-09 13:18:37 -07:00
|
|
|
cracky={times={[1]=2.0, [2]=1.0, [3]=0.50}, uses=250, maxlevel=3},
|
|
|
|
crumbly={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=350, maxlevel=3},
|
|
|
|
snappy={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=300, maxlevel=3}
|
2016-10-16 03:28:49 -07:00
|
|
|
},
|
|
|
|
damage_groups = {fleshy=5},
|
2016-11-21 00:13:17 -08:00
|
|
|
sound = {breaks = "default_tool_breaks"},
|
2016-10-16 03:28:49 -07:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Items
|
|
|
|
--
|
|
|
|
|
|
|
|
-- apple
|
2016-10-25 14:30:06 -07:00
|
|
|
minetest.register_craftitem("obsidianmese:mese_apple", {
|
2016-10-16 03:28:49 -07:00
|
|
|
description = "Mese apple [restores full health]",
|
|
|
|
inventory_image = "obsidianmese_apple.png",
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
|
|
|
|
minetest.sound_play("apple_eat", {
|
|
|
|
pos = user:getpos(),
|
2017-08-09 13:18:37 -07:00
|
|
|
max_hear_distance = 32,
|
|
|
|
gain = 0.5,
|
2016-10-16 03:28:49 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
user:set_hp(20)
|
|
|
|
itemstack:take_item()
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
--
|
2017-08-09 13:18:37 -07:00
|
|
|
-- Crafting
|
2016-10-16 03:28:49 -07:00
|
|
|
--
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "obsidianmese:sword",
|
|
|
|
recipe = {
|
|
|
|
{"", "default:mese_crystal", ""},
|
|
|
|
{"default:obsidian_shard", "default:mese_crystal", "default:obsidian_shard"},
|
|
|
|
{"", "default:obsidian_shard", ""},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "obsidianmese:pick",
|
|
|
|
recipe = {
|
|
|
|
{"default:mese_crystal", "default:mese_crystal", "default:mese_crystal"},
|
|
|
|
{"", "default:obsidian_shard", ""},
|
|
|
|
{"", "default:obsidian_shard", ""},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2016-10-25 14:30:06 -07:00
|
|
|
output = "obsidianmese:mese_apple 4",
|
2016-10-16 03:28:49 -07:00
|
|
|
recipe = {
|
2016-10-25 14:30:06 -07:00
|
|
|
{"", "default:apple", ""},
|
|
|
|
{"default:apple","default:mese", "default:apple"},
|
|
|
|
{"", "default:apple", ""},
|
2016-10-16 03:28:49 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
print("[Mod] ObsidianMese Loaded.")
|