Skip to content

Commit

Permalink
Wind avoids flying creative players and snow has a limit
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Dec 23, 2023
1 parent d7965a4 commit e5d430b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,9 @@ private boolean tryFreezeBlock(ServerLevel level, BlockPos toFreeze) {
level.setBlockAndUpdate(toSnow, newState);
Block.pushEntitiesUp(state, newState, level, toSnow);
} else if (state.canBeReplaced() && Blocks.SNOW.defaultBlockState().canSurvive(level, toSnow)) {
level.setBlockAndUpdate(toSnow, Blocks.SNOW.defaultBlockState());
if (hasSpaceForSnow(level, toSnow)) {
level.setBlockAndUpdate(toSnow, Blocks.SNOW.defaultBlockState());
}
}
return level.random.nextFloat() < precip;
}
Expand All @@ -397,6 +399,20 @@ private boolean tryFreezeBlock(ServerLevel level, BlockPos toFreeze) {
return level.random.nextFloat() < (level.random.nextBoolean() ? -temp : precip);
}

private static boolean hasSpaceForSnow(ServerLevel level, BlockPos pos) {
for (int i = 0; i < 4; i++) {
pos = pos.below();
if (!validBlock(level, pos)) {
return true;
}
var block = level.getBlockState(pos).getBlock();
if (block != Blocks.SNOW_BLOCK && block != Blocks.POWDER_SNOW) {
return true;
}
}
return false;
}

private static boolean tryHailBreak(ServerLevel level, BlockPos toFreeze) {
var hailEffectState = level.getBlockState(toFreeze);
if (hailEffectState.is(Constants.BREAKS_WITH_HAIL) && !hailEffectState.is(Constants.SAFE_WITH_HAIL)) {
Expand Down Expand Up @@ -520,7 +536,7 @@ private boolean shouldFreeze(ServerLevel level, BlockPos toFreeze) {
return level.getBrightness(LightLayer.BLOCK, toFreeze) < 10;
}

private boolean validBlock(ServerLevel level, BlockPos toFreeze) {
private static boolean validBlock(ServerLevel level, BlockPos toFreeze) {
return toFreeze.getY() >= level.getMinBuildHeight() && toFreeze.getY() < level.getMaxBuildHeight();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,27 @@ public abstract class LivingEntityMixin extends Entity {
)
)
private void tempest$wrapDeltaMovement(LivingEntity livingEntity, double dx, double dy, double dz, Operation<Void> operation) {
//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 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;

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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"id": "#c:buds",
"required": false
},
"minecraft:small_amethyst_bud",
"minecraft:medium_amethyst_bud",
"minecraft:large_amethyst_bud",
"minecraft:amethyst_cluster",
"#minecraft:small_flowers",
"#minecraft:saplings",
"#minecraft:crops",
Expand Down

0 comments on commit e5d430b

Please sign in to comment.