mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-12-12 12:43:15 +01:00
Update minetest->Luanti in affected documentation, update minetest. -> core. in affected code, factor out common subexpressions in mods/ITEMS/vl_projectile/init.lua
This commit is contained in:
parent
7c1cb6dc46
commit
4c5b29b404
@ -1,7 +1,7 @@
|
|||||||
mcl_util = {}
|
mcl_util = {}
|
||||||
|
|
||||||
local modname = minetest.get_current_modname()
|
local modname = core.get_current_modname()
|
||||||
local modpath = minetest.get_modpath(modname)
|
local modpath = core.get_modpath(modname)
|
||||||
dofile(modpath.."/roman_numerals.lua")
|
dofile(modpath.."/roman_numerals.lua")
|
||||||
dofile(modpath.."/nodes.lua")
|
dofile(modpath.."/nodes.lua")
|
||||||
|
|
||||||
|
@ -5,20 +5,20 @@
|
|||||||
-- debugging. See:
|
-- debugging. See:
|
||||||
-- https://git.minetest.land/VoxeLibre/VoxeLibre/issues/1392
|
-- https://git.minetest.land/VoxeLibre/VoxeLibre/issues/1392
|
||||||
function mcl_util.get_natural_light (pos, time)
|
function mcl_util.get_natural_light (pos, time)
|
||||||
local status, retVal = pcall(minetest.get_natural_light, pos, time)
|
local status, retVal = pcall(core.get_natural_light, pos, time)
|
||||||
if status then
|
if status then
|
||||||
return retVal
|
return retVal
|
||||||
else
|
else
|
||||||
minetest.log("warning", "Failed to get natural light at pos: " .. dump(pos) .. ", time: " .. dump(time))
|
core.log("warning", "Failed to get natural light at pos: " .. dump(pos) .. ", time: " .. dump(time))
|
||||||
if (pos) then
|
if (pos) then
|
||||||
local node = minetest.get_node(pos)
|
local node = core.get_node(pos)
|
||||||
minetest.log("warning", "Node at pos: " .. dump(node.name))
|
core.log("warning", "Node at pos: " .. dump(node.name))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Based on minetest.rotate_and_place
|
-- Based on core.rotate_and_place
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Attempt to predict the desired orientation of the pillar-like node
|
Attempt to predict the desired orientation of the pillar-like node
|
||||||
@ -30,16 +30,16 @@ field is false or omitted (else, the itemstack is not changed).
|
|||||||
* `invert_wall`: if `true`, place wall-orientation on the ground and ground-
|
* `invert_wall`: if `true`, place wall-orientation on the ground and ground-
|
||||||
orientation on wall
|
orientation on wall
|
||||||
|
|
||||||
This function is a simplified version of minetest.rotate_and_place.
|
This function is a simplified version of core.rotate_and_place.
|
||||||
The Luanti function is seen as inappropriate because this includes mirror
|
The Luanti function is seen as inappropriate because this includes mirror
|
||||||
images of possible orientations, causing problems with pillar shadings.
|
images of possible orientations, causing problems with pillar shadings.
|
||||||
]]
|
]]
|
||||||
function mcl_util.rotate_axis_and_place(itemstack, placer, pointed_thing, infinitestacks, invert_wall)
|
function mcl_util.rotate_axis_and_place(itemstack, placer, pointed_thing, infinitestacks, invert_wall)
|
||||||
local unode = minetest.get_node_or_nil(pointed_thing.under)
|
local unode = core.get_node_or_nil(pointed_thing.under)
|
||||||
if not unode then
|
if not unode then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local undef = minetest.registered_nodes[unode.name]
|
local undef = core.registered_nodes[unode.name]
|
||||||
if undef and undef.on_rightclick and not invert_wall then
|
if undef and undef.on_rightclick and not invert_wall then
|
||||||
undef.on_rightclick(pointed_thing.under, unode, placer,
|
undef.on_rightclick(pointed_thing.under, unode, placer,
|
||||||
itemstack, pointed_thing)
|
itemstack, pointed_thing)
|
||||||
@ -50,7 +50,7 @@ function mcl_util.rotate_axis_and_place(itemstack, placer, pointed_thing, infini
|
|||||||
local above = pointed_thing.above
|
local above = pointed_thing.above
|
||||||
local under = pointed_thing.under
|
local under = pointed_thing.under
|
||||||
|
|
||||||
local anode = minetest.get_node_or_nil(above)
|
local anode = core.get_node_or_nil(above)
|
||||||
if not anode then
|
if not anode then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -62,12 +62,12 @@ function mcl_util.rotate_axis_and_place(itemstack, placer, pointed_thing, infini
|
|||||||
node = unode
|
node = unode
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.is_protected(pos, placer:get_player_name()) then
|
if core.is_protected(pos, placer:get_player_name()) then
|
||||||
minetest.record_protection_violation(pos, placer:get_player_name())
|
core.record_protection_violation(pos, placer:get_player_name())
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local ndef = minetest.registered_nodes[node.name]
|
local ndef = core.registered_nodes[node.name]
|
||||||
if not ndef or not ndef.buildable_to then
|
if not ndef or not ndef.buildable_to then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -80,7 +80,7 @@ function mcl_util.rotate_axis_and_place(itemstack, placer, pointed_thing, infini
|
|||||||
elseif above.z ~= under.z then
|
elseif above.z ~= under.z then
|
||||||
p2 = 6
|
p2 = 6
|
||||||
end
|
end
|
||||||
minetest.set_node(pos, {name = wield_name, param2 = p2})
|
core.set_node(pos, {name = wield_name, param2 = p2})
|
||||||
|
|
||||||
if not infinitestacks then
|
if not infinitestacks then
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
@ -89,10 +89,10 @@ function mcl_util.rotate_axis_and_place(itemstack, placer, pointed_thing, infini
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Wrapper of above function for use as `on_place` callback (Recommended).
|
-- Wrapper of above function for use as `on_place` callback (Recommended).
|
||||||
-- Similar to minetest.rotate_node.
|
-- Similar to core.rotate_node.
|
||||||
function mcl_util.rotate_axis(itemstack, placer, pointed_thing)
|
function mcl_util.rotate_axis(itemstack, placer, pointed_thing)
|
||||||
mcl_util.rotate_axis_and_place(itemstack, placer, pointed_thing,
|
mcl_util.rotate_axis_and_place(itemstack, placer, pointed_thing,
|
||||||
minetest.is_creative_enabled(placer:get_player_name()),
|
core.is_creative_enabled(placer:get_player_name()),
|
||||||
placer:get_player_control().sneak)
|
placer:get_player_control().sneak)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
@ -132,8 +132,8 @@ function mcl_util.generate_on_place_plant_function(condition)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Call on_rightclick if the pointed node defines it
|
-- Call on_rightclick if the pointed node defines it
|
||||||
local node = minetest.get_node(pointed_thing.under)
|
local node = core.get_node(pointed_thing.under)
|
||||||
local node_def = minetest.registered_nodes[node.name]
|
local node_def = core.registered_nodes[node.name]
|
||||||
|
|
||||||
if placer and not placer:get_player_control().sneak then
|
if placer and not placer:get_player_control().sneak then
|
||||||
if node_def and node_def.on_rightclick then
|
if node_def and node_def.on_rightclick then
|
||||||
@ -142,8 +142,8 @@ function mcl_util.generate_on_place_plant_function(condition)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local place_pos
|
local place_pos
|
||||||
local def_under = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name]
|
local def_under = core.registered_nodes[core.get_node(pointed_thing.under).name]
|
||||||
local def_above = minetest.registered_nodes[minetest.get_node(pointed_thing.above).name]
|
local def_above = core.registered_nodes[core.get_node(pointed_thing.above).name]
|
||||||
if not def_under or not def_above then
|
if not def_under or not def_above then
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
@ -160,11 +160,11 @@ function mcl_util.generate_on_place_plant_function(condition)
|
|||||||
local result, param2 = condition(place_pos, node, itemstack)
|
local result, param2 = condition(place_pos, node, itemstack)
|
||||||
if result == true then
|
if result == true then
|
||||||
local idef = itemstack:get_definition()
|
local idef = itemstack:get_definition()
|
||||||
local new_itemstack, success = minetest.item_place_node(itemstack, placer, pointed_thing, param2)
|
local new_itemstack, success = core.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
|
|
||||||
if success then
|
if success then
|
||||||
if idef.sounds and idef.sounds.place then
|
if idef.sounds and idef.sounds.place then
|
||||||
minetest.sound_play(idef.sounds.place, {pos = pointed_thing.above, gain = 1}, true)
|
core.sound_play(idef.sounds.place, {pos = pointed_thing.above, gain = 1}, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
itemstack = new_itemstack
|
itemstack = new_itemstack
|
||||||
@ -202,7 +202,7 @@ function mcl_util.bypass_buildable_to(func)
|
|||||||
-- Returns a logging function. For empty names, does not log. Copied from minetest builtin
|
-- Returns a logging function. For empty names, does not log. Copied from minetest builtin
|
||||||
-- https://github.com/minetest/minetest/blob/526a2f7b8c45504088e194a83d54a19045227bbd/builtin/game/item.lua#L142-L144
|
-- https://github.com/minetest/minetest/blob/526a2f7b8c45504088e194a83d54a19045227bbd/builtin/game/item.lua#L142-L144
|
||||||
local function make_log(name)
|
local function make_log(name)
|
||||||
return name ~= "" and minetest.log or function() end
|
return name ~= "" and core.log or function() end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Copied from minetest builtin
|
-- Copied from minetest builtin
|
||||||
@ -260,24 +260,24 @@ function mcl_util.bypass_buildable_to(func)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local under = pointed_thing.under
|
local under = pointed_thing.under
|
||||||
local oldnode_under = minetest.get_node_or_nil(under)
|
local oldnode_under = core.get_node_or_nil(under)
|
||||||
local above = pointed_thing.above
|
local above = pointed_thing.above
|
||||||
local oldnode_above = minetest.get_node_or_nil(above)
|
local oldnode_above = core.get_node_or_nil(above)
|
||||||
local playername = user_name(placer)
|
local playername = user_name(placer)
|
||||||
local log = make_log(playername)
|
local log = make_log(playername)
|
||||||
|
|
||||||
if not oldnode_under or not oldnode_above then
|
if not oldnode_under or not oldnode_above then
|
||||||
log("info", playername .. " tried to place"
|
log("info", playername .. " tried to place"
|
||||||
.. " node in unloaded position " .. minetest.pos_to_string(above))
|
.. " node in unloaded position " .. core.pos_to_string(above))
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
local olddef_under = minetest.registered_nodes[oldnode_under.name] or minetest.nodedef_default
|
local olddef_under = core.registered_nodes[oldnode_under.name] or core.nodedef_default
|
||||||
local olddef_above = minetest.registered_nodes[oldnode_above.name] or minetest.nodedef_default
|
local olddef_above = core.registered_nodes[oldnode_above.name] or core.nodedef_default
|
||||||
|
|
||||||
if not olddef_above.buildable_to and not olddef_under.buildable_to then
|
if not olddef_above.buildable_to and not olddef_under.buildable_to then
|
||||||
log("info", playername .. " tried to place"
|
log("info", playername .. " tried to place"
|
||||||
.. " node in invalid position " .. minetest.pos_to_string(above)
|
.. " node in invalid position " .. core.pos_to_string(above)
|
||||||
.. ", replacing " .. oldnode_above.name)
|
.. ", replacing " .. oldnode_above.name)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
@ -292,16 +292,16 @@ function mcl_util.bypass_buildable_to(func)
|
|||||||
place_to = under
|
place_to = under
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.is_protected(place_to, playername) then
|
if core.is_protected(place_to, playername) then
|
||||||
log("action", playername
|
log("action", playername
|
||||||
.. " tried to place " .. def.name
|
.. " tried to place " .. def.name
|
||||||
.. " at protected position "
|
.. " at protected position "
|
||||||
.. minetest.pos_to_string(place_to))
|
.. core.pos_to_string(place_to))
|
||||||
minetest.record_protection_violation(place_to, playername)
|
core.record_protection_violation(place_to, playername)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
local oldnode = minetest.get_node(place_to)
|
local oldnode = core.get_node(place_to)
|
||||||
local newnode = {name = def.name, param1 = 0, param2 = param2 or 0}
|
local newnode = {name = def.name, param1 = 0, param2 = param2 or 0}
|
||||||
|
|
||||||
-- Calculate direction for wall mounted stuff like torches and signs
|
-- Calculate direction for wall mounted stuff like torches and signs
|
||||||
@ -309,7 +309,7 @@ function mcl_util.bypass_buildable_to(func)
|
|||||||
newnode.param2 = def.place_param2
|
newnode.param2 = def.place_param2
|
||||||
elseif (def.paramtype2 == "wallmounted" or
|
elseif (def.paramtype2 == "wallmounted" or
|
||||||
def.paramtype2 == "colorwallmounted") and not param2 then
|
def.paramtype2 == "colorwallmounted") and not param2 then
|
||||||
newnode.param2 = minetest.dir_to_wallmounted(vector.subtract(under, above))
|
newnode.param2 = core.dir_to_wallmounted(vector.subtract(under, above))
|
||||||
-- Calculate the direction for furnaces and chests and stuff
|
-- Calculate the direction for furnaces and chests and stuff
|
||||||
elseif (def.paramtype2 == "facedir" or
|
elseif (def.paramtype2 == "facedir" or
|
||||||
def.paramtype2 == "colorfacedir" or
|
def.paramtype2 == "colorfacedir" or
|
||||||
@ -317,7 +317,7 @@ function mcl_util.bypass_buildable_to(func)
|
|||||||
def.paramtype2 == "color4dir") and not param2 then
|
def.paramtype2 == "color4dir") and not param2 then
|
||||||
local placer_pos = placer and placer:get_pos()
|
local placer_pos = placer and placer:get_pos()
|
||||||
if placer_pos then
|
if placer_pos then
|
||||||
newnode.param2 = minetest.dir_to_facedir(vector.subtract(above, placer_pos))
|
newnode.param2 = core.dir_to_facedir(vector.subtract(above, placer_pos))
|
||||||
log("info", "facedir: " .. newnode.param2)
|
log("info", "facedir: " .. newnode.param2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -346,23 +346,23 @@ function mcl_util.bypass_buildable_to(func)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Check if the node is attached and if it can be placed there
|
-- Check if the node is attached and if it can be placed there
|
||||||
local an = minetest.get_item_group(def.name, "attached_node")
|
local an = core.get_item_group(def.name, "attached_node")
|
||||||
if an ~= 0 and
|
if an ~= 0 and
|
||||||
not check_attached_node(place_to, newnode, an) then
|
not check_attached_node(place_to, newnode, an) then
|
||||||
log("action", "attached node " .. def.name ..
|
log("action", "attached node " .. def.name ..
|
||||||
" cannot be placed at " .. minetest.pos_to_string(place_to))
|
" cannot be placed at " .. core.pos_to_string(place_to))
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
log("action", playername .. " places node "
|
log("action", playername .. " places node "
|
||||||
.. def.name .. " at " .. minetest.pos_to_string(place_to))
|
.. def.name .. " at " .. core.pos_to_string(place_to))
|
||||||
|
|
||||||
-- Add node and update
|
-- Add node and update
|
||||||
minetest.add_node(place_to, newnode)
|
core.add_node(place_to, newnode)
|
||||||
|
|
||||||
-- Play sound if it was done by a player
|
-- Play sound if it was done by a player
|
||||||
if playername ~= "" and def.sounds and def.sounds.place then
|
if playername ~= "" and def.sounds and def.sounds.place then
|
||||||
minetest.sound_play(def.sounds.place, {
|
core.sound_play(def.sounds.place, {
|
||||||
pos = place_to,
|
pos = place_to,
|
||||||
exclude_player = playername,
|
exclude_player = playername,
|
||||||
}, true)
|
}, true)
|
||||||
@ -382,7 +382,7 @@ function mcl_util.bypass_buildable_to(func)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Run script hook
|
-- Run script hook
|
||||||
for _, callback in ipairs(minetest.registered_on_placenodes) do
|
for _, callback in ipairs(core.registered_on_placenodes) do
|
||||||
-- Deepcopy pos, node and pointed_thing because callback can modify them
|
-- Deepcopy pos, node and pointed_thing because callback can modify them
|
||||||
local place_to_copy = vector.copy(place_to)
|
local place_to_copy = vector.copy(place_to)
|
||||||
local newnode_copy = {name = newnode.name, param1 = newnode.param1, param2 = newnode.param2}
|
local newnode_copy = {name = newnode.name, param1 = newnode.param1, param2 = newnode.param2}
|
||||||
@ -402,10 +402,10 @@ end
|
|||||||
|
|
||||||
local DEFAULT_PALETTE_INDEXES = {grass_palette_index = 0, foliage_palette_index = 0, water_palette_index = 0}
|
local DEFAULT_PALETTE_INDEXES = {grass_palette_index = 0, foliage_palette_index = 0, water_palette_index = 0}
|
||||||
function mcl_util.get_palette_indexes_from_pos(pos)
|
function mcl_util.get_palette_indexes_from_pos(pos)
|
||||||
local biome_data = minetest.get_biome_data(pos)
|
local biome_data = core.get_biome_data(pos)
|
||||||
local biome = biome_data.biome
|
local biome = biome_data.biome
|
||||||
local biome_name = minetest.get_biome_name(biome)
|
local biome_name = core.get_biome_name(biome)
|
||||||
local reg_biome = minetest.registered_biomes[biome_name]
|
local reg_biome = core.registered_biomes[biome_name]
|
||||||
if reg_biome and reg_biome._mcl_grass_palette_index and reg_biome._mcl_foliage_palette_index and reg_biome._mcl_water_palette_index then
|
if reg_biome and reg_biome._mcl_grass_palette_index and reg_biome._mcl_foliage_palette_index and reg_biome._mcl_water_palette_index then
|
||||||
return {
|
return {
|
||||||
grass_palette_index = reg_biome._mcl_grass_palette_index,
|
grass_palette_index = reg_biome._mcl_grass_palette_index,
|
||||||
@ -418,7 +418,7 @@ function mcl_util.get_palette_indexes_from_pos(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function mcl_util.get_colorwallmounted_rotation(pos)
|
function mcl_util.get_colorwallmounted_rotation(pos)
|
||||||
local colorwallmounted_node = minetest.get_node(pos)
|
local colorwallmounted_node = core.get_node(pos)
|
||||||
for i = 0, 32, 1 do
|
for i = 0, 32, 1 do
|
||||||
local colorwallmounted_rotation = colorwallmounted_node.param2 - (i * 8)
|
local colorwallmounted_rotation = colorwallmounted_node.param2 - (i * 8)
|
||||||
if colorwallmounted_rotation < 6 then
|
if colorwallmounted_rotation < 6 then
|
||||||
@ -432,7 +432,7 @@ function mcl_util.match_node_to_filter(node_name, filters)
|
|||||||
local filter = filters[i]
|
local filter = filters[i]
|
||||||
if node_name == filter then return true end
|
if node_name == filter then return true end
|
||||||
|
|
||||||
if string.sub(filter,1,6) == "group:" and minetest.get_item_group(node_name, string.sub(filter,7)) ~= 0 then return true end
|
if string.sub(filter,1,6) == "group:" and core.get_item_group(node_name, string.sub(filter,7)) ~= 0 then return true end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -427,7 +427,7 @@ function mcl_mobs.register_arrow(name, def)
|
|||||||
pos.y = pos.y + 1
|
pos.y = pos.y + 1
|
||||||
self.lastpos = self.lastpos or pos
|
self.lastpos = self.lastpos or pos
|
||||||
|
|
||||||
minetest.add_item(self.lastpos, self.object:get_luaentity().name)
|
core.add_item(self.lastpos, self.object:get_luaentity().name)
|
||||||
end
|
end
|
||||||
|
|
||||||
mcl_util.remove_entity(self)
|
mcl_util.remove_entity(self)
|
||||||
@ -479,7 +479,7 @@ function mcl_mobs.register_arrow(name, def)
|
|||||||
|
|
||||||
-- does arrow have a tail (fireball)
|
-- does arrow have a tail (fireball)
|
||||||
if def.tail == 1 and def.tail_texture then
|
if def.tail == 1 and def.tail_texture then
|
||||||
minetest.add_particle({
|
core.add_particle({
|
||||||
pos = pos,
|
pos = pos,
|
||||||
velocity = {x = 0, y = 0, z = 0},
|
velocity = {x = 0, y = 0, z = 0},
|
||||||
acceleration = {x = 0, y = 0, z = 0},
|
acceleration = {x = 0, y = 0, z = 0},
|
||||||
|
@ -163,7 +163,7 @@ mcl_mobs.register_arrow("mobs_mc:dragon_fireball", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
hit_mob = function(self, mob)
|
hit_mob = function(self, mob)
|
||||||
minetest.sound_play("tnt_explode", {pos = mob:get_pos(), gain = 1.5, max_hear_distance = 2*64}, true)
|
core.sound_play("tnt_explode", {pos = mob:get_pos(), gain = 1.5, max_hear_distance = 2*64}, true)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- node hit, explode
|
-- node hit, explode
|
||||||
|
@ -128,7 +128,7 @@ mcl_mobs.register_arrow("mobs_mc:fireball", {
|
|||||||
local name = mob:get_luaentity().name
|
local name = mob:get_luaentity().name
|
||||||
mcl_mobs.mob_class.boom(self,self.object:get_pos(), 1, true)
|
mcl_mobs.mob_class.boom(self,self.object:get_pos(), 1, true)
|
||||||
local ent = mob:get_luaentity()
|
local ent = mob:get_luaentity()
|
||||||
if (not ent or ent.health <= 0) and self._owner and minetest.get_player_by_name(self._owner) and name == "mobs_mc:ghast" then
|
if (not ent or ent.health <= 0) and self._owner and core.get_player_by_name(self._owner) and name == "mobs_mc:ghast" then
|
||||||
awards.unlock(self._owner, "mcl:fireball_redir_serv")
|
awards.unlock(self._owner, "mcl:fireball_redir_serv")
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -127,7 +127,7 @@ local arrow_entity = {
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Item definition entity collision hook
|
-- Item definition entity collision hook
|
||||||
local item_def = minetest.registered_items[self._arrow_item]
|
local item_def = core.registered_items[self._arrow_item]
|
||||||
local hook = item_def and item_def._on_collide_with_entity
|
local hook = item_def and item_def._on_collide_with_entity
|
||||||
if hook then hook(self, pos, obj) end
|
if hook then hook(self, pos, obj) end
|
||||||
|
|
||||||
@ -162,13 +162,13 @@ local arrow_entity = {
|
|||||||
-- Preserve entity properties
|
-- Preserve entity properties
|
||||||
out.properties = self.object:get_properties()
|
out.properties = self.object:get_properties()
|
||||||
|
|
||||||
return minetest.serialize(out)
|
return core.serialize(out)
|
||||||
end,
|
end,
|
||||||
on_activate = function(self, staticdata, dtime_s)
|
on_activate = function(self, staticdata, dtime_s)
|
||||||
self.object:set_armor_groups({ immortal = 1 })
|
self.object:set_armor_groups({ immortal = 1 })
|
||||||
|
|
||||||
self._time_in_air = 1.0
|
self._time_in_air = 1.0
|
||||||
local data = minetest.deserialize(staticdata)
|
local data = core.deserialize(staticdata)
|
||||||
if not data then return end
|
if not data then return end
|
||||||
|
|
||||||
-- Restore entity properties
|
-- Restore entity properties
|
||||||
@ -189,7 +189,7 @@ local arrow_entity = {
|
|||||||
end
|
end
|
||||||
|
|
||||||
if data.shootername then
|
if data.shootername then
|
||||||
local shooter = minetest.get_player_by_name(data.shootername)
|
local shooter = core.get_player_by_name(data.shootername)
|
||||||
if shooter and shooter:is_player() then
|
if shooter and shooter:is_player() then
|
||||||
self._shooter = shooter
|
self._shooter = shooter
|
||||||
end
|
end
|
||||||
@ -206,7 +206,7 @@ mcl_bows.arrow_entity = table.copy(arrow_entity)
|
|||||||
|
|
||||||
vl_projectile.register("mcl_bows:arrow_entity", arrow_entity)
|
vl_projectile.register("mcl_bows:arrow_entity", arrow_entity)
|
||||||
|
|
||||||
minetest.register_on_respawnplayer(function(player)
|
core.register_on_respawnplayer(function(player)
|
||||||
for _, obj in pairs(player:get_children()) do
|
for _, obj in pairs(player:get_children()) do
|
||||||
local ent = obj:get_luaentity()
|
local ent = obj:get_luaentity()
|
||||||
if ent and ent.name and string.find(ent.name, "mcl_bows:arrow_entity") then
|
if ent and ent.name and string.find(ent.name, "mcl_bows:arrow_entity") then
|
||||||
@ -215,8 +215,8 @@ minetest.register_on_respawnplayer(function(player)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if minetest.get_modpath("mcl_core") and minetest.get_modpath("mcl_mobitems") then
|
if core.get_modpath("mcl_core") and core.get_modpath("mcl_mobitems") then
|
||||||
minetest.register_craft({
|
core.register_craft({
|
||||||
output = "mcl_bows:arrow 4",
|
output = "mcl_bows:arrow 4",
|
||||||
recipe = {
|
recipe = {
|
||||||
{"mcl_core:flint"},
|
{"mcl_core:flint"},
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = core.get_translator(core.get_current_modname())
|
||||||
|
|
||||||
local BOW_DURABILITY = 385
|
local BOW_DURABILITY = 385
|
||||||
|
|
||||||
@ -68,11 +68,11 @@ function mcl_bows.shoot_arrow(arrow_item, pos, dir, yaw, shooter, power, damage,
|
|||||||
le._knockback = knockback
|
le._knockback = knockback
|
||||||
le._collectable = collectable
|
le._collectable = collectable
|
||||||
le._arrow_item = arrow_item
|
le._arrow_item = arrow_item
|
||||||
local item_def = minetest.registered_items[le._arrow_item]
|
local item_def = core.registered_items[le._arrow_item]
|
||||||
if item_def and item_def._arrow_image then
|
if item_def and item_def._arrow_image then
|
||||||
obj:set_properties({ textures = item_def._arrow_image })
|
obj:set_properties({ textures = item_def._arrow_image })
|
||||||
end
|
end
|
||||||
minetest.sound_play("mcl_bows_bow_shoot", {pos=pos, max_hear_distance=16}, true)
|
core.sound_play("mcl_bows_bow_shoot", {pos=pos, max_hear_distance=16}, true)
|
||||||
if shooter and shooter:is_player() then
|
if shooter and shooter:is_player() then
|
||||||
if le.player == "" then
|
if le.player == "" then
|
||||||
le.player = shooter
|
le.player = shooter
|
||||||
|
@ -66,7 +66,7 @@ function mcl_bows_s.shoot_arrow_crossbow(arrow_item, pos, dir, yaw, shooter, pow
|
|||||||
le._knockback = knockback
|
le._knockback = knockback
|
||||||
le._collectable = collectable
|
le._collectable = collectable
|
||||||
le._arrow_item = arrow_item
|
le._arrow_item = arrow_item
|
||||||
minetest.sound_play("mcl_bows_crossbow_shoot", {pos=pos, max_hear_distance=16}, true)
|
core.sound_play("mcl_bows_crossbow_shoot", {pos=pos, max_hear_distance=16}, true)
|
||||||
if shooter and shooter:is_player() then
|
if shooter and shooter:is_player() then
|
||||||
if obj:get_luaentity().player == "" then
|
if obj:get_luaentity().player == "" then
|
||||||
obj:get_luaentity().player = shooter
|
obj:get_luaentity().player = shooter
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
mcl_bows = {}
|
mcl_bows = {}
|
||||||
|
local modpath = core.get_modpath("mcl_bows")
|
||||||
|
|
||||||
--Bow
|
--Bow
|
||||||
dofile(minetest.get_modpath("mcl_bows") .. "/arrow.lua")
|
dofile(modpath.."/arrow.lua")
|
||||||
dofile(minetest.get_modpath("mcl_bows") .. "/bow.lua")
|
dofile(modpath.."/bow.lua")
|
||||||
dofile(minetest.get_modpath("mcl_bows") .. "/rocket.lua")
|
dofile(modpath.."/rocket.lua")
|
||||||
|
|
||||||
--Crossbow
|
--Crossbow
|
||||||
dofile(minetest.get_modpath("mcl_bows") .. "/crossbow.lua")
|
dofile(modpath.."/crossbow.lua")
|
||||||
|
|
||||||
--Compatiblility with older MineClone worlds
|
--Compatiblility with older MineClone worlds
|
||||||
minetest.register_alias("mcl_throwing:bow", "mcl_bows:bow")
|
minetest.register_alias("mcl_throwing:bow", "mcl_bows:bow")
|
||||||
|
@ -14,7 +14,7 @@ local function damage_explosion(self, damagemulitplier, pos)
|
|||||||
local p = pos or self.object:get_pos()
|
local p = pos or self.object:get_pos()
|
||||||
if not p then return end
|
if not p then return end
|
||||||
mcl_explosions.explode(p, 3, {})
|
mcl_explosions.explode(p, 3, {})
|
||||||
local objects = minetest.get_objects_inside_radius(p, 8)
|
local objects = core.get_objects_inside_radius(p, 8)
|
||||||
for _,obj in pairs(objects) do
|
for _,obj in pairs(objects) do
|
||||||
if obj:is_player() then
|
if obj:is_player() then
|
||||||
mcl_util.deal_damage(obj, damagemulitplier - vector.distance(p, obj:get_pos()), {type = "explosion"})
|
mcl_util.deal_damage(obj, damagemulitplier - vector.distance(p, obj:get_pos()), {type = "explosion"})
|
||||||
@ -45,14 +45,14 @@ local function particle_explosion(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if type == 1 then
|
if type == 1 then
|
||||||
minetest.sound_play("mcl_bows_firework", {
|
core.sound_play("mcl_bows_firework", {
|
||||||
pos = pos,
|
pos = pos,
|
||||||
max_hear_distance = 100,
|
max_hear_distance = 100,
|
||||||
gain = 3.0,
|
gain = 3.0,
|
||||||
pitch = fpitch/100
|
pitch = fpitch/100
|
||||||
}, true)
|
}, true)
|
||||||
else
|
else
|
||||||
minetest.sound_play("mcl_bows_firework_soft", {
|
core.sound_play("mcl_bows_firework_soft", {
|
||||||
pos = pos,
|
pos = pos,
|
||||||
max_hear_distance = 100,
|
max_hear_distance = 100,
|
||||||
gain = 4.0,
|
gain = 4.0,
|
||||||
@ -61,7 +61,7 @@ local function particle_explosion(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if particle_pattern == 1 then
|
if particle_pattern == 1 then
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 400 * size,
|
amount = 400 * size,
|
||||||
time = 0.0001,
|
time = 0.0001,
|
||||||
minpos = pos,
|
minpos = pos,
|
||||||
@ -77,7 +77,7 @@ local function particle_explosion(pos)
|
|||||||
texture = "mcl_bows_firework_"..this_colors[1]..".png",
|
texture = "mcl_bows_firework_"..this_colors[1]..".png",
|
||||||
glow = 14,
|
glow = 14,
|
||||||
})
|
})
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 400 * size,
|
amount = 400 * size,
|
||||||
time = 0.0001,
|
time = 0.0001,
|
||||||
minpos = pos,
|
minpos = pos,
|
||||||
@ -93,7 +93,7 @@ local function particle_explosion(pos)
|
|||||||
texture = "mcl_bows_firework_"..this_colors[2]..".png",
|
texture = "mcl_bows_firework_"..this_colors[2]..".png",
|
||||||
glow = 14,
|
glow = 14,
|
||||||
})
|
})
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 100 * size,
|
amount = 100 * size,
|
||||||
time = 0.0001,
|
time = 0.0001,
|
||||||
minpos = pos,
|
minpos = pos,
|
||||||
@ -111,7 +111,7 @@ local function particle_explosion(pos)
|
|||||||
})
|
})
|
||||||
elseif particle_pattern == 2 then
|
elseif particle_pattern == 2 then
|
||||||
|
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 240 * size,
|
amount = 240 * size,
|
||||||
time = 0.0001,
|
time = 0.0001,
|
||||||
minpos = pos,
|
minpos = pos,
|
||||||
@ -127,7 +127,7 @@ local function particle_explosion(pos)
|
|||||||
texture = "mcl_bows_firework_"..this_colors[1]..".png",
|
texture = "mcl_bows_firework_"..this_colors[1]..".png",
|
||||||
glow = 14,
|
glow = 14,
|
||||||
})
|
})
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 500 * size,
|
amount = 500 * size,
|
||||||
time = 0.0001,
|
time = 0.0001,
|
||||||
minpos = pos,
|
minpos = pos,
|
||||||
@ -143,7 +143,7 @@ local function particle_explosion(pos)
|
|||||||
texture = "mcl_bows_firework_"..this_colors[2]..".png",
|
texture = "mcl_bows_firework_"..this_colors[2]..".png",
|
||||||
glow = 14,
|
glow = 14,
|
||||||
})
|
})
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 350 * size,
|
amount = 350 * size,
|
||||||
time = 0.0001,
|
time = 0.0001,
|
||||||
minpos = pos,
|
minpos = pos,
|
||||||
@ -161,7 +161,7 @@ local function particle_explosion(pos)
|
|||||||
})
|
})
|
||||||
elseif particle_pattern == 3 then
|
elseif particle_pattern == 3 then
|
||||||
|
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 400 * size,
|
amount = 400 * size,
|
||||||
time = 0.0001,
|
time = 0.0001,
|
||||||
minpos = pos,
|
minpos = pos,
|
||||||
@ -177,7 +177,7 @@ local function particle_explosion(pos)
|
|||||||
texture = "mcl_bows_firework_"..this_colors[1]..".png",
|
texture = "mcl_bows_firework_"..this_colors[1]..".png",
|
||||||
glow = 14,
|
glow = 14,
|
||||||
})
|
})
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 120 * size,
|
amount = 120 * size,
|
||||||
time = 0.0001,
|
time = 0.0001,
|
||||||
minpos = pos,
|
minpos = pos,
|
||||||
@ -193,7 +193,7 @@ local function particle_explosion(pos)
|
|||||||
texture = "mcl_bows_firework_"..this_colors[2]..".png",
|
texture = "mcl_bows_firework_"..this_colors[2]..".png",
|
||||||
glow = 14,
|
glow = 14,
|
||||||
})
|
})
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 130 * size,
|
amount = 130 * size,
|
||||||
time = 0.0001,
|
time = 0.0001,
|
||||||
minpos = pos,
|
minpos = pos,
|
||||||
@ -215,7 +215,7 @@ local function particle_explosion(pos)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_craftitem("mcl_bows:rocket", {
|
core.register_craftitem("mcl_bows:rocket", {
|
||||||
description = S("Arrow"),
|
description = S("Arrow"),
|
||||||
_tt_help = S("Ammunition").."\n"..S("Damage from bow: 1-10").."\n"..S("Damage from dispenser: 3"),
|
_tt_help = S("Ammunition").."\n"..S("Damage from bow: 1-10").."\n"..S("Damage from dispenser: 3"),
|
||||||
_doc_items_longdesc = S("Arrows are ammunition for bows and dispensers.").."\n"..
|
_doc_items_longdesc = S("Arrows are ammunition for bows and dispensers.").."\n"..
|
||||||
@ -278,8 +278,8 @@ end
|
|||||||
|
|
||||||
vl_projectile.register("mcl_bows:rocket_entity", rocket_entity)
|
vl_projectile.register("mcl_bows:rocket_entity", rocket_entity)
|
||||||
|
|
||||||
if minetest.get_modpath("mcl_core") and minetest.get_modpath("mcl_mobitems") then
|
if core.get_modpath("mcl_core") and core.get_modpath("mcl_mobitems") then
|
||||||
minetest.register_craft({
|
core.register_craft({
|
||||||
output = "mcl_bows:rocket 1",
|
output = "mcl_bows:rocket 1",
|
||||||
recipe = {
|
recipe = {
|
||||||
{"mcl_core:paper"},
|
{"mcl_core:paper"},
|
||||||
|
@ -310,7 +310,7 @@ end
|
|||||||
|
|
||||||
bobber_ENTITY.on_step = bobber_on_step
|
bobber_ENTITY.on_step = bobber_on_step
|
||||||
|
|
||||||
minetest.register_entity("mcl_fishing:bobber_entity", bobber_ENTITY)
|
core.register_entity("mcl_fishing:bobber_entity", bobber_ENTITY)
|
||||||
|
|
||||||
vl_projectile.register("mcl_fishing:flying_bobber_entity", {
|
vl_projectile.register("mcl_fishing:flying_bobber_entity", {
|
||||||
physical = false,
|
physical = false,
|
||||||
@ -336,11 +336,11 @@ vl_projectile.register("mcl_fishing:flying_bobber_entity", {
|
|||||||
-- Make sure the player field is valid for when we create the floating bobber
|
-- Make sure the player field is valid for when we create the floating bobber
|
||||||
if not player then return end
|
if not player then return end
|
||||||
|
|
||||||
local def = minetest.registered_nodes[node.name]
|
local def = core.registered_nodes[node.name]
|
||||||
if not def then return end
|
if not def then return end
|
||||||
|
|
||||||
if def.walkable or def.liquidtype == "flowing" or def.liquidtype == "source" then
|
if def.walkable or def.liquidtype == "flowing" or def.liquidtype == "source" then
|
||||||
local ent = minetest.add_entity(pos, "mcl_fishing:bobber_entity"):get_luaentity()
|
local ent = core.add_entity(pos, "mcl_fishing:bobber_entity"):get_luaentity()
|
||||||
ent.player = player
|
ent.player = player
|
||||||
ent.child = true
|
ent.child = true
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = core.get_translator(core.get_current_modname())
|
||||||
|
|
||||||
local PARTICLE_DENSITY = 4
|
local PARTICLE_DENSITY = 4
|
||||||
local mod_target = minetest.get_modpath("mcl_target")
|
local mod_target = core.get_modpath("mcl_target")
|
||||||
|
|
||||||
local function lingering_image(colorstring, opacity)
|
local function lingering_image(colorstring, opacity)
|
||||||
if not opacity then
|
if not opacity then
|
||||||
@ -37,7 +37,7 @@ local function linger_particles(pos, d, texture, color)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local lingering_timer = 0
|
local lingering_timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
core.register_globalstep(function(dtime)
|
||||||
|
|
||||||
lingering_timer = lingering_timer + dtime
|
lingering_timer = lingering_timer + dtime
|
||||||
if lingering_timer >= 1 then
|
if lingering_timer >= 1 then
|
||||||
@ -150,7 +150,7 @@ function mcl_potions.register_lingering(name, descr, color, def)
|
|||||||
local velocity = 10
|
local velocity = 10
|
||||||
local dir = placer:get_look_dir();
|
local dir = placer:get_look_dir();
|
||||||
local pos = placer:getpos();
|
local pos = placer:getpos();
|
||||||
minetest.sound_play("mcl_throwing_throw", {pos = pos, gain = 0.4, max_hear_distance = 16}, true)
|
core.sound_play("mcl_throwing_throw", {pos = pos, gain = 0.4, max_hear_distance = 16}, true)
|
||||||
local obj = vl_projectile.create(id.."_flying",{
|
local obj = vl_projectile.create(id.."_flying",{
|
||||||
pos = vector.offset(pos, dir.x, dir.y + 1.64, dir.z),
|
pos = vector.offset(pos, dir.x, dir.y + 1.64, dir.z),
|
||||||
owner = placer,
|
owner = placer,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = core.get_translator(core.get_current_modname())
|
||||||
local GRAVITY = tonumber(minetest.settings:get("movement_gravity"))
|
local GRAVITY = tonumber(core.settings:get("movement_gravity"))
|
||||||
local REDUX_MAP = {7/8,0.5,0.25}
|
local REDUX_MAP = {7/8,0.5,0.25}
|
||||||
local PARTICLE_DIAMETER = 0.1
|
local PARTICLE_DIAMETER = 0.1
|
||||||
local PARTICLE_MIN_VELOCITY = vector.new(-2, 0, -2)
|
local PARTICLE_MIN_VELOCITY = vector.new(-2, 0, -2)
|
||||||
@ -26,7 +26,7 @@ function mcl_potions.register_splash(name, descr, color, def)
|
|||||||
local groups = {brewitem=1, bottle=1, splash_potion=1, _mcl_potion=1}
|
local groups = {brewitem=1, bottle=1, splash_potion=1, _mcl_potion=1}
|
||||||
if def.nocreative then groups.not_in_creative_inventory = 1 end
|
if def.nocreative then groups.not_in_creative_inventory = 1 end
|
||||||
|
|
||||||
minetest.register_craftitem(id, {
|
core.register_craftitem(id, {
|
||||||
description = descr,
|
description = descr,
|
||||||
_tt_help = def._tt,
|
_tt_help = def._tt,
|
||||||
_dynamic_tt = def._dynamic_tt,
|
_dynamic_tt = def._dynamic_tt,
|
||||||
@ -96,7 +96,7 @@ function mcl_potions.register_splash(name, descr, color, def)
|
|||||||
particle_texture = particle_texture.."^[colorize:"..color..":127"
|
particle_texture = particle_texture.."^[colorize:"..color..":127"
|
||||||
|
|
||||||
local function splash_effects(self, pos, def, range)
|
local function splash_effects(self, pos, def, range)
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 50,
|
amount = 50,
|
||||||
time = 0.1,
|
time = 0.1,
|
||||||
minpos = vector.offset(pos, -PARTICLE_DIAMETER, 0.5, -PARTICLE_DIAMETER),
|
minpos = vector.offset(pos, -PARTICLE_DIAMETER, 0.5, -PARTICLE_DIAMETER),
|
||||||
@ -114,7 +114,7 @@ function mcl_potions.register_splash(name, descr, color, def)
|
|||||||
texture = particle_texture,
|
texture = particle_texture,
|
||||||
})
|
})
|
||||||
|
|
||||||
for _,obj in pairs(minetest.get_objects_inside_radius(pos, range)) do
|
for _,obj in pairs(core.get_objects_inside_radius(pos, range)) do
|
||||||
-- Make sure the potion can interact with this object
|
-- Make sure the potion can interact with this object
|
||||||
local entity = obj:get_luaentity()
|
local entity = obj:get_luaentity()
|
||||||
if obj:is_player() or entity and entity.is_mob then
|
if obj:is_player() or entity and entity.is_mob then
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = core.get_translator(core.get_current_modname())
|
||||||
|
|
||||||
local math = math
|
local math = math
|
||||||
|
|
||||||
@ -11,10 +11,10 @@ local function arrow_image(colorstring, opacity)
|
|||||||
return {"mcl_bows_arrow.png^(mcl_bows_arrow_overlay.png^[colorize:"..colorstring..":"..tostring(opacity)..")"}
|
return {"mcl_bows_arrow.png^(mcl_bows_arrow_overlay.png^[colorize:"..colorstring..":"..tostring(opacity)..")"}
|
||||||
end
|
end
|
||||||
|
|
||||||
local how_to_shoot = minetest.registered_items["mcl_bows:arrow"]._doc_items_usagehelp
|
local how_to_shoot = core.registered_items["mcl_bows:arrow"]._doc_items_usagehelp
|
||||||
|
|
||||||
local arrow_longdesc = minetest.registered_items["mcl_bows:arrow"]._doc_items_longdesc or ""
|
local arrow_longdesc = core.registered_items["mcl_bows:arrow"]._doc_items_longdesc or ""
|
||||||
local arrow_tt = minetest.registered_items["mcl_bows:arrow"]._tt_help or ""
|
local arrow_tt = core.registered_items["mcl_bows:arrow"]._tt_help or ""
|
||||||
|
|
||||||
function mcl_potions.register_arrow(name, desc, color, def)
|
function mcl_potions.register_arrow(name, desc, color, def)
|
||||||
local longdesc = def._longdesc or ""
|
local longdesc = def._longdesc or ""
|
||||||
@ -22,7 +22,7 @@ function mcl_potions.register_arrow(name, desc, color, def)
|
|||||||
local groups = {ammo=1, ammo_bow=1, brewitem=1, _mcl_potion=1}
|
local groups = {ammo=1, ammo_bow=1, brewitem=1, _mcl_potion=1}
|
||||||
if def.nocreative then groups.not_in_creative_inventory = 1 end
|
if def.nocreative then groups.not_in_creative_inventory = 1 end
|
||||||
local arrow_item = "mcl_potions:"..name.."_arrow"
|
local arrow_item = "mcl_potions:"..name.."_arrow"
|
||||||
minetest.register_craftitem(arrow_item, {
|
core.register_craftitem(arrow_item, {
|
||||||
description = desc,
|
description = desc,
|
||||||
_tt_help = arrow_tt .. "\n" .. tt,
|
_tt_help = arrow_tt .. "\n" .. tt,
|
||||||
_dynamic_tt = def._dynamic_tt,
|
_dynamic_tt = def._dynamic_tt,
|
||||||
@ -83,8 +83,8 @@ function mcl_potions.register_arrow(name, desc, color, def)
|
|||||||
end
|
end
|
||||||
vl_projectile.register("mcl_potions:"..name.."_arrow_entity", arrow_entity)
|
vl_projectile.register("mcl_potions:"..name.."_arrow_entity", arrow_entity)
|
||||||
|
|
||||||
if minetest.get_modpath("mcl_bows") then
|
if core.get_modpath("mcl_bows") then
|
||||||
minetest.register_craft({
|
core.register_craft({
|
||||||
output = "mcl_potions:"..name.."_arrow 8",
|
output = "mcl_potions:"..name.."_arrow 8",
|
||||||
recipe = {
|
recipe = {
|
||||||
{"mcl_bows:arrow","mcl_bows:arrow","mcl_bows:arrow"},
|
{"mcl_bows:arrow","mcl_bows:arrow","mcl_bows:arrow"},
|
||||||
@ -94,7 +94,7 @@ function mcl_potions.register_arrow(name, desc, color, def)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.get_modpath("doc_identifier") then
|
if core.get_modpath("doc_identifier") then
|
||||||
doc.sub.identifier.register_object("mcl_bows:arrow_entity", "craftitems", "mcl_bows:arrow")
|
doc.sub.identifier.register_object("mcl_bows:arrow_entity", "craftitems", "mcl_bows:arrow")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
local modname = minetest.get_current_modname()
|
local modname = core.get_current_modname()
|
||||||
local S = minetest.get_translator(modname)
|
local S = core.get_translator(modname)
|
||||||
|
|
||||||
local mod_target = minetest.get_modpath("mcl_target")
|
local mod_target = core.get_modpath("mcl_target")
|
||||||
local how_to_throw = S("Use the punch key to throw.")
|
local how_to_throw = S("Use the punch key to throw.")
|
||||||
|
|
||||||
-- Egg
|
-- Egg
|
||||||
minetest.register_craftitem("mcl_throwing:egg", {
|
core.register_craftitem("mcl_throwing:egg", {
|
||||||
description = S("Egg"),
|
description = S("Egg"),
|
||||||
_tt_help = S("Throwable").."\n"..S("Chance to hatch chicks when broken"),
|
_tt_help = S("Throwable").."\n"..S("Chance to hatch chicks when broken"),
|
||||||
_doc_items_longdesc = S("Eggs can be thrown or launched from a dispenser and breaks on impact. There is a small chance that 1 or even 4 chicks will pop out of the egg."),
|
_doc_items_longdesc = S("Eggs can be thrown or launched from a dispenser and breaks on impact. There is a small chance that 1 or even 4 chicks will pop out of the egg."),
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
local modname = minetest.get_current_modname()
|
local modname = core.get_current_modname()
|
||||||
local S = minetest.get_translator(modname)
|
local S = core.get_translator(modname)
|
||||||
|
|
||||||
local math = math
|
local math = math
|
||||||
local vector = vector
|
local vector = vector
|
||||||
|
|
||||||
local mod_target = minetest.get_modpath("mcl_target")
|
local mod_target = core.get_modpath("mcl_target")
|
||||||
local how_to_throw = S("Use the punch key to throw.")
|
local how_to_throw = S("Use the punch key to throw.")
|
||||||
|
|
||||||
-- Ender Pearl
|
-- Ender Pearl
|
||||||
minetest.register_craftitem("mcl_throwing:ender_pearl", {
|
core.register_craftitem("mcl_throwing:ender_pearl", {
|
||||||
description = S("Ender Pearl"),
|
description = S("Ender Pearl"),
|
||||||
_tt_help = S("Throwable").."\n"..minetest.colorize(mcl_colors.YELLOW, S("Teleports you on impact for cost of 5 HP")),
|
_tt_help = S("Throwable").."\n"..core.colorize(mcl_colors.YELLOW, S("Teleports you on impact for cost of 5 HP")),
|
||||||
_doc_items_longdesc = S("An ender pearl is an item which can be used for teleportation at the cost of health. It can be thrown and teleport the thrower to its impact location when it hits a solid block or a plant. Each teleportation hurts the user by 5 hit points."),
|
_doc_items_longdesc = S("An ender pearl is an item which can be used for teleportation at the cost of health. It can be thrown and teleport the thrower to its impact location when it hits a solid block or a plant. Each teleportation hurts the user by 5 hit points."),
|
||||||
_doc_items_usagehelp = how_to_throw,
|
_doc_items_usagehelp = how_to_throw,
|
||||||
wield_image = "mcl_throwing_ender_pearl.png",
|
wield_image = "mcl_throwing_ender_pearl.png",
|
||||||
@ -31,7 +31,7 @@ function on_collide(self, pos, node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Make sure we have a reference to the player
|
-- Make sure we have a reference to the player
|
||||||
local player = self._thrower and minetest.get_player_by_name(self._thrower)
|
local player = self._thrower and core.get_player_by_name(self._thrower)
|
||||||
if not player then return end
|
if not player then return end
|
||||||
|
|
||||||
-- Teleport and hurt player
|
-- Teleport and hurt player
|
||||||
@ -40,7 +40,7 @@ function on_collide(self, pos, node)
|
|||||||
local dir = vector.zero()
|
local dir = vector.zero()
|
||||||
|
|
||||||
local v = self.object:get_velocity()
|
local v = self.object:get_velocity()
|
||||||
local node_def = minetest.registered_nodes[node.name]
|
local node_def = core.registered_nodes[node.name]
|
||||||
if node_def and node_def.walkable then
|
if node_def and node_def.walkable then
|
||||||
local vc = vector.normalize(v) -- vector for calculating
|
local vc = vector.normalize(v) -- vector for calculating
|
||||||
-- Node is walkable, we have to find a place somewhere outside of that node
|
-- Node is walkable, we have to find a place somewhere outside of that node
|
||||||
@ -75,12 +75,12 @@ function on_collide(self, pos, node)
|
|||||||
|
|
||||||
-- Final teleportation position
|
-- Final teleportation position
|
||||||
local telepos = vector.add(pos, dir)
|
local telepos = vector.add(pos, dir)
|
||||||
local telenode = minetest.get_node(telepos)
|
local telenode = core.get_node(telepos)
|
||||||
|
|
||||||
--[[ It may be possible that telepos is walkable due to the algorithm.
|
--[[ It may be possible that telepos is walkable due to the algorithm.
|
||||||
Especially when the ender pearl is faster horizontally than vertical.
|
Especially when the ender pearl is faster horizontally than vertical.
|
||||||
This applies final fixing, just to be sure we're not in a walkable node ]]
|
This applies final fixing, just to be sure we're not in a walkable node ]]
|
||||||
if not minetest.registered_nodes[telenode.name] or minetest.registered_nodes[telenode.name].walkable then
|
if not core.registered_nodes[telenode.name] or core.registered_nodes[telenode.name].walkable then
|
||||||
if v.y < 0 then
|
if v.y < 0 then
|
||||||
telepos.y = telepos.y + 0.5
|
telepos.y = telepos.y + 0.5
|
||||||
else
|
else
|
||||||
@ -95,7 +95,7 @@ function on_collide(self, pos, node)
|
|||||||
|
|
||||||
-- 5% chance to spawn endermite at the player's origin
|
-- 5% chance to spawn endermite at the player's origin
|
||||||
if math.random(1,20) == 1 then
|
if math.random(1,20) == 1 then
|
||||||
minetest.add_entity(oldpos, "mobs_mc:endermite")
|
core.add_entity(oldpos, "mobs_mc:endermite")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ vl_projectile.register("mcl_throwing:ender_pearl_entity",{
|
|||||||
return le and (le.is_mob or le._hittable_by_projectile) or object:is_player()
|
return le and (le.is_mob or le._hittable_by_projectile) or object:is_player()
|
||||||
end,
|
end,
|
||||||
on_collide_with_entity = function(self, pos, entity)
|
on_collide_with_entity = function(self, pos, entity)
|
||||||
on_collide(self, pos, minetest.get_node(pos))
|
on_collide(self, pos, core.get_node(pos))
|
||||||
end,
|
end,
|
||||||
on_collide_with_solid = on_collide,
|
on_collide_with_solid = on_collide,
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
mcl_throwing = {}
|
mcl_throwing = {}
|
||||||
|
|
||||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
local modpath = core.get_modpath(core.get_current_modname())
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Snowballs and other throwable items
|
-- Snowballs and other throwable items
|
||||||
@ -12,13 +12,13 @@ local velocities = {}
|
|||||||
function mcl_throwing.register_throwable_object(name, entity, velocity)
|
function mcl_throwing.register_throwable_object(name, entity, velocity)
|
||||||
entity_mapping[name] = entity
|
entity_mapping[name] = entity
|
||||||
velocities[name] = velocity
|
velocities[name] = velocity
|
||||||
assert(minetest.registered_entities[entity], entity.." not registered")
|
assert(core.registered_entities[entity], entity.." not registered")
|
||||||
assert(minetest.registered_entities[entity]._vl_projectile)
|
assert(core.registered_entities[entity]._vl_projectile)
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_throwing.throw(throw_item, pos, dir, velocity, thrower)
|
function mcl_throwing.throw(throw_item, pos, dir, velocity, thrower)
|
||||||
velocity = velocity or velocities[throw_item] or 22
|
velocity = velocity or velocities[throw_item] or 22
|
||||||
minetest.sound_play("mcl_throwing_throw", {pos=pos, gain=0.4, max_hear_distance=16}, true)
|
core.sound_play("mcl_throwing_throw", {pos=pos, gain=0.4, max_hear_distance=16}, true)
|
||||||
|
|
||||||
local itemstring = ItemStack(throw_item):get_name()
|
local itemstring = ItemStack(throw_item):get_name()
|
||||||
local obj = vl_projectile.create(entity_mapping[itemstring], {
|
local obj = vl_projectile.create(entity_mapping[itemstring], {
|
||||||
@ -67,7 +67,7 @@ function mcl_throwing.get_staticdata(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function mcl_throwing.on_activate(self, staticdata, dtime_s)
|
function mcl_throwing.on_activate(self, staticdata, dtime_s)
|
||||||
local data = minetest.deserialize(staticdata)
|
local data = core.deserialize(staticdata)
|
||||||
self._staticdata = data
|
self._staticdata = data
|
||||||
if data then
|
if data then
|
||||||
self._lastpos = data._lastpos
|
self._lastpos = data._lastpos
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
local modname = minetest.get_current_modname()
|
local modname = core.get_current_modname()
|
||||||
local modpath = minetest.get_modpath(modname)
|
local modpath = core.get_modpath(modname)
|
||||||
|
|
||||||
dofile(modpath.."/snowball.lua")
|
dofile(modpath.."/snowball.lua")
|
||||||
dofile(modpath.."/egg.lua")
|
dofile(modpath.."/egg.lua")
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
local modname = minetest.get_current_modname()
|
local modname = core.get_current_modname()
|
||||||
local S = minetest.get_translator(modname)
|
local S = core.get_translator(modname)
|
||||||
|
|
||||||
local mod_target = minetest.get_modpath("mcl_target")
|
local mod_target = core.get_modpath("mcl_target")
|
||||||
local how_to_throw = S("Use the punch key to throw.")
|
local how_to_throw = S("Use the punch key to throw.")
|
||||||
|
|
||||||
-- Snowball
|
-- Snowball
|
||||||
minetest.register_craftitem("mcl_throwing:snowball", {
|
core.register_craftitem("mcl_throwing:snowball", {
|
||||||
description = S("Snowball"),
|
description = S("Snowball"),
|
||||||
_tt_help = S("Throwable"),
|
_tt_help = S("Throwable"),
|
||||||
_doc_items_longdesc = S("Snowballs can be thrown or launched from a dispenser for fun. Hitting something with a snowball does nothing."),
|
_doc_items_longdesc = S("Snowballs can be thrown or launched from a dispenser for fun. Hitting something with a snowball does nothing."),
|
||||||
@ -20,7 +20,7 @@ minetest.register_craftitem("mcl_throwing:snowball", {
|
|||||||
-- The snowball entity
|
-- The snowball entity
|
||||||
local function snowball_particles(pos, vel)
|
local function snowball_particles(pos, vel)
|
||||||
local vel = vector.normalize(vector.multiply(vel, -1))
|
local vel = vector.normalize(vector.multiply(vel, -1))
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 20,
|
amount = 20,
|
||||||
time = 0.001,
|
time = 0.001,
|
||||||
minpos = pos,
|
minpos = pos,
|
||||||
|
@ -6,8 +6,8 @@ Registers a projectile entity.
|
|||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
* `entity_name`: The name the entity will be refered to by the minetest engine
|
* `entity_name`: The name the entity will be refered to by the Luanti engine
|
||||||
* `def`: Projectile defintion. Supports all fields that standard minetest entities support.
|
* `def`: Projectile defintion. Supports all fields that standard Luanti entities support.
|
||||||
Must include the field `_vl_projectile` for projectile-specific behaviors. These are the supported
|
Must include the field `_vl_projectile` for projectile-specific behaviors. These are the supported
|
||||||
fields:
|
fields:
|
||||||
* `ignore_gravity`: if true, the projectile will not be affected by gravity
|
* `ignore_gravity`: if true, the projectile will not be affected by gravity
|
||||||
@ -25,7 +25,7 @@ Arguments:
|
|||||||
behaviors: `vl_projectiles.collides_with_solids`, `vl_projectiles.collides_with_entities` and `vl_projectiles.raycast_collides_with_entities`
|
behaviors: `vl_projectiles.collides_with_solids`, `vl_projectiles.collides_with_entities` and `vl_projectiles.raycast_collides_with_entities`
|
||||||
* `maximum_time`: number of seconds until projectiles are removed.
|
* `maximum_time`: number of seconds until projectiles are removed.
|
||||||
* `sounds`: sounds for this projectile. All fields take a table with three parameters corresponding to the
|
* `sounds`: sounds for this projectile. All fields take a table with three parameters corresponding to the
|
||||||
three parameters for `minetest.play_sound()`. Supported sounds are:
|
three parameters for `core.play_sound()`. Supported sounds are:
|
||||||
* `on_collision`: played when no other more specific sound is defined. May be a function of type `function(projectile, entity_def, projectile_def, type, ...)`
|
* `on_collision`: played when no other more specific sound is defined. May be a function of type `function(projectile, entity_def, projectile_def, type, ...)`
|
||||||
* `on_solid_collision`: played when the projectile collides with a solid node. May be a function of type
|
* `on_solid_collision`: played when the projectile collides with a solid node. May be a function of type
|
||||||
`funciton(projectile, entity_def, projectile_def, type, pos, node, node_def)` with `type = "node"`
|
`funciton(projectile, entity_def, projectile_def, type, pos, node, node_def)` with `type = "node"`
|
||||||
@ -93,7 +93,7 @@ Arguments:
|
|||||||
* `self`: The lua entity of the projectile
|
* `self`: The lua entity of the projectile
|
||||||
* `dtime`: The amount of time that has passed since the last update. Nomally the `dtime`
|
* `dtime`: The amount of time that has passed since the last update. Nomally the `dtime`
|
||||||
parameter of the entity's `on_step(self, dtime)` callback.
|
parameter of the entity's `on_step(self, dtime)` callback.
|
||||||
* `entity_def`: The definition from `minetest.registered_entities` for the projectile.
|
* `entity_def`: The definition from `core.registered_entities` for the projectile.
|
||||||
* `projectile_def`: Same as `entity_def._vl_projectile`
|
* `projectile_def`: Same as `entity_def._vl_projectile`
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
vl_projectile = {}
|
vl_projectile = {}
|
||||||
local mod = vl_projectile
|
local mod = vl_projectile
|
||||||
|
|
||||||
local vl_physics_path = minetest.get_modpath("vl_physics")
|
local vl_physics_path = core.get_modpath("vl_physics")
|
||||||
|
|
||||||
local DEBUG = false
|
local DEBUG = false
|
||||||
local YAW_OFFSET = -math.pi/2
|
local YAW_OFFSET = -math.pi/2
|
||||||
local GRAVITY = tonumber(minetest.settings:get("movement_gravity"))
|
local GRAVITY = tonumber(core.settings:get("movement_gravity"))
|
||||||
local STUCK_TIMEOUT = 60
|
local STUCK_TIMEOUT = 60
|
||||||
local STUCK_RECHECK_TIME = 0.25
|
local STUCK_RECHECK_TIME = 0.25
|
||||||
local enable_pvp = minetest.settings:get_bool("enable_pvp")
|
local enable_pvp = core.settings:get_bool("enable_pvp")
|
||||||
|
|
||||||
function mod.projectile_physics(obj, entity_def, v, a)
|
function mod.projectile_physics(obj, entity_def, v, a)
|
||||||
local le = obj:get_luaentity()
|
local le = obj:get_luaentity()
|
||||||
if not le then return end
|
if not le then return end
|
||||||
|
|
||||||
local entity_def = minetest.registered_entities[le.name]
|
local entity_def = core.registered_entities[le.name]
|
||||||
local pos = obj:get_pos()
|
local pos = obj:get_pos()
|
||||||
if not pos then return end
|
if not pos then return end
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ function mod.projectile_physics(obj, entity_def, v, a)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if entity_def.liquid_drag then
|
if entity_def.liquid_drag then
|
||||||
local def = minetest.registered_nodes[minetest.get_node(pos).name]
|
local def = core.registered_nodes[core.get_node(pos).name]
|
||||||
if def and def.liquidtype ~= "none" then
|
if def and def.liquidtype ~= "none" then
|
||||||
-- Slow down arrow in liquids
|
-- Slow down arrow in liquids
|
||||||
local visc = def.liquid_viscosity or 0
|
local visc = def.liquid_viscosity or 0
|
||||||
@ -53,7 +53,7 @@ function mod.projectile_physics(obj, entity_def, v, a)
|
|||||||
|
|
||||||
-- Update projectile yaw to match velocity direction
|
-- Update projectile yaw to match velocity direction
|
||||||
if v and le and not le._stuck then
|
if v and le and not le._stuck then
|
||||||
local yaw = minetest.dir_to_yaw(v) + YAW_OFFSET + (entity_def._vl_projectile.yaw_offset or 0)
|
local yaw = core.dir_to_yaw(v) + YAW_OFFSET + (entity_def._vl_projectile.yaw_offset or 0)
|
||||||
local pitch = math.asin(vector.normalize(v).y) + (entity_def._vl_projectile.pitch_offset or 0)
|
local pitch = math.asin(vector.normalize(v).y) + (entity_def._vl_projectile.pitch_offset or 0)
|
||||||
obj:set_rotation(vector.new(0,yaw,pitch))
|
obj:set_rotation(vector.new(0,yaw,pitch))
|
||||||
end
|
end
|
||||||
@ -77,7 +77,7 @@ function mod.update_projectile(self, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local entity_name = self.name
|
local entity_name = self.name
|
||||||
local entity_def = minetest.registered_entities[entity_name] or {}
|
local entity_def = core.registered_entities[entity_name] or {}
|
||||||
local entity_vl_projectile = entity_def._vl_projectile or {}
|
local entity_vl_projectile = entity_def._vl_projectile or {}
|
||||||
|
|
||||||
-- Update entity timer and remove expired projectiles
|
-- Update entity timer and remove expired projectiles
|
||||||
@ -106,7 +106,7 @@ end
|
|||||||
|
|
||||||
local function damage_particles(pos, is_critical)
|
local function damage_particles(pos, is_critical)
|
||||||
if is_critical then
|
if is_critical then
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 15,
|
amount = 15,
|
||||||
time = 0.1,
|
time = 0.1,
|
||||||
minpos = vector.offset(pos, -0.5, -0.5, -0.5),
|
minpos = vector.offset(pos, -0.5, -0.5, -0.5),
|
||||||
@ -147,8 +147,10 @@ local function check_hitpoint(hitpoint)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if not hitpoint.ref:is_player() and hitpoint.ref:get_luaentity() then
|
local obj = hitpoint.ref
|
||||||
if (hitpoint.ref:get_luaentity().is_mob or hitpoint.ref:get_luaentity()._hittable_by_projectile) then
|
local le = obj:get_luaentity()
|
||||||
|
if not obj:is_player() and le then
|
||||||
|
if (le.is_mob or le._hittable_by_projectile) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -159,7 +161,7 @@ local function handle_player_sticking(self, entity_def, projectile_def, entity)
|
|||||||
if self._in_player or self._blocked then return end
|
if self._in_player or self._blocked then return end
|
||||||
if not projectile_def.sticks_in_players then return end
|
if not projectile_def.sticks_in_players then return end
|
||||||
|
|
||||||
minetest.after(150, function() mcl_util.remove_entity(self) end)
|
core.after(150, function() mcl_util.remove_entity(self) end)
|
||||||
|
|
||||||
-- Handle blocking projectiles
|
-- Handle blocking projectiles
|
||||||
if mcl_shields.is_blocking(entity) then
|
if mcl_shields.is_blocking(entity) then
|
||||||
@ -207,10 +209,10 @@ function mod.burns(self, dtime, entity_def, projectile_def)
|
|||||||
if not pos then return true end
|
if not pos then return true end
|
||||||
|
|
||||||
-- Handle getting set on fire
|
-- Handle getting set on fire
|
||||||
local node = minetest.get_node(vector.round(pos))
|
local node = core.get_node(vector.round(pos))
|
||||||
if not node or node.name == "ignore" then return end
|
if not node or node.name == "ignore" then return end
|
||||||
|
|
||||||
local set_on_fire = minetest.get_item_group(node.name, "set_on_fire")
|
local set_on_fire = core.get_item_group(node.name, "set_on_fire")
|
||||||
if set_on_fire ~= 0 then
|
if set_on_fire ~= 0 then
|
||||||
mcl_burning.set_on_fire(self.object, set_on_fire)
|
mcl_burning.set_on_fire(self.object, set_on_fire)
|
||||||
end
|
end
|
||||||
@ -228,7 +230,7 @@ function mod.has_tracer(self, dtime, entity_def, projectile_def)
|
|||||||
if hide_tracer and hide_tracer(self) then return end
|
if hide_tracer and hide_tracer(self) then return end
|
||||||
|
|
||||||
-- Add tracer
|
-- Add tracer
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 20,
|
amount = 20,
|
||||||
time = .2,
|
time = .2,
|
||||||
minpos = vector.zero(),
|
minpos = vector.zero(),
|
||||||
@ -257,8 +259,8 @@ function mod.replace_with_item_drop(self, pos, projectile_def)
|
|||||||
item = projectile_def.item
|
item = projectile_def.item
|
||||||
end
|
end
|
||||||
|
|
||||||
if item and self._collectable and not minetest.is_creative_enabled("") then
|
if item and self._collectable and not core.is_creative_enabled("") then
|
||||||
local item = minetest.add_item(pos, item)
|
local item = core.add_item(pos, item)
|
||||||
item:set_velocity(vector.zero())
|
item:set_velocity(vector.zero())
|
||||||
item:set_yaw(self.object:get_yaw())
|
item:set_yaw(self.object:get_yaw())
|
||||||
end
|
end
|
||||||
@ -285,8 +287,8 @@ local function stuck_on_step(self, dtime, entity_def, projectile_def)
|
|||||||
if self._stuckrechecktimer > 1 then
|
if self._stuckrechecktimer > 1 then
|
||||||
self._stuckrechecktimer = 0
|
self._stuckrechecktimer = 0
|
||||||
if self._stuckin then
|
if self._stuckin then
|
||||||
local node = minetest.get_node(self._stuckin)
|
local node = core.get_node(self._stuckin)
|
||||||
local node_def = minetest.registered_nodes[node.name]
|
local node_def = core.registered_nodes[node.name]
|
||||||
if node_def and node_def.walkable == false then
|
if node_def and node_def.walkable == false then
|
||||||
mod.replace_with_item_drop(self, pos, projectile_def)
|
mod.replace_with_item_drop(self, pos, projectile_def)
|
||||||
return
|
return
|
||||||
@ -300,21 +302,21 @@ local function stuck_on_step(self, dtime, entity_def, projectile_def)
|
|||||||
-- Pickup arrow if player is nearby (not in Creative Mode)
|
-- Pickup arrow if player is nearby (not in Creative Mode)
|
||||||
if self._removed then return end
|
if self._removed then return end
|
||||||
|
|
||||||
local objects = minetest.get_objects_inside_radius(pos, 1)
|
local objects = core.get_objects_inside_radius(pos, 1)
|
||||||
for i = 1,#objects do
|
for i = 1,#objects do
|
||||||
local obj = objects[i]
|
local obj = objects[i]
|
||||||
if obj:is_player() then
|
if obj:is_player() then
|
||||||
local player_name = obj:get_player_name()
|
local player_name = obj:get_player_name()
|
||||||
local creative = minetest.is_creative_enabled(player_name)
|
local creative = core.is_creative_enabled(player_name)
|
||||||
if self._collectable and not creative then
|
if self._collectable and not creative then
|
||||||
local arrow_item = self._itemstring or self._arrow_item
|
local arrow_item = self._itemstring or self._arrow_item
|
||||||
if arrow_item and minetest.registered_items[arrow_item] and obj:get_inventory():room_for_item("main", arrow_item) then
|
if arrow_item and core.registered_items[arrow_item] and obj:get_inventory():room_for_item("main", arrow_item) then
|
||||||
obj:get_inventory():add_item("main", arrow_item)
|
obj:get_inventory():add_item("main", arrow_item)
|
||||||
self._picked_up = true
|
self._picked_up = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.sound_play("item_drop_pickup", {
|
core.sound_play("item_drop_pickup", {
|
||||||
pos = pos,
|
pos = pos,
|
||||||
max_hear_distance = 16,
|
max_hear_distance = 16,
|
||||||
gain = 1.0,
|
gain = 1.0,
|
||||||
@ -346,8 +348,8 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def)
|
|||||||
if not self._last_pos then return end
|
if not self._last_pos then return end
|
||||||
|
|
||||||
-- Check if the object can collide with this node
|
-- Check if the object can collide with this node
|
||||||
local node = minetest.get_node(pos)
|
local node = core.get_node(pos)
|
||||||
local node_def = minetest.registered_nodes[node.name]
|
local node_def = core.registered_nodes[node.name]
|
||||||
local collides_with = projectile_def.collides_with
|
local collides_with = projectile_def.collides_with
|
||||||
|
|
||||||
if entity_def.physical then
|
if entity_def.physical then
|
||||||
@ -386,12 +388,12 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def)
|
|||||||
dir = vector.new(0, -1, 0)
|
dir = vector.new(0, -1, 0)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
dir = minetest.facedir_to_dir(minetest.dir_to_facedir(minetest.yaw_to_dir(self.object:get_yaw()-YAW_OFFSET)))
|
dir = core.facedir_to_dir(core.dir_to_facedir(core.yaw_to_dir(self.object:get_yaw()-YAW_OFFSET)))
|
||||||
end
|
end
|
||||||
self._stuckin = vector.add(dpos, dir)
|
self._stuckin = vector.add(dpos, dir)
|
||||||
|
|
||||||
local snode = minetest.get_node(self._stuckin)
|
local snode = core.get_node(self._stuckin)
|
||||||
local sdef = minetest.registered_nodes[snode.name]
|
local sdef = core.registered_nodes[snode.name]
|
||||||
|
|
||||||
-- If node is non-walkable, unknown or ignore, don't make arrow stuck.
|
-- If node is non-walkable, unknown or ignore, don't make arrow stuck.
|
||||||
-- This causes a deflection in the engine.
|
-- This causes a deflection in the engine.
|
||||||
@ -436,7 +438,7 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def)
|
|||||||
if sound then
|
if sound then
|
||||||
local arg2 = table.copy(sound[2])
|
local arg2 = table.copy(sound[2])
|
||||||
arg2.pos = pos
|
arg2.pos = pos
|
||||||
minetest.sound_play(sound[1], arg2, sound[3])
|
core.sound_play(sound[1], arg2, sound[3])
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Normally objects should be removed on collision with solids
|
-- Normally objects should be removed on collision with solids
|
||||||
@ -508,7 +510,7 @@ local function handle_entity_collision(self, entity_def, projectile_def, object)
|
|||||||
if hook then hook(self, pos, object) end
|
if hook then hook(self, pos, object) end
|
||||||
|
|
||||||
-- Call reverse entity collision hook
|
-- Call reverse entity collision hook
|
||||||
local other_entity_def = minetest.registered_entities[object.name] or {}
|
local other_entity_def = core.registered_entities[object.name] or {}
|
||||||
local other_entity_vl_projectile = other_entity_def._vl_projectile or {}
|
local other_entity_vl_projectile = other_entity_def._vl_projectile or {}
|
||||||
local hook = other_entity_vl_projectile and other_entity_vl_projectile.on_collide
|
local hook = other_entity_vl_projectile and other_entity_vl_projectile.on_collide
|
||||||
if hook then hook(object, self) end
|
if hook then hook(object, self) end
|
||||||
@ -520,7 +522,7 @@ local function handle_entity_collision(self, entity_def, projectile_def, object)
|
|||||||
if sound then
|
if sound then
|
||||||
local arg2 = table.copy(sound[2])
|
local arg2 = table.copy(sound[2])
|
||||||
arg2.pos = pos
|
arg2.pos = pos
|
||||||
minetest.sound_play(sound[1], arg2, sound[3])
|
core.sound_play(sound[1], arg2, sound[3])
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Remove the projectile if it didn't survive
|
-- Remove the projectile if it didn't survive
|
||||||
@ -537,7 +539,7 @@ end
|
|||||||
function mod.collides_with_entities(self, dtime, entity_def, projectile_def)
|
function mod.collides_with_entities(self, dtime, entity_def, projectile_def)
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
local objects = minetest.get_objects_inside_radius(pos, 1.5)
|
local objects = core.get_objects_inside_radius(pos, 1.5)
|
||||||
for i = 1,#objects do
|
for i = 1,#objects do
|
||||||
local object = objects[i]
|
local object = objects[i]
|
||||||
local entity = object:get_luaentity()
|
local entity = object:get_luaentity()
|
||||||
@ -561,7 +563,7 @@ function mod.raycast_collides_with_entities(self, dtime, entity_def, projectile_
|
|||||||
local arrow_dir = self.object:get_velocity()
|
local arrow_dir = self.object:get_velocity()
|
||||||
|
|
||||||
--create a raycast from the arrow based on the velocity of the arrow to deal with lag
|
--create a raycast from the arrow based on the velocity of the arrow to deal with lag
|
||||||
local raycast = minetest.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 0.1)), true, false)
|
local raycast = core.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 0.1)), true, false)
|
||||||
for hitpoint in raycast do
|
for hitpoint in raycast do
|
||||||
if check_hitpoint(hitpoint) then
|
if check_hitpoint(hitpoint) then
|
||||||
local hitpoint_ref = hitpoint.ref
|
local hitpoint_ref = hitpoint.ref
|
||||||
@ -580,7 +582,7 @@ end
|
|||||||
|
|
||||||
function mod.create(entity_id, options)
|
function mod.create(entity_id, options)
|
||||||
local pos = options.pos
|
local pos = options.pos
|
||||||
local obj = minetest.add_entity(pos, entity_id, options.staticdata)
|
local obj = core.add_entity(pos, entity_id, options.staticdata)
|
||||||
|
|
||||||
-- Set initial velocity and acceleration
|
-- Set initial velocity and acceleration
|
||||||
local a, v
|
local a, v
|
||||||
@ -591,7 +593,7 @@ function mod.create(entity_id, options)
|
|||||||
a = vector.zero()
|
a = vector.zero()
|
||||||
v = a
|
v = a
|
||||||
end
|
end
|
||||||
local entity_def = minetest.registered_entities[entity_id]
|
local entity_def = core.registered_entities[entity_id]
|
||||||
mod.projectile_physics(obj, entity_def, v, a)
|
mod.projectile_physics(obj, entity_def, v, a)
|
||||||
|
|
||||||
-- Update projectile parameters
|
-- Update projectile parameters
|
||||||
@ -645,6 +647,6 @@ function mod.register(name, def)
|
|||||||
def._shooter = nil
|
def._shooter = nil
|
||||||
def._last_pos = nil
|
def._last_pos = nil
|
||||||
|
|
||||||
minetest.register_entity(name, def)
|
core.register_entity(name, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user