Merge pull request #562 from MihailRis/fixes

Fixes
This commit is contained in:
MihailRis 2025-07-22 00:01:35 +03:00 committed by GitHub
commit 833459bb64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 19 deletions

View File

@ -64,8 +64,12 @@ function on_sensor_enter(index, oid)
local odrop = other:get_component("base:drop").dropitem
if odrop.id == dropitem.id and not odrop.data then
local stack = item.stack_size(dropitem.id)
local sum = dropitem.count + odrop.count
if sum <= stack then
local sum = (dropitem.count or 0) + (odrop.count or 0)
if sum == 0 then
dropitem:despawn();
odrop:despawn();
return
elseif sum <= stack then
dropitem.count = 0
odrop.count = sum
entity:despawn()

View File

@ -523,6 +523,15 @@ function time.post_runnable(runnable)
table.insert(__post_runnables, runnable)
end
-- Hide unsafe debug.* functions
local removed_names = {
"getregistry", "getupvalue", "setupvalue", "upvalueid", "upvaluejoin",
"sethook", "gethook", "getinfo"
}
for i, name in ipairs(removed_names) do
debug[name] = nil
end
-- --------- Deprecated functions ------ --
local function wrap_deprecated(func, name, alternatives)
return function (...)

View File

@ -461,10 +461,12 @@ function file.readlines(path)
return lines
end
local _debug_getinfo = debug.getinfo
function debug.count_frames()
local frames = 1
while true do
local info = debug.getinfo(frames)
local info = _debug_getinfo(frames)
if info then
frames = frames + 1
else
@ -477,7 +479,7 @@ function debug.get_traceback(start)
local frames = {}
local n = 2 + (start or 0)
while true do
local info = debug.getinfo(n)
local info = _debug_getinfo(n)
if info then
table.insert(frames, info)
else
@ -567,7 +569,7 @@ end
function require(path)
if not string.find(path, ':') then
local prefix, _ = parse_path(debug.getinfo(2).source)
local prefix, _ = parse_path(_debug_getinfo(2).source)
return require(prefix..':'..path)
end
local prefix, file = parse_path(path)

View File

@ -10,20 +10,19 @@ uniform int u_shadowsRes;
uniform float u_shadowsOpacity;
uniform float u_shadowsSoftness;
float calc_shadow(vec4 modelPos, vec3 realnormal, float distance) {
#ifdef ENABLE_SHADOWS
float calc_shadow(
sampler2DShadow shadowsMap,
mat4 shadowMatrix,
vec4 modelPos,
vec3 realnormal,
vec3 normalOffset,
float bias
) {
float step = 1.0 / float(u_shadowsRes);
float s = pow(abs(cos(u_dayTime * PI2)), 0.25) * u_shadowsOpacity;
vec3 normalOffset = realnormal * (distance > 64.0 ? 0.2 : 0.04);
int shadowIdx = distance > 80.0 ? 1 : 0;
vec4 mpos = u_shadowsMatrix[shadowIdx] * vec4(modelPos.xyz + normalOffset, 1.0);
vec4 mpos = shadowMatrix * vec4(modelPos.xyz + normalOffset, 1.0);
vec3 projCoords = mpos.xyz / mpos.w;
projCoords = projCoords * 0.5 + 0.5;
projCoords.z -= 0.00001 / u_shadowsRes;
if (shadowIdx > 0) {
projCoords.z -= 0.001;
}
projCoords.z -= 0.00001 / u_shadowsRes + bias;
float shadow = 0.0;
if (dot(realnormal, u_sunDir) < 0.0) {
@ -31,13 +30,27 @@ float calc_shadow(vec4 modelPos, vec3 realnormal, float distance) {
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
vec3 offset = vec3(x, y, -(abs(x) + abs(y)) * 0.8) * step * 1.0 * u_shadowsSoftness;
shadow += texture(u_shadows[shadowIdx], projCoords + offset);
shadow += texture(shadowsMap, projCoords + offset);
}
}
shadow /= 9.0;
} else {
shadow = 0.5;
}
return shadow;
}
// TODO: add array textures support
float calc_shadow(vec4 modelPos, vec3 realnormal, float distance) {
#ifdef ENABLE_SHADOWS
float s = pow(abs(cos(u_dayTime * PI2)), 0.25) * u_shadowsOpacity;
vec3 normalOffset = realnormal * (distance > 64.0 ? 0.2 : 0.04);
// as slow as mix(...)
float shadow = (distance < 80.0)
? calc_shadow(u_shadows[0], u_shadowsMatrix[0], modelPos, realnormal, normalOffset, 0.0)
: calc_shadow(u_shadows[1], u_shadowsMatrix[1], modelPos, realnormal, normalOffset, 0.001);
return 0.5 * (1.0 + s * shadow);
#else
return 1.0;

View File

@ -149,7 +149,7 @@ void PrecipitationRenderer::render(
glm::cross(glm::vec3(0, 1, 0), face.right),
FACE_SIZE,
light_at(chunks, pos.x, y, pos.z),
glm::vec3(1.0f),
glm::vec3(2.0f),
calc_uv(pos, face.right, timer, weather)
);
}

View File

@ -58,7 +58,7 @@ struct WeatherPreset : Serializable {
float thunderRate = 0.0f;
/// @brief Weather effects intensity
float intensity = 1.0f;
float intensity = 0.0f;
dv::value serialize() const override;
void deserialize(const dv::value& src) override;