Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DON'T SQUASH] Implement ice breaking on falling & fix crash if ctf_map is not present #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions winterize/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local leaves = {"leaves", "aspen_leaves", "jungleleaves"}

local snow_placement_blacklist = {"default:snow", ".*slab.*", ".*stair.*", ".*fence.*", ".*post.*", ".*door.*"}

local ice_sounds = default.node_sound_glass_defaults()
minetest.register_node("winterize:ice", { -- breaks instantly, drops nothing
drawtype = "nodebox",
description = "Ice",
Expand All @@ -30,10 +31,47 @@ minetest.register_node("winterize:ice", { -- breaks instantly, drops nothing
},
},
drop = "",
groups = {dig_immediate = 3, slippery = 4, fall_damage_add_percent = -75},
sounds = default.node_sound_glass_defaults(),
groups = {dig_immediate = 3, slippery = 4},
sounds = ice_sounds,
})

local ice_fall_damage = 2
minetest.register_on_player_hpchange(function(player, hp_change, reason)
if reason.type ~= "fall" then
return hp_change
end
local pos = player:get_pos()
local collision_box = player:get_properties().collisionbox
-- Remove all ice nodes the collision box presumably collided with
-- Only works for collision boxes where the XZ plane is smaller than 1x1
for y = 0, -10, -1 do -- HACK arbitrarily look down up to 10 nodes, as clients tend to report fall damage early
local ground_reached, ground_is_only_ice = false, true
for x = 1, 4, 3 do
for z = 3, 6, 3 do
local node_pos = vector.offset(pos, collision_box[x], y, collision_box[z])
local node = minetest.get_node(node_pos)
if node.name == "winterize:ice" then
ground_reached = true
minetest.dig_node(node_pos)
minetest.sound_play(ice_sounds.dig, {pos = node_pos}, true)
elseif (minetest.registered_nodes[node.name] or {}).walkable ~= false then
ground_reached = true
ground_is_only_ice = false
end
end
end
if ground_reached then
if ground_is_only_ice and hp_change < -ice_fall_damage then
-- Infer speed from damage: "1 hp per node/s", 1.4 node/s base speed that goes without damage according to clientenvironment.cpp
-- Continue falling with the speed only reduced by the done ice fall damage
player:add_velocity(vector.new(0, ice_fall_damage - 1.4 + hp_change, 0))
return -ice_fall_damage
end
return hp_change
end
end
end, true)

-- local function snow_can_fall_freely(pos)
-- local voxelmanip = VoxelManip()
-- local aircheck_pos = vector.new(pos.x, pos.y + 20, pos.z)
Expand Down Expand Up @@ -119,10 +157,12 @@ for _, leaftype in pairs(leaves) do
special_tiles = {"winterize_dead_leaves.png"},
})

minetest.override_item("ctf_map:" .. leaftype, {
tiles = {"winterize_dead_leaves.png"},
special_tiles = {"winterize_dead_leaves.png"},
})
if minetest.registered_nodes["ctf_map:" .. leaftype] then
minetest.override_item("ctf_map:" .. leaftype, {
tiles = {"winterize_dead_leaves.png"},
special_tiles = {"winterize_dead_leaves.png"},
})
end
end

for _, grasstype in pairs(grasses) do
Expand Down