Skip to content

Commit

Permalink
Improve snow rendering and fix wind issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Dec 23, 2023
1 parent b98242b commit d370644
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void renderWeather(LightTexture lightTexture, float partialTick, double c
RenderSystem.enableDepthTest();

int layers = 10;
int belowAbove = 5;

int rendering = -1;

Expand All @@ -141,8 +142,8 @@ public void renderWeather(LightTexture lightTexture, float partialTick, double c
if (status != null) {
float precipLevel = status.intensity;
int lowerY = level.getHeight(Heightmap.Types.MOTION_BLOCKING, x, z);
int minY = Math.max(floorY - layers, lowerY);
int maxY = Math.max(floorY + layers, lowerY);
int minY = Math.max(floorY - belowAbove, lowerY);
int maxY = Math.max(floorY + belowAbove, lowerY);

int upperY = Math.max(floorY, lowerY);

Expand All @@ -166,7 +167,12 @@ public void renderWeather(LightTexture lightTexture, float partialTick, double c
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE);
}

float slowVerticalOffset = -((ticks & (512 - 1)) + partialTick) / 512.0F;
//float slowVerticalOffset = -((ticks & (512 - 1)) + partialTick) / 512.0F;
float speed = Mth.clamp(status.speed, 0, 1.25f);
float relSpeed = (speed / 1.25f);
relSpeed = 1 - (1 - relSpeed) * (1 - relSpeed) * (1 - relSpeed) * (1 - relSpeed);
float slowFactor = 512F * (1 - relSpeed) + 32F * relSpeed;
float slowVerticalOffset = -((ticks & (512 - 1)) + partialTick) / slowFactor;
float randomizingOffset = (float) (randomsource.nextDouble() + (time * randomsource.nextGaussian()) * 0.001);
int offsetTicks = ticks + hash & 31;
float fastVerticalOffset = -(offsetTicks + partialTick) / 32.0F * (3.0F + randomsource.nextFloat());
Expand All @@ -178,7 +184,7 @@ public void renderWeather(LightTexture lightTexture, float partialTick, double c

Matrix4f quadRotate = new Matrix4f();
quadRotate.translate((float) (x - camX + 0.5), (float) (minY - camY), (float) (z - camZ + 0.5));
quadRotate.rotate(Mth.clamp(status.speed, 0, 1.25f), -status.windZ, 0, status.windX);
quadRotate.rotate(speed, -status.windZ, 0, status.windX);
quadRotate.translate((float) -(x - camX + 0.5), (float) -(minY - camY), (float) -(z - camZ + 0.5));

float movement = swirlMovement * status.swirl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,24 @@ public abstract class LivingEntityMixin extends Entity {
)
)
private void tempest$wrapDeltaMovement(LivingEntity livingEntity, double dx, double dy, double dz, Operation<Void> operation) {
//noinspection ConstantValue
if (!((Object) this instanceof Player player) || (!player.isSpectator() && (!player.isCreative() || !player.getAbilities().flying))) {
//noinspection DataFlowIssue
if (!((LivingEntity) (Object) this).shouldDiscardFriction()) {
if (this.onGround()) {
var pos = this.getBlockPosBelowThatAffectsMyMovement();
//noinspection resource
var weatherData = Services.PLATFORM.getChunkData(this.level().getChunkAt(pos)).query(pos);
int blackIce = weatherData.blackIce();
if (blackIce != 0) {
var unscaledDx = dx / 0.91f;
var unscaledDz = dz / 0.91f;
//noinspection DataFlowIssue
if (!((LivingEntity) (Object) this).shouldDiscardFriction()) {
if (this.onGround()) {
var pos = this.getBlockPosBelowThatAffectsMyMovement();
//noinspection resource
var weatherData = Services.PLATFORM.getChunkData(this.level().getChunkAt(pos)).query(pos);
int blackIce = weatherData.blackIce();
if (blackIce != 0) {
var unscaledDx = dx / 0.91f;
var unscaledDz = dz / 0.91f;

var degree = 1 - (blackIce / 15f);
degree = degree * degree;
var degree = 1 - (blackIce / 15f);
degree = degree * degree;

var newDx = degree * dx + (1 - degree) * unscaledDx;
var newDz = degree * dz + (1 - degree) * unscaledDz;
operation.call(livingEntity, newDx, dy, newDz);
return;
}
var newDx = degree * dx + (1 - degree) * unscaledDx;
var newDz = degree * dz + (1 - degree) * unscaledDz;
operation.call(livingEntity, newDx, dy, newDz);
return;
}
}
}
Expand Down Expand Up @@ -91,13 +88,16 @@ public abstract class LivingEntityMixin extends Entity {
}
}
if (status != null && status.speed > 0.75) {
if (!this.onGround() || status.speed > 1) {
var cDelta = this.getDeltaMovement();
var windDelta = new Vec3(status.windX, 0, status.windZ);
double inDirection = cDelta.dot(windDelta);
if (inDirection < status.speed) {
double mult = (status.speed*0.25 - inDirection) * 0.1;
this.setDeltaMovement(cDelta.add(windDelta.scale(mult)));
//noinspection ConstantValue
if (!((Object) this instanceof Player player) || (!player.isSpectator() && (!player.isCreative() || !player.getAbilities().flying))) {
if (!this.onGround() || status.speed > 1) {
var cDelta = this.getDeltaMovement();
var windDelta = new Vec3(status.windX, 0, status.windZ);
double inDirection = cDelta.dot(windDelta);
if (inDirection < status.speed) {
double mult = (status.speed * 0.25 - inDirection) * 0.1;
this.setDeltaMovement(cDelta.add(windDelta.scale(mult)));
}
}
}
}
Expand Down

0 comments on commit d370644

Please sign in to comment.