mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Rewrite turbulance to be more forgiving for short flights
This commit is contained in:
parent
f3816d06b4
commit
97807d0ec1
3 changed files with 67 additions and 32 deletions
|
@ -9,6 +9,7 @@ import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.registry.tag.BlockTags;
|
import net.minecraft.registry.tag.BlockTags;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.*;
|
import net.minecraft.util.math.*;
|
||||||
|
import net.minecraft.util.math.random.Random;
|
||||||
import net.minecraft.world.Heightmap.Type;
|
import net.minecraft.world.Heightmap.Type;
|
||||||
import net.minecraft.world.PersistentState;
|
import net.minecraft.world.PersistentState;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -115,7 +116,12 @@ public class WeatherConditions extends PersistentState implements Tickable {
|
||||||
Vec3d thermalGradient = THERMAL_FIELD.computeAverage(world, pos, probedPosition).multiply(terrainFactor);
|
Vec3d thermalGradient = THERMAL_FIELD.computeAverage(world, pos, probedPosition).multiply(terrainFactor);
|
||||||
Vec3d wind = get(world).getWindDirection().multiply(1 - windFactor);
|
Vec3d wind = get(world).getWindDirection().multiply(1 - windFactor);
|
||||||
|
|
||||||
return terrainGradient.add(thermalGradient).add(wind).normalize().add(0, getUpdraft(probedPosition.set(pos), world), 0);
|
return terrainGradient
|
||||||
|
.add(thermalGradient)
|
||||||
|
.add(wind)
|
||||||
|
.normalize()
|
||||||
|
.add(0, getUpdraft(probedPosition.set(pos), world), 0)
|
||||||
|
.multiply(localAltitude / MAX_WIND_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getUpdraft(BlockPos.Mutable pos, World world) {
|
public static double getUpdraft(BlockPos.Mutable pos, World world) {
|
||||||
|
@ -148,6 +154,34 @@ public class WeatherConditions extends PersistentState implements Tickable {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Vec3d getGustStrength(World world, BlockPos pos) {
|
||||||
|
Random random = getPositionalRandom(world, pos);
|
||||||
|
float strength = 0.015F * random.nextFloat();
|
||||||
|
|
||||||
|
if (random.nextInt(30) == 0) {
|
||||||
|
strength *= 10;
|
||||||
|
}
|
||||||
|
if (random.nextInt(30) == 0) {
|
||||||
|
strength *= 10;
|
||||||
|
}
|
||||||
|
if (random.nextInt(40) == 0) {
|
||||||
|
strength *= 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
strength = Math.min(strength, 7);
|
||||||
|
|
||||||
|
float pitch = (180 * random.nextFloat()) - 90;
|
||||||
|
float yaw = (180 * random.nextFloat()) - 90;
|
||||||
|
|
||||||
|
return new Vec3d(strength * world.getRainGradient(1), pitch, yaw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Random getPositionalRandom(World world, BlockPos pos) {
|
||||||
|
long posLong = ChunkPos.toLong(pos);
|
||||||
|
long time = world.getTime();
|
||||||
|
return Random.create(posLong + time);
|
||||||
|
}
|
||||||
|
|
||||||
private static int getSurfaceBelow(BlockPos.Mutable pos, World world) {
|
private static int getSurfaceBelow(BlockPos.Mutable pos, World world) {
|
||||||
do {
|
do {
|
||||||
pos.move(Direction.DOWN);
|
pos.move(Direction.DOWN);
|
||||||
|
|
|
@ -32,13 +32,14 @@ import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
import net.minecraft.particle.ParticleTypes;
|
||||||
import net.minecraft.sound.SoundCategory;
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.math.*;
|
import net.minecraft.util.math.*;
|
||||||
import net.minecraft.util.math.random.Random;
|
|
||||||
import net.minecraft.world.event.GameEvent;
|
import net.minecraft.world.event.GameEvent;
|
||||||
|
|
||||||
public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickable, Motion, NbtSerialisable {
|
public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickable, Motion, NbtSerialisable {
|
||||||
private static final int MAX_WALL_HIT_CALLDOWN = 30;
|
private static final int MAX_WALL_HIT_CALLDOWN = 30;
|
||||||
private static final int MAX_TICKS_TO_GLIDE = 20;
|
private static final int MAX_TICKS_TO_GLIDE = 20;
|
||||||
|
private static final int MAX_TICKS_TO_WEATHER_EFFECTS = 100;
|
||||||
private static final int IDLE_FLAP_INTERVAL = 20;
|
private static final int IDLE_FLAP_INTERVAL = 20;
|
||||||
private static final int GLIDING_SOUND_INTERVAL = 200;
|
private static final int GLIDING_SOUND_INTERVAL = 200;
|
||||||
|
|
||||||
|
@ -564,42 +565,24 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyTurbulance(MutableVector velocity) {
|
private void applyTurbulance(MutableVector velocity) {
|
||||||
|
float effectStrength = Math.min(1, (float)ticksInAir / MAX_TICKS_TO_WEATHER_EFFECTS);
|
||||||
|
Vec3d gust = WeatherConditions.getGustStrength(entity.world, entity.getBlockPos());
|
||||||
|
|
||||||
Vec3d wind = WeatherConditions.getAirflow(entity.getBlockPos(), entity.world).multiply(0.04);
|
if (effectStrength * gust.getX() >= 1) {
|
||||||
velocity.x += wind.x;
|
|
||||||
velocity.y += wind.y;
|
|
||||||
velocity.z += wind.z;
|
|
||||||
|
|
||||||
Random rng = Random.create(entity.world.getTime());
|
|
||||||
|
|
||||||
float glance = 360 * rng.nextFloat();
|
|
||||||
float forward = 0.015F * rng.nextFloat() * entity.world.getRainGradient(1);
|
|
||||||
|
|
||||||
if (entity.world.random.nextInt(30) == 0) {
|
|
||||||
forward *= 10;
|
|
||||||
}
|
|
||||||
if (entity.world.random.nextInt(30) == 0) {
|
|
||||||
forward *= 10;
|
|
||||||
}
|
|
||||||
if (entity.world.random.nextInt(40) == 0) {
|
|
||||||
forward *= 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity.world.isThundering() && rng.nextInt(60) == 0) {
|
|
||||||
velocity.y += forward * 3 * getGravitySignum();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (forward >= 1) {
|
|
||||||
SoundEmitter.playSoundAt(entity, USounds.AMBIENT_WIND_GUST, SoundCategory.AMBIENT, 3, 1);
|
SoundEmitter.playSoundAt(entity, USounds.AMBIENT_WIND_GUST, SoundCategory.AMBIENT, 3, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
forward = Math.min(forward, 7);
|
float weight = 1 + (EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, entity) * 0.8F) + (pony.getActualSpecies().canUseEarth() ? 1 : 0);
|
||||||
forward /= 1 + (EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, entity) * 0.8F);
|
|
||||||
|
|
||||||
velocity.x += - forward * MathHelper.sin((entity.getYaw() + glance) * 0.017453292F);
|
velocity.add(WeatherConditions.getAirflow(entity.getBlockPos(), entity.world), 0.04F * effectStrength);
|
||||||
velocity.z += forward * MathHelper.cos((entity.getYaw() + glance) * 0.017453292F);
|
velocity.add(Vec3d.fromPolar(
|
||||||
|
(entity.getPitch() + (float)gust.getY()) * MathHelper.RADIANS_PER_DEGREE,
|
||||||
|
(entity.getYaw() + (float)gust.getZ()) * MathHelper.RADIANS_PER_DEGREE
|
||||||
|
),
|
||||||
|
effectStrength * (float)gust.getX() / weight
|
||||||
|
);
|
||||||
|
|
||||||
if (!entity.world.isClient && entity.world.isThundering() && entity.world.random.nextInt(9000) == 0) {
|
if (!entity.world.isClient && effectStrength > 0.9F && entity.world.isThundering() && entity.world.random.nextInt(9000) == 0) {
|
||||||
LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(entity.world);
|
LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(entity.world);
|
||||||
lightning.refreshPositionAfterTeleport(entity.getX(), entity.getY(), entity.getZ());
|
lightning.refreshPositionAfterTeleport(entity.getX(), entity.getY(), entity.getZ());
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,24 @@ public class MutableVector {
|
||||||
z = vec.z;
|
z = vec.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void add(Vec3d vector) {
|
||||||
|
add(vector.x, vector.y, vector.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Vec3d vector, float scale) {
|
||||||
|
add(vector.x, vector.y, vector.z, scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(double x, double y, double z, float scale) {
|
||||||
|
add(x * scale, y * scale, z * scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(double x, double y, double z) {
|
||||||
|
this.x += x;
|
||||||
|
this.y += y;
|
||||||
|
this.z += z;
|
||||||
|
}
|
||||||
|
|
||||||
public Vec3d toImmutable() {
|
public Vec3d toImmutable() {
|
||||||
return new Vec3d(x, y, z);
|
return new Vec3d(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue