1
0
mirror of https://gitlab.com/echoes91/throwing.git synced 2025-06-29 14:50:25 +02:00

8 Commits

11 changed files with 41 additions and 28 deletions

View File

@ -27,6 +27,7 @@ minetest.register_node("throwing:arrow_build_box", {
}, },
tiles = {"throwing_arrow_build.png", "throwing_arrow_build.png", "throwing_arrow_build_back.png", "throwing_arrow_build_front.png", "throwing_arrow_build_2.png", "throwing_arrow_build.png"}, tiles = {"throwing_arrow_build.png", "throwing_arrow_build.png", "throwing_arrow_build_back.png", "throwing_arrow_build_front.png", "throwing_arrow_build_2.png", "throwing_arrow_build.png"},
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
use_texture_alpha = "opaque",
}) })
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
@ -42,7 +43,7 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local pos = self.object:get_pos()
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if not self.inventory or not self.stack then if not self.inventory or not self.stack then
self.object:remove() self.object:remove()
@ -74,7 +75,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
if self.lastpos.x~=nil then if self.lastpos.x~=nil then
if node.name ~= "air" then if node.name ~= "air" then
self.object:remove() self.object:remove()
if self.inventory and self.stack and not minetest.setting_getbool("creative_mode") then if self.inventory and self.stack and not minetest.settings:get_bool("creative_mode") then
self.inventory:remove_item("main", {name=self.stack:get_name()}) self.inventory:remove_item("main", {name=self.stack:get_name()})
end end
if self.stack then if self.stack then

View File

@ -27,6 +27,7 @@ minetest.register_node("throwing:arrow_dig_box", {
}, },
tiles = {"throwing_arrow_dig.png", "throwing_arrow_dig.png", "throwing_arrow_dig_back.png", "throwing_arrow_dig_front.png", "throwing_arrow_dig_2.png", "throwing_arrow_dig.png"}, tiles = {"throwing_arrow_dig.png", "throwing_arrow_dig.png", "throwing_arrow_dig_back.png", "throwing_arrow_dig_front.png", "throwing_arrow_dig_2.png", "throwing_arrow_dig.png"},
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
use_texture_alpha = "opaque",
}) })
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
@ -41,7 +42,7 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local pos = self.object:get_pos()
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if self.timer>0.2 then if self.timer>0.2 then

View File

@ -27,6 +27,7 @@ minetest.register_node("throwing:arrow_fire_box", {
}, },
tiles = {"throwing_arrow_fire.png", "throwing_arrow_fire.png", "throwing_arrow_fire_back.png", "throwing_arrow_fire_front.png", "throwing_arrow_fire_2.png", "throwing_arrow_fire.png"}, tiles = {"throwing_arrow_fire.png", "throwing_arrow_fire.png", "throwing_arrow_fire_back.png", "throwing_arrow_fire_front.png", "throwing_arrow_fire_2.png", "throwing_arrow_fire.png"},
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
use_texture_alpha = "opaque",
}) })
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
@ -41,7 +42,7 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local pos = self.object:get_pos()
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if self.timer>0.2 then if self.timer>0.2 then

View File

@ -28,6 +28,7 @@ local function throwing_register_fireworks(color, desc)
}, },
tiles = {"throwing_arrow_fireworks_" .. color .. ".png", "throwing_arrow_fireworks_" .. color .. ".png", "throwing_arrow_fireworks_" .. color .. "_back.png", "throwing_arrow_fireworks_" .. color .. "_front.png", "throwing_arrow_fireworks_" .. color .. "_2.png", "throwing_arrow_fireworks_" .. color .. ".png"}, tiles = {"throwing_arrow_fireworks_" .. color .. ".png", "throwing_arrow_fireworks_" .. color .. ".png", "throwing_arrow_fireworks_" .. color .. "_back.png", "throwing_arrow_fireworks_" .. color .. "_front.png", "throwing_arrow_fireworks_" .. color .. "_2.png", "throwing_arrow_fireworks_" .. color .. ".png"},
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
use_texture_alpha = "opaque",
}) })
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
@ -74,7 +75,7 @@ local function throwing_register_fireworks(color, desc)
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local pos = self.object:get_pos()
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if self.timer < 0.07 then if self.timer < 0.07 then
minetest.sound_play("throwing_firework_launch", {pos=pos, gain=0.8, max_hear_distance=2*64}) minetest.sound_play("throwing_firework_launch", {pos=pos, gain=0.8, max_hear_distance=2*64})

View File

@ -20,12 +20,12 @@ function throwing_shoot_arrow (itemstack, player, stiffness, is_cross)
local arrow = itemstack:get_metadata() local arrow = itemstack:get_metadata()
itemstack:set_metadata("") itemstack:set_metadata("")
player:set_wielded_item(itemstack) player:set_wielded_item(itemstack)
local playerpos = player:getpos() local playerpos = player:get_pos()
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow) local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow)
local dir = player:get_look_dir() local dir = player:get_look_dir()
obj:setvelocity({x=dir.x*stiffness, y=dir.y*stiffness, z=dir.z*stiffness}) obj:set_velocity({x=dir.x*stiffness, y=dir.y*stiffness, z=dir.z*stiffness})
obj:setacceleration({x=dir.x*-3, y=-8.5, z=dir.z*-3}) obj:set_acceleration({x=dir.x*-3, y=-8.5, z=dir.z*-3})
obj:setyaw(player:get_look_yaw()+math.pi) obj:set_yaw(player:get_look_horizontal()-math.pi/2)
if is_cross then if is_cross then
minetest.sound_play("throwing_crossbow_sound", {pos=playerpos}) minetest.sound_play("throwing_crossbow_sound", {pos=playerpos})
else else
@ -58,11 +58,11 @@ function throwing_reload (itemstack, player, pos, is_cross, loaded)
local playerName = player:get_player_name() local playerName = player:get_player_name()
players[playerName]['reloading'] = false players[playerName]['reloading'] = false
if itemstack:get_name() == player:get_wielded_item():get_name() then if itemstack:get_name() == player:get_wielded_item():get_name() then
if (pos.x == player:getpos().x and pos.y == player:getpos().y and pos.z == player:getpos().z) or not is_cross then if (pos.x == player:get_pos().x and pos.y == player:get_pos().y and pos.z == player:get_pos().z) or not is_cross then
local wear = itemstack:get_wear() local wear = itemstack:get_wear()
for _,arrow in ipairs(throwing_arrows) do for _,arrow in ipairs(throwing_arrows) do
if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1] then if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1] then
if not minetest.setting_getbool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
player:get_inventory():remove_item("main", arrow[1]) player:get_inventory():remove_item("main", arrow[1])
end end
local meta = arrow[2] local meta = arrow[2]
@ -82,7 +82,7 @@ function throwing_register_bow (name, desc, scale, stiffness, reload_time, tough
wield_scale = scale, wield_scale = scale,
stack_max = 1, stack_max = 1,
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
local pos = user:getpos() local pos = user:get_pos()
local playerName = user:get_player_name() local playerName = user:get_player_name()
if not players[playerName]['reloading'] then if not players[playerName]['reloading'] then
players[playerName]['reloading'] = true players[playerName]['reloading'] = true
@ -99,7 +99,7 @@ function throwing_register_bow (name, desc, scale, stiffness, reload_time, tough
stack_max = 1, stack_max = 1,
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
local wear = itemstack:get_wear() local wear = itemstack:get_wear()
if not minetest.setting_getbool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
wear = wear + (65535/toughness) wear = wear + (65535/toughness)
end end
local unloaded = "throwing:" .. name local unloaded = "throwing:" .. name

View File

@ -61,6 +61,6 @@ if minetest.get_modpath('tnt') then
dofile(minetest.get_modpath("throwing").."/fireworks_arrows.lua") dofile(minetest.get_modpath("throwing").."/fireworks_arrows.lua")
end end
if minetest.setting_get("log_mods") then if minetest.settings:get("log_mods") then
minetest.log("action", "throwing loaded") minetest.log("action", "throwing loaded")
end end

View File

@ -27,6 +27,7 @@ minetest.register_node("throwing:arrow_shell_box", {
}, },
tiles = {"throwing_arrow_shell.png", "throwing_arrow_shell.png", "throwing_arrow_shell_back.png", "throwing_arrow_shell_front.png", "throwing_arrow_shell_2.png", "throwing_arrow_shell.png"}, tiles = {"throwing_arrow_shell.png", "throwing_arrow_shell.png", "throwing_arrow_shell_back.png", "throwing_arrow_shell_front.png", "throwing_arrow_shell_2.png", "throwing_arrow_shell.png"},
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
use_texture_alpha = "opaque",
}) })
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
@ -71,7 +72,7 @@ end
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local pos = self.object:get_pos()
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if self.timer>0.2 then if self.timer>0.2 then

View File

@ -28,6 +28,7 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft)
}, },
tiles = {"throwing_arrow_" .. kind .. ".png", "throwing_arrow_" .. kind .. ".png", "throwing_arrow_" .. kind .. "_back.png", "throwing_arrow_" .. kind .. "_front.png", "throwing_arrow_" .. kind .. "_2.png", "throwing_arrow_" .. kind .. ".png"}, tiles = {"throwing_arrow_" .. kind .. ".png", "throwing_arrow_" .. kind .. ".png", "throwing_arrow_" .. kind .. "_back.png", "throwing_arrow_" .. kind .. "_front.png", "throwing_arrow_" .. kind .. "_2.png", "throwing_arrow_" .. kind .. ".png"},
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
use_texture_alpha = "opaque",
}) })
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
@ -42,7 +43,7 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft)
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local pos = self.object:get_pos()
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if self.timer>0.2 then if self.timer>0.2 then

View File

@ -27,6 +27,7 @@ minetest.register_node("throwing:arrow_teleport_box", {
}, },
tiles = {"throwing_arrow_teleport.png", "throwing_arrow_teleport.png", "throwing_arrow_teleport_back.png", "throwing_arrow_teleport_front.png", "throwing_arrow_teleport_2.png", "throwing_arrow_teleport.png"}, tiles = {"throwing_arrow_teleport.png", "throwing_arrow_teleport.png", "throwing_arrow_teleport_back.png", "throwing_arrow_teleport_front.png", "throwing_arrow_teleport_2.png", "throwing_arrow_teleport.png"},
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
use_texture_alpha = "opaque",
}) })
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
@ -42,7 +43,7 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local pos = self.object:get_pos()
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if not self.player then if not self.player then
self.object:remove() self.object:remove()
@ -55,7 +56,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
if obj:get_luaentity().name ~= "throwing:arrow_teleport_entity" and obj:get_luaentity().name ~= "__builtin:item" then if obj:get_luaentity().name ~= "throwing:arrow_teleport_entity" and obj:get_luaentity().name ~= "__builtin:item" then
self.object:remove() self.object:remove()
if self.player ~= "" then if self.player ~= "" then
self.player:setpos(pos) self.player:set_pos(pos)
self.player:get_inventory():add_item("main", ItemStack("default:stick 2")) self.player:get_inventory():add_item("main", ItemStack("default:stick 2"))
end end
end end
@ -67,7 +68,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
if node.name ~= "air" then if node.name ~= "air" then
self.object:remove() self.object:remove()
if self.player ~= "" then if self.player ~= "" then
self.player:setpos(self.lastpos) self.player:set_pos(self.lastpos)
self.player:get_inventory():add_item("main", ItemStack("default:stick 2")) self.player:get_inventory():add_item("main", ItemStack("default:stick 2"))
end end
end end

View File

@ -27,6 +27,7 @@ minetest.register_node("throwing:arrow_tnt_box", {
}, },
tiles = {"throwing_arrow_tnt.png", "throwing_arrow_tnt.png", "throwing_arrow_tnt_back.png", "throwing_arrow_tnt_front.png", "throwing_arrow_tnt_2.png", "throwing_arrow_tnt.png"}, tiles = {"throwing_arrow_tnt.png", "throwing_arrow_tnt.png", "throwing_arrow_tnt_back.png", "throwing_arrow_tnt_front.png", "throwing_arrow_tnt_2.png", "throwing_arrow_tnt.png"},
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
use_texture_alpha = "opaque",
}) })
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
@ -47,7 +48,7 @@ local loss_prob = {}
loss_prob["default:cobble"] = 3 loss_prob["default:cobble"] = 3
loss_prob["default:dirt"] = 4 loss_prob["default:dirt"] = 4
local radius = tonumber(minetest.setting_get("tnt_radius") or 3) local radius = tonumber(minetest.settings:get("tnt_radius") or 3)
-- Fill a list with data for content IDs, after all nodes are registered -- Fill a list with data for content IDs, after all nodes are registered
local cid_data = {} local cid_data = {}
@ -82,8 +83,8 @@ local function eject_drops(drops, pos, radius)
local obj = minetest.add_item(drop_pos, item) local obj = minetest.add_item(drop_pos, item)
if obj then if obj then
obj:get_luaentity().collect = true obj:get_luaentity().collect = true
obj:setacceleration({x=0, y=-10, z=0}) obj:set_acceleration({x=0, y=-10, z=0})
obj:setvelocity({x=math.random(-3, 3), y=10, obj:set_velocity({x=math.random(-3, 3), y=10,
z=math.random(-3, 3)}) z=math.random(-3, 3)})
end end
count = count - max count = count - max
@ -147,12 +148,12 @@ local function entity_physics(pos, radius)
radius = radius * 2 radius = radius * 2
local objs = minetest.get_objects_inside_radius(pos, radius) local objs = minetest.get_objects_inside_radius(pos, radius)
for _, obj in pairs(objs) do for _, obj in pairs(objs) do
local obj_pos = obj:getpos() local obj_pos = obj:get_pos()
local obj_vel = obj:getvelocity() local obj_vel = obj:get_velocity()
local dist = math.max(1, vector.distance(pos, obj_pos)) local dist = math.max(1, vector.distance(pos, obj_pos))
if obj_vel ~= nil then if obj_vel ~= nil then
obj:setvelocity(calc_velocity(pos, obj_pos, obj:set_velocity(calc_velocity(pos, obj_pos,
obj_vel, radius * 10)) obj_vel, radius * 10))
end end
@ -245,7 +246,7 @@ end
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local pos = self.object:get_pos()
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if self.timer>0.2 then if self.timer>0.2 then

View File

@ -27,6 +27,7 @@ minetest.register_node("throwing:arrow_torch_box", {
}, },
tiles = {"throwing_arrow_torch.png", "throwing_arrow_torch.png", "throwing_arrow_torch_back.png", "throwing_arrow_torch_front.png", "throwing_arrow_torch_2.png", "throwing_arrow_torch.png"}, tiles = {"throwing_arrow_torch.png", "throwing_arrow_torch.png", "throwing_arrow_torch_back.png", "throwing_arrow_torch_front.png", "throwing_arrow_torch_2.png", "throwing_arrow_torch.png"},
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
use_texture_alpha = "opaque",
}) })
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
@ -42,7 +43,7 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local pos = self.object:get_pos()
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if self.timer>0.2 then if self.timer>0.2 then
@ -76,7 +77,11 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
if not string.find(node.name, "water") and not string.find(node.name, "lava") and not string.find(node.name, "torch") then if not string.find(node.name, "water") and not string.find(node.name, "lava") and not string.find(node.name, "torch") then
local dir=vector.direction(self.lastpos, pos) local dir=vector.direction(self.lastpos, pos)
local wall=minetest.dir_to_wallmounted(dir) local wall=minetest.dir_to_wallmounted(dir)
minetest.add_node(self.lastpos, {name="default:torch", param2 = wall}) if wall ~= 1 and wall ~= 0 then
minetest.add_node(self.lastpos, {name="default:torch_wall", param2 = wall})
else
minetest.add_node(self.lastpos, {name="default:torch", param2 = wall})
end
else else
local toughness = 0.9 local toughness = 0.9
if math.random() < toughness then if math.random() < toughness then