forked from mtcontrib/minetest-mod-snow
change snowballs and play sounds; add preperation for automatic snowball throwing in creative mode
This commit is contained in:
parent
5b6592022f
commit
f26ece0620
18
init.lua
18
init.lua
@ -94,27 +94,39 @@ function snow.place(pos)
|
|||||||
if level < 63 then
|
if level < 63 then
|
||||||
if minetest.get_item_group(bnode.name, "leafdecay") == 0
|
if minetest.get_item_group(bnode.name, "leafdecay") == 0
|
||||||
and not snow.is_uneven(pos) then
|
and not snow.is_uneven(pos) then
|
||||||
|
minetest.sound_play("default_snow_footstep", {pos=pos})
|
||||||
minetest.add_node_level(pos, 7)
|
minetest.add_node_level(pos, 7)
|
||||||
end
|
end
|
||||||
elseif level == 63 then
|
elseif level == 63 then
|
||||||
local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass")
|
local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass")
|
||||||
if p
|
if p
|
||||||
and minetest.get_node_light(p, 0.5) == 15 then
|
and minetest.get_node_light(p, 0.5) == 15 then
|
||||||
|
minetest.sound_play("default_grass_footstep", {pos=pos})
|
||||||
minetest.place_node({x=pos.x, y=pos.y+1, z=pos.z}, {name="default:snow"})
|
minetest.place_node({x=pos.x, y=pos.y+1, z=pos.z}, {name="default:snow"})
|
||||||
else
|
else
|
||||||
minetest.add_node(pos,{name="default:snowblock"})
|
minetest.sound_play("default_snow_footstep", {pos=pos})
|
||||||
|
minetest.add_node(pos, {name="default:snowblock"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif node.name ~= "default:ice"
|
elseif node.name ~= "default:ice"
|
||||||
and bnode.name ~= "air" then
|
and bnode.name ~= "air" then
|
||||||
local drawtype = minetest.registered_nodes[node.name].drawtype
|
local data = minetest.registered_nodes[node.name]
|
||||||
|
local drawtype = data.drawtype
|
||||||
if drawtype == "normal"
|
if drawtype == "normal"
|
||||||
or drawtype == "allfaces_optional" then
|
or drawtype == "allfaces_optional" then
|
||||||
pos.y = pos.y+1
|
pos.y = pos.y+1
|
||||||
|
local sound = data.sounds
|
||||||
|
if sound then
|
||||||
|
sound = sound.footstep
|
||||||
|
if sound then
|
||||||
|
minetest.sound_play(sound.name, {pos=pos, gain=sound.gain})
|
||||||
|
end
|
||||||
|
end
|
||||||
minetest.place_node(pos, {name="default:snow"})
|
minetest.place_node(pos, {name="default:snow"})
|
||||||
elseif drawtype == "plantlike" then
|
elseif drawtype == "plantlike" then
|
||||||
pos.y = pos.y - 1
|
pos.y = pos.y - 1
|
||||||
if minetest.get_node(pos).name == "default:dirt_with_grass" then
|
if minetest.get_node(pos).name == "default:dirt_with_grass" then
|
||||||
|
minetest.sound_play("default_grass_footstep", {pos=pos})
|
||||||
minetest.add_node(pos, {name="default:dirt_with_snow"})
|
minetest.add_node(pos, {name="default:dirt_with_snow"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -164,7 +176,7 @@ local function is_uneven(pos)
|
|||||||
end
|
end
|
||||||
if found then
|
if found then
|
||||||
local p = {x=pos.x+foundx, y=pos.y, z=pos.z+foundz}
|
local p = {x=pos.x+foundx, y=pos.y, z=pos.z+foundz}
|
||||||
if snow.is_uneven(p) ~= true then
|
if is_uneven(p) ~= true then
|
||||||
minetest.add_node_level(p, 7)
|
minetest.add_node_level(p, 7)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
|
173
src/snowball.lua
173
src/snowball.lua
@ -6,61 +6,134 @@
|
|||||||
-- Quite a bit of trial-and-error learning here and it boiled down to a
|
-- Quite a bit of trial-and-error learning here and it boiled down to a
|
||||||
-- small handful of code lines making the difference. ~ LazyJ
|
-- small handful of code lines making the difference. ~ LazyJ
|
||||||
|
|
||||||
local snowball_GRAVITY=9
|
local creative_mode = minetest.setting_getbool("creative_mode")
|
||||||
local snowball_VELOCITY=19
|
|
||||||
|
local function get_gravity()
|
||||||
|
local grav = tonumber(minetest.setting_get("movement_gravity")) or 9.81
|
||||||
|
return grav*snow.snowball_gravity
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[local someone_digging
|
||||||
|
local timer = 0]]
|
||||||
|
|
||||||
--Shoot snowball
|
--Shoot snowball
|
||||||
local snow_shoot_snowball=function (item, player, pointed_thing)
|
local function snow_shoot_snowball(item, player)
|
||||||
local playerpos=player:getpos()
|
local pos = player:getpos()
|
||||||
local obj=minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, "snow:snowball_entity")
|
pos.y = pos.y+1.625
|
||||||
local dir=player:get_look_dir()
|
local obj = minetest.add_entity(pos, "snow:snowball_entity")
|
||||||
obj:setvelocity({x=dir.x*snowball_VELOCITY, y=dir.y*snowball_VELOCITY, z=dir.z*snowball_VELOCITY})
|
local dir = player:get_look_dir()
|
||||||
obj:setacceleration({x=dir.x*-3, y=-snowball_GRAVITY, z=dir.z*-3})
|
obj:setvelocity(vector.multiply(dir, snow.snowball_velocity))
|
||||||
|
obj:setacceleration({x=dir.x*-3, y=-get_gravity(), z=dir.z*-3})
|
||||||
|
if creative_mode then
|
||||||
|
return
|
||||||
|
end
|
||||||
item:take_item()
|
item:take_item()
|
||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[ simulate the players digging with it using a globalstep
|
||||||
|
minetest.register_globalstep(function(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
|
||||||
|
if timer < speed then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
timer = 0
|
||||||
|
|
||||||
|
local active
|
||||||
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
|
if player:get_player_control().LMB then
|
||||||
|
local item = player:get_wielded_item()
|
||||||
|
local itemname = item:get_name()
|
||||||
|
for name,func in pairs(drills) do
|
||||||
|
if name == itemname then
|
||||||
|
-- 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
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- disable the function if noone currently uses a mk3 drill to reduce lag
|
||||||
|
if not active then
|
||||||
|
someone_digging = false
|
||||||
|
end
|
||||||
|
end)--]]
|
||||||
|
|
||||||
--The snowball Entity
|
--The snowball Entity
|
||||||
snow_snowball_ENTITY={
|
local snow_snowball_ENTITY = {
|
||||||
physical = false,
|
physical = false,
|
||||||
timer=0,
|
timer = 0,
|
||||||
textures = {"default_snowball.png"},
|
textures = {"default_snowball.png"},
|
||||||
lastpos={},
|
collisionbox = {-5/16,-5/16,-5/16,5/16,5/16,5/16},
|
||||||
collisionbox = {0,0,0,0,0,0},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function snow_snowball_ENTITY.on_activate(self)
|
||||||
|
self.lastpos = self.object:getpos()
|
||||||
|
minetest.after(0, function(obj)
|
||||||
|
if not obj
|
||||||
|
or obj:getvelocity().y ~= 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
minetest.after(0, function(obj)
|
||||||
|
if obj
|
||||||
|
and obj:getvelocity().y == 0 then
|
||||||
|
obj:remove()
|
||||||
|
end
|
||||||
|
end, obj)
|
||||||
|
end, self.object)
|
||||||
|
end
|
||||||
|
|
||||||
--Snowball_entity.on_step()--> called when snowball is moving.
|
--Snowball_entity.on_step()--> called when snowball is moving.
|
||||||
snow_snowball_ENTITY.on_step = function(self, dtime)
|
function snow_snowball_ENTITY.on_step(self, dtime)
|
||||||
self.timer = self.timer+dtime
|
self.timer = self.timer+dtime
|
||||||
if self.timer > 600 then
|
if self.timer > 600 then
|
||||||
-- 10 minutes are too long for a snowball to fly somewhere
|
-- 10 minutes are too long for a snowball to fly somewhere
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
local pos = self.object:getpos()
|
|
||||||
local node = minetest.get_node(pos)
|
|
||||||
|
|
||||||
--Become item when hitting a node.
|
if self.physical then
|
||||||
if self.lastpos.x then --If there is no lastpos for some reason. ~ Splizard
|
local fell = self.object:getvelocity().y == 0
|
||||||
-- Check to see what is one node above where the snow is
|
if not fell then
|
||||||
-- going to be placed. ~ LazyJ, 2014_04_08
|
return
|
||||||
-- Identify the name of the node that was found above. ~ LazyJ, 2014_04_08
|
|
||||||
local findwhatisabove = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
|
|
||||||
-- If the node above is air, then it's OK to go on to the next step. ~ LazyJ, 2014_04_08
|
|
||||||
if findwhatisabove == "air" then
|
|
||||||
-- If the node where the snow is going is anything except air, then it's OK to put
|
|
||||||
-- the snow on it. ~ Original line of code by Splizard, comment by LazyJ so I can
|
|
||||||
-- keep track of what this code does. ~ LazyJ, 2014_04_07
|
|
||||||
if node.name ~= "air" then
|
|
||||||
snow.place(pos) -- this is the original code, I replaced it with
|
|
||||||
-- minetest.place_node and bumped the y position up by 2 (make the snow drop
|
|
||||||
-- from a node above and pile up). ~ LazyJ, 2014_04_07
|
|
||||||
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"})
|
|
||||||
self.object:remove()
|
|
||||||
end
|
|
||||||
else -- If findwhatisabove is not equal to "air" then cancel the snowball
|
|
||||||
-- with self.object:remove() ~ LazyJ, 2014_04_08
|
|
||||||
self.object:remove()
|
|
||||||
end
|
end
|
||||||
|
local pos = vector.round(self.object:getpos())
|
||||||
|
if minetest.get_node(pos).name == "air" then
|
||||||
|
pos.y = pos.y-1
|
||||||
|
if minetest.get_node(pos).name == "air" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
snow.place(pos)
|
||||||
|
self.object:remove()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local pos = vector.round(self.object:getpos())
|
||||||
|
if vector.equals(pos, self.lastpos) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if minetest.get_node(pos).name ~= "air" then
|
||||||
|
self.object:setacceleration({x=0, y=-get_gravity(), z=0})
|
||||||
|
--self.object:setvelocity({x=0, y=0, z=0})
|
||||||
|
pos = self.lastpos
|
||||||
|
self.object:setpos(pos)
|
||||||
|
local gain = vector.length(self.object:getvelocity())/30
|
||||||
|
minetest.sound_play("default_snow_footstep", {pos=pos, gain=gain})
|
||||||
|
self.object:set_properties({physical = true})
|
||||||
|
self.physical = true
|
||||||
|
return
|
||||||
end
|
end
|
||||||
self.lastpos = vector.new(pos)
|
self.lastpos = vector.new(pos)
|
||||||
end
|
end
|
||||||
@ -121,16 +194,8 @@ minetest.override_item("default:snow", {
|
|||||||
drop = {
|
drop = {
|
||||||
max_items = 2,
|
max_items = 2,
|
||||||
items = {
|
items = {
|
||||||
{
|
{items = {'snow:moss'}, rarity = 20,},
|
||||||
-- player will get sapling with 1/20 chance
|
{items = {'default:snow'},}
|
||||||
items = {'snow:moss'},
|
|
||||||
rarity = 20,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
-- player will get leaves only if he get no saplings,
|
|
||||||
-- this is because max_items is 1
|
|
||||||
items = {'default:snow'},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
leveled = 7,
|
leveled = 7,
|
||||||
@ -140,7 +205,7 @@ minetest.override_item("default:snow", {
|
|||||||
{-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
|
{-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3,falling_node=1, melts=2, float=1},
|
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, falling_node=1, melts=2, float=1},
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
--Disable placement prediction for snow.
|
--Disable placement prediction for snow.
|
||||||
node_placement_prediction = "",
|
node_placement_prediction = "",
|
||||||
@ -153,12 +218,6 @@ minetest.override_item("default:snow", {
|
|||||||
minetest.set_node(pos, node)
|
minetest.set_node(pos, node)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
--Remove dirt_with_snow and replace with dirt_with_grass.
|
|
||||||
--[[after_destruct = function(pos)
|
|
||||||
if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt_with_snow" then
|
|
||||||
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z}, {name="default:dirt_with_grass"})
|
|
||||||
end
|
|
||||||
end,]]
|
|
||||||
--Handle node drops due to node level.
|
--Handle node drops due to node level.
|
||||||
on_dig = function(pos, node, digger)
|
on_dig = function(pos, node, digger)
|
||||||
local level = minetest.get_node_level(pos)
|
local level = minetest.get_node_level(pos)
|
||||||
@ -170,12 +229,11 @@ minetest.override_item("default:snow", {
|
|||||||
end
|
end
|
||||||
local left = inv:add_item("main", "default:snow "..tostring(level/7-1))
|
local left = inv:add_item("main", "default:snow "..tostring(level/7-1))
|
||||||
if not left:is_empty() then
|
if not left:is_empty() then
|
||||||
local p = {
|
minetest.add_item({
|
||||||
x = pos.x + math.random()/2-0.25,
|
x = pos.x + math.random()/2-0.25,
|
||||||
y = pos.y + math.random()/2-0.25,
|
y = pos.y + math.random()/2-0.25,
|
||||||
z = pos.z + math.random()/2-0.25,
|
z = pos.z + math.random()/2-0.25,
|
||||||
}
|
}, left)
|
||||||
minetest.add_item(p, left)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@ -218,8 +276,7 @@ minetest.override_item("default:snow", {
|
|||||||
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
on_use = snow_shoot_snowball -- This line is from the 'Snow' mod,
|
on_use = snow_shoot_snowball
|
||||||
-- the reset is default Minetest. ~ LazyJ
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
--Global config and function table.
|
--Global config and function table.
|
||||||
snow = {
|
snow = {
|
||||||
|
snowball_gravity = 100/109,
|
||||||
|
snowball_velocity = 19,
|
||||||
sleds = true,
|
sleds = true,
|
||||||
enable_snowfall = true,
|
enable_snowfall = true,
|
||||||
lighter_snowfall = false,
|
lighter_snowfall = false,
|
||||||
@ -12,6 +14,8 @@ snow = {
|
|||||||
|
|
||||||
--Config documentation.
|
--Config documentation.
|
||||||
local doc = {
|
local doc = {
|
||||||
|
snowball_gravity = "The gravity of thrown snowballs",
|
||||||
|
snowball_velocity = "How fast players throw snowballs",
|
||||||
sleds = "Disable this to prevent sleds from being riden.",
|
sleds = "Disable this to prevent sleds from being riden.",
|
||||||
enable_snowfall = "Enables falling snow.",
|
enable_snowfall = "Enables falling snow.",
|
||||||
lighter_snowfall = "Reduces the amount of resources and fps used by snowfall.",
|
lighter_snowfall = "Reduces the amount of resources and fps used by snowfall.",
|
||||||
|
Loading…
Reference in New Issue
Block a user