mirror of
https://github.com/Splizard/minetest-mod-snow.git
synced 2024-12-29 16:00:16 +01:00
automatic snowball throwing in creative mdoe
This commit is contained in:
parent
09a422a0e7
commit
777d5b1407
@ -13,34 +13,35 @@ local function get_gravity()
|
|||||||
return grav*snow.snowball_gravity
|
return grav*snow.snowball_gravity
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[local someone_digging
|
local someone_throwing
|
||||||
local timer = 0]]
|
local timer = 0
|
||||||
|
|
||||||
--Shoot snowball
|
--Shoot snowball
|
||||||
local function snow_shoot_snowball(item, player)
|
local function snow_shoot_snowball(item, player)
|
||||||
local pos = player:getpos()
|
local addp = {y = 1.625} -- + (math.random()-0.5)/5}
|
||||||
pos.y = pos.y+1.625
|
|
||||||
local obj = minetest.add_entity(pos, "snow:snowball_entity")
|
|
||||||
local dir = player:get_look_dir()
|
local dir = player:get_look_dir()
|
||||||
|
local dif = 2*math.sqrt(dir.z*dir.z+dir.x*dir.x)
|
||||||
|
addp.x = dir.z/dif -- + (math.random()-0.5)/5
|
||||||
|
addp.z = -dir.x/dif -- + (math.random()-0.5)/5
|
||||||
|
local pos = vector.add(player:getpos(), addp)
|
||||||
|
local obj = minetest.add_entity(pos, "snow:snowball_entity")
|
||||||
obj:setvelocity(vector.multiply(dir, snow.snowball_velocity))
|
obj:setvelocity(vector.multiply(dir, snow.snowball_velocity))
|
||||||
obj:setacceleration({x=dir.x*-3, y=-get_gravity(), z=dir.z*-3})
|
obj:setacceleration({x=dir.x*-3, y=-get_gravity(), z=dir.z*-3})
|
||||||
if creative_mode then
|
if creative_mode then
|
||||||
|
if not someone_throwing then
|
||||||
|
someone_throwing = true
|
||||||
|
timer = -0.5
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
item:take_item()
|
item:take_item()
|
||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[ simulate the players digging with it using a globalstep
|
if creative_mode then
|
||||||
minetest.register_globalstep(function(dtime)
|
local function update_step(dtime)
|
||||||
-- abort if noone uses a drill
|
|
||||||
if not someone_digging then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- abort that it doesn't dig too fast
|
|
||||||
timer = timer+dtime
|
timer = timer+dtime
|
||||||
if timer < speed then
|
if timer < 0.006 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
timer = 0
|
timer = 0
|
||||||
@ -50,26 +51,28 @@ minetest.register_globalstep(function(dtime)
|
|||||||
if player:get_player_control().LMB then
|
if player:get_player_control().LMB then
|
||||||
local item = player:get_wielded_item()
|
local item = player:get_wielded_item()
|
||||||
local itemname = item:get_name()
|
local itemname = item:get_name()
|
||||||
for name,func in pairs(drills) do
|
if itemname == "default:snow" then
|
||||||
if name == itemname then
|
snow_shoot_snowball(nil, player)
|
||||||
-- player has a mk3 drill as wielditem and holds left mouse button
|
|
||||||
local pt = get_pointed_thing(player, ranges[itemname])
|
|
||||||
if pt then
|
|
||||||
-- simulate the function
|
|
||||||
player:set_wielded_item(func(item, player, pt))
|
|
||||||
end
|
|
||||||
active = true
|
active = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- disable the function if noone currently throws them
|
||||||
|
if not active then
|
||||||
|
someone_throwing = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- disable the function if noone currently uses a mk3 drill to reduce lag
|
-- do automatic throwing using a globalstep
|
||||||
if not active then
|
minetest.register_globalstep(function(dtime)
|
||||||
someone_digging = false
|
-- only if one holds left click
|
||||||
|
if someone_throwing then
|
||||||
|
update_step(dtime)
|
||||||
end
|
end
|
||||||
end)--]]
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
--The snowball Entity
|
--The snowball Entity
|
||||||
local snow_snowball_ENTITY = {
|
local snow_snowball_ENTITY = {
|
||||||
@ -80,15 +83,24 @@ local snow_snowball_ENTITY = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function snow_snowball_ENTITY.on_activate(self)
|
function snow_snowball_ENTITY.on_activate(self)
|
||||||
|
self.object:setacceleration({x=0, y=-get_gravity(), z=0})
|
||||||
self.lastpos = self.object:getpos()
|
self.lastpos = self.object:getpos()
|
||||||
minetest.after(0, function(obj)
|
minetest.after(0.1, function(obj)
|
||||||
if not obj
|
if not obj then
|
||||||
or obj:getvelocity().y ~= 0 then
|
return
|
||||||
|
end
|
||||||
|
local vel = obj:getvelocity()
|
||||||
|
if vel
|
||||||
|
and vel.y ~= 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
minetest.after(0, function(obj)
|
minetest.after(0, function(obj)
|
||||||
if obj
|
if not obj then
|
||||||
and obj:getvelocity().y == 0 then
|
return
|
||||||
|
end
|
||||||
|
local vel = obj:getvelocity()
|
||||||
|
if not vel
|
||||||
|
or vel.y == 0 then
|
||||||
obj:remove()
|
obj:remove()
|
||||||
end
|
end
|
||||||
end, obj)
|
end, obj)
|
||||||
|
Loading…
Reference in New Issue
Block a user