diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/UnstableCloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/UnstableCloudBlock.java index 30bf49c4..b64c03d6 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/UnstableCloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/UnstableCloudBlock.java @@ -2,9 +2,9 @@ package com.minelittlepony.unicopia.block.cloud; import java.util.Optional; -import com.minelittlepony.unicopia.entity.mob.StormCloudEntity; import com.minelittlepony.unicopia.particle.LightningBoltParticleEffect; import com.minelittlepony.unicopia.particle.ParticleUtils; +import com.minelittlepony.unicopia.util.PosHelper; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -82,7 +82,7 @@ public class UnstableCloudBlock extends CloudBlock { ); BlockPos shockPosition = lightningRodPos.or(() -> { return sw.getOtherEntities(entity, new Box(pos.down()).expand(5, 0, 5).stretch(0, -10, 0)).stream().findAny().map(Entity::getBlockPos); - }).orElseGet(() -> StormCloudEntity.findSurfaceBelow(sw, pos.add(world.random.nextInt(10) - 5, -world.random.nextInt(10), world.random.nextInt(10) - 5)).toImmutable()); + }).orElseGet(() -> PosHelper.findNearestSurface(sw, pos.add(world.random.nextInt(10) - 5, -world.random.nextInt(10), world.random.nextInt(10) - 5)).toImmutable()); ParticleUtils.spawnParticle(world, new LightningBoltParticleEffect(false, 10, 6, 0.3F, Optional.of(shockPosition.toCenterPos())), diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/StormCloudEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/StormCloudEntity.java index d7f1054f..6bad71e2 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/StormCloudEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/StormCloudEntity.java @@ -11,6 +11,7 @@ import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.entity.MagicImmune; import com.minelittlepony.unicopia.particle.UParticles; import com.minelittlepony.unicopia.server.world.WeatherConditions; +import com.minelittlepony.unicopia.util.PosHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityStatuses; @@ -38,7 +39,6 @@ import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameRules; @@ -148,7 +148,7 @@ public class StormCloudEntity extends Entity implements MagicImmune { } if (isLogicalSideForUpdatingMovement()) { - float groundY = findSurfaceBelow(getWorld(), getBlockPos()).getY(); + float groundY = PosHelper.findNearestSurface(getWorld(), getBlockPos()).getY(); float targetY = isStormy() ? STORMY_TARGET_ALTITUDE : CLEAR_TARGET_ALTITUDE; float cloudY = (float)getY() - targetY; @@ -271,24 +271,10 @@ public class StormCloudEntity extends Entity implements MagicImmune { private void pickRandomPoints(int count, Consumer action) { BlockPos.iterateRandomly(random, 3, getBlockPos(), getSizeInBlocks()).forEach(pos -> { - action.accept(findSurfaceBelow(getWorld(), pos)); + action.accept(PosHelper.findNearestSurface(getWorld(), pos)); }); } - public static BlockPos findSurfaceBelow(World world, BlockPos pos) { - BlockPos.Mutable mutable = new BlockPos.Mutable(); - mutable.set(pos); - while (mutable.getY() > world.getBottomY() && world.isAir(mutable)) { - mutable.move(Direction.DOWN); - } - while (world.isInBuildLimit(mutable) && !world.isAir(mutable)) { - mutable.move(Direction.UP); - } - mutable.move(Direction.DOWN); - - return mutable; - } - private void spawnLightningStrike(BlockPos pos, boolean cosmetic, boolean infect) { if (infect) { if (!CrystalShardsEntity.infestBlock((ServerWorld)getWorld(), pos)) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java index 2afbc3ca..e86b61c8 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java @@ -7,10 +7,10 @@ import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation; import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation.Recipient; import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck; -import com.minelittlepony.unicopia.entity.mob.StormCloudEntity; import com.minelittlepony.unicopia.network.track.DataTracker; import com.minelittlepony.unicopia.network.track.TrackableDataType; import com.minelittlepony.unicopia.util.NbtSerialisable; +import com.minelittlepony.unicopia.util.PosHelper; import com.minelittlepony.unicopia.util.Tickable; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -51,7 +51,7 @@ public class Acrobatics implements Tickable, NbtSerialisable { if (entity.isCreative() && entity.getAbilities().flying) { return false; } - return pony.getCompositeRace().any(Race::isFish) && !entity.isTouchingWater() && !entity.getWorld().isWater(StormCloudEntity.findSurfaceBelow(entity.getWorld(), entity.getBlockPos())); + return pony.getCompositeRace().any(Race::isFish) && !entity.isTouchingWater() && !entity.getWorld().isWater(PosHelper.findNearestSurface(entity.getWorld(), entity.getBlockPos())); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/FlightStuntUtil.java b/src/main/java/com/minelittlepony/unicopia/entity/player/FlightStuntUtil.java index c5975dbe..9ff96023 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/FlightStuntUtil.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/FlightStuntUtil.java @@ -1,7 +1,7 @@ package com.minelittlepony.unicopia.entity.player; -import com.minelittlepony.unicopia.entity.mob.StormCloudEntity; import com.minelittlepony.unicopia.util.MutableVector; +import com.minelittlepony.unicopia.util.PosHelper; import net.minecraft.util.math.BlockPos; @@ -14,6 +14,6 @@ public class FlightStuntUtil { public static boolean isFlyingLow(Pony pony, MutableVector velocity) { BlockPos pos = pony.asEntity().getBlockPos(); - return velocity.horizontalLengthSquared() > 0.005F && (pos.getY() - StormCloudEntity.findSurfaceBelow(pony.asWorld(), pos).getY()) < 6; + return velocity.horizontalLengthSquared() > 0.005F && (pos.getY() - PosHelper.findNearestSurface(pony.asWorld(), pos).getY()) < 6; } } diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/WeatherConditions.java b/src/main/java/com/minelittlepony/unicopia/server/world/WeatherConditions.java index d392b684..ec505291 100644 --- a/src/main/java/com/minelittlepony/unicopia/server/world/WeatherConditions.java +++ b/src/main/java/com/minelittlepony/unicopia/server/world/WeatherConditions.java @@ -165,6 +165,8 @@ public class WeatherConditions extends PersistentState implements Tickable { final float terrainFactor = getScaledDistanceFromTerrain(probedPosition.set(pos), world, MAX_TERRAIN_HEIGHT); final float windFactor = getScaledDistanceFromTerrain(probedPosition.set(pos), world, MAX_WIND_HEIGHT); + System.out.println(terrainFactor + "/" + windFactor); + Vec3d terrainGradient = LOCAL_ALTITUDE_FIELD.computeAverage(world, pos, probedPosition).multiply(1 - terrainFactor); Vec3d thermalGradient = THERMAL_FIELD.computeAverage(world, pos, probedPosition).multiply(1 - terrainFactor); Vec3d wind = get(world).getWindDirection().multiply(windFactor); @@ -212,7 +214,15 @@ public class WeatherConditions extends PersistentState implements Tickable { } if (state.getFluidState().isIn(FluidTags.WATER)) { - return MeteorlogicalUtil.getSunIntensity(world); + float sunIntensity = MeteorlogicalUtil.getSunIntensity(world); + int depth = 0; + BlockPos.Mutable mutable = pos.mutableCopy(); + while (depth < 15 && world.getFluidState(mutable).isIn(FluidTags.WATER)) { + mutable.move(Direction.DOWN); + depth++; + } + + return sunIntensity * (depth / 15F); } return 0; diff --git a/src/main/java/com/minelittlepony/unicopia/util/PosHelper.java b/src/main/java/com/minelittlepony/unicopia/util/PosHelper.java index f050c796..d7c00444 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/PosHelper.java +++ b/src/main/java/com/minelittlepony/unicopia/util/PosHelper.java @@ -28,6 +28,20 @@ public interface PosHelper { return a.add(b.getX(), b.getY(), b.getZ()); } + static BlockPos findNearestSurface(World world, BlockPos pos) { + BlockPos.Mutable mutable = pos.mutableCopy(); + + while (mutable.getY() > world.getBottomY() && world.isAir(mutable)) { + mutable.move(Direction.DOWN); + } + while (world.isInBuildLimit(mutable) && !world.isAir(mutable)) { + mutable.move(Direction.UP); + } + mutable.move(Direction.DOWN); + + return mutable; + } + static BlockPos findSolidGroundAt(World world, BlockPos pos, int signum) { BlockPos.Mutable mutable = pos.mutableCopy(); while (world.isInBuildLimit(mutable) && (world.isAir(mutable) || !world.getBlockState(mutable).canPlaceAt(world, mutable))) {