mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Account for the water's depth when determining the amount of lift pegasi should receive
This commit is contained in:
parent
66d0dc8750
commit
aaea2bfbc1
6 changed files with 34 additions and 24 deletions
|
@ -2,9 +2,9 @@ package com.minelittlepony.unicopia.block.cloud;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.entity.mob.StormCloudEntity;
|
|
||||||
import com.minelittlepony.unicopia.particle.LightningBoltParticleEffect;
|
import com.minelittlepony.unicopia.particle.LightningBoltParticleEffect;
|
||||||
import com.minelittlepony.unicopia.particle.ParticleUtils;
|
import com.minelittlepony.unicopia.particle.ParticleUtils;
|
||||||
|
import com.minelittlepony.unicopia.util.PosHelper;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
@ -82,7 +82,7 @@ public class UnstableCloudBlock extends CloudBlock {
|
||||||
);
|
);
|
||||||
BlockPos shockPosition = lightningRodPos.or(() -> {
|
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);
|
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,
|
ParticleUtils.spawnParticle(world,
|
||||||
new LightningBoltParticleEffect(false, 10, 6, 0.3F, Optional.of(shockPosition.toCenterPos())),
|
new LightningBoltParticleEffect(false, 10, 6, 0.3F, Optional.of(shockPosition.toCenterPos())),
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.minelittlepony.unicopia.USounds;
|
||||||
import com.minelittlepony.unicopia.entity.MagicImmune;
|
import com.minelittlepony.unicopia.entity.MagicImmune;
|
||||||
import com.minelittlepony.unicopia.particle.UParticles;
|
import com.minelittlepony.unicopia.particle.UParticles;
|
||||||
import com.minelittlepony.unicopia.server.world.WeatherConditions;
|
import com.minelittlepony.unicopia.server.world.WeatherConditions;
|
||||||
|
import com.minelittlepony.unicopia.util.PosHelper;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityStatuses;
|
import net.minecraft.entity.EntityStatuses;
|
||||||
|
@ -38,7 +39,6 @@ import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.GameRules;
|
import net.minecraft.world.GameRules;
|
||||||
|
@ -148,7 +148,7 @@ public class StormCloudEntity extends Entity implements MagicImmune {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLogicalSideForUpdatingMovement()) {
|
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 targetY = isStormy() ? STORMY_TARGET_ALTITUDE : CLEAR_TARGET_ALTITUDE;
|
||||||
float cloudY = (float)getY() - targetY;
|
float cloudY = (float)getY() - targetY;
|
||||||
|
|
||||||
|
@ -271,24 +271,10 @@ public class StormCloudEntity extends Entity implements MagicImmune {
|
||||||
|
|
||||||
private void pickRandomPoints(int count, Consumer<BlockPos> action) {
|
private void pickRandomPoints(int count, Consumer<BlockPos> action) {
|
||||||
BlockPos.iterateRandomly(random, 3, getBlockPos(), getSizeInBlocks()).forEach(pos -> {
|
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) {
|
private void spawnLightningStrike(BlockPos pos, boolean cosmetic, boolean infect) {
|
||||||
if (infect) {
|
if (infect) {
|
||||||
if (!CrystalShardsEntity.infestBlock((ServerWorld)getWorld(), pos)) {
|
if (!CrystalShardsEntity.infestBlock((ServerWorld)getWorld(), pos)) {
|
||||||
|
|
|
@ -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;
|
||||||
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation.Recipient;
|
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation.Recipient;
|
||||||
import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck;
|
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.DataTracker;
|
||||||
import com.minelittlepony.unicopia.network.track.TrackableDataType;
|
import com.minelittlepony.unicopia.network.track.TrackableDataType;
|
||||||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||||
|
import com.minelittlepony.unicopia.util.PosHelper;
|
||||||
import com.minelittlepony.unicopia.util.Tickable;
|
import com.minelittlepony.unicopia.util.Tickable;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
|
@ -51,7 +51,7 @@ public class Acrobatics implements Tickable, NbtSerialisable {
|
||||||
if (entity.isCreative() && entity.getAbilities().flying) {
|
if (entity.isCreative() && entity.getAbilities().flying) {
|
||||||
return false;
|
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
|
@Override
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.minelittlepony.unicopia.entity.player;
|
package com.minelittlepony.unicopia.entity.player;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.entity.mob.StormCloudEntity;
|
|
||||||
import com.minelittlepony.unicopia.util.MutableVector;
|
import com.minelittlepony.unicopia.util.MutableVector;
|
||||||
|
import com.minelittlepony.unicopia.util.PosHelper;
|
||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
@ -14,6 +14,6 @@ public class FlightStuntUtil {
|
||||||
|
|
||||||
public static boolean isFlyingLow(Pony pony, MutableVector velocity) {
|
public static boolean isFlyingLow(Pony pony, MutableVector velocity) {
|
||||||
BlockPos pos = pony.asEntity().getBlockPos();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,6 +165,8 @@ public class WeatherConditions extends PersistentState implements Tickable {
|
||||||
final float terrainFactor = getScaledDistanceFromTerrain(probedPosition.set(pos), world, MAX_TERRAIN_HEIGHT);
|
final float terrainFactor = getScaledDistanceFromTerrain(probedPosition.set(pos), world, MAX_TERRAIN_HEIGHT);
|
||||||
final float windFactor = getScaledDistanceFromTerrain(probedPosition.set(pos), world, MAX_WIND_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 terrainGradient = LOCAL_ALTITUDE_FIELD.computeAverage(world, pos, probedPosition).multiply(1 - terrainFactor);
|
||||||
Vec3d thermalGradient = THERMAL_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);
|
Vec3d wind = get(world).getWindDirection().multiply(windFactor);
|
||||||
|
@ -212,7 +214,15 @@ public class WeatherConditions extends PersistentState implements Tickable {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.getFluidState().isIn(FluidTags.WATER)) {
|
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;
|
return 0;
|
||||||
|
|
|
@ -28,6 +28,20 @@ public interface PosHelper {
|
||||||
return a.add(b.getX(), b.getY(), b.getZ());
|
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) {
|
static BlockPos findSolidGroundAt(World world, BlockPos pos, int signum) {
|
||||||
BlockPos.Mutable mutable = pos.mutableCopy();
|
BlockPos.Mutable mutable = pos.mutableCopy();
|
||||||
while (world.isInBuildLimit(mutable) && (world.isAir(mutable) || !world.getBlockState(mutable).canPlaceAt(world, mutable))) {
|
while (world.isInBuildLimit(mutable) && (world.isAir(mutable) || !world.getBlockState(mutable).canPlaceAt(world, mutable))) {
|
||||||
|
|
Loading…
Reference in a new issue