Fixed cloud movement

This commit is contained in:
Sollace 2019-01-29 16:23:42 +02:00
parent f90d6ae480
commit b5e7bf673d
2 changed files with 79 additions and 40 deletions

View file

@ -9,6 +9,7 @@ import com.minelittlepony.unicopia.UItems;
import com.minelittlepony.unicopia.UParticles; import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.particle.Particles; import com.minelittlepony.unicopia.particle.Particles;
import com.minelittlepony.unicopia.player.PlayerSpeciesList; import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import net.minecraft.block.BlockCrops; import net.minecraft.block.BlockCrops;
import net.minecraft.block.BlockFarmland; import net.minecraft.block.BlockFarmland;
import net.minecraft.block.BlockFire; import net.minecraft.block.BlockFire;
@ -22,6 +23,7 @@ import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityFlying; import net.minecraft.entity.EntityFlying;
import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityList;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.IAnimals; import net.minecraft.entity.passive.IAnimals;
@ -51,36 +53,27 @@ import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World; import net.minecraft.world.World;
public class EntityCloud extends EntityFlying implements IAnimals { public class EntityCloud extends EntityFlying implements IAnimals {
private double altitude;
private final double baseWidth = 3f;
private final double baseHeight = 0.8f;
public EntityCloud(World world) {
super(world);
preventEntitySpawning = false;
ignoreFrustumCheck = true;
if (world.rand.nextInt(20) == 0 && canRainHere()) {
setRaining();
if (world.rand.nextInt(20) == 0) {
setIsThundering(true);
}
}
setCloudSize(1 + rand.nextInt(3));
}
private static final DataParameter<Integer> RAINTIMER = EntityDataManager.createKey(EntityCloud.class, DataSerializers.VARINT); private static final DataParameter<Integer> RAINTIMER = EntityDataManager.createKey(EntityCloud.class, DataSerializers.VARINT);
private static final DataParameter<Boolean> THUNDERING = EntityDataManager.createKey(EntityCloud.class, DataSerializers.BOOLEAN); private static final DataParameter<Boolean> THUNDERING = EntityDataManager.createKey(EntityCloud.class, DataSerializers.BOOLEAN);
private static final DataParameter<Integer> SCALE = EntityDataManager.createKey(EntityCloud.class, DataSerializers.VARINT); private static final DataParameter<Integer> SCALE = EntityDataManager.createKey(EntityCloud.class, DataSerializers.VARINT);
private static final DataParameter<Boolean> STATIONARY = EntityDataManager.createKey(EntityCloud.class, DataSerializers.BOOLEAN); private static final DataParameter<Boolean> STATIONARY = EntityDataManager.createKey(EntityCloud.class, DataSerializers.BOOLEAN);
protected double altitude;
private final double baseWidth = 3f;
private final double baseHeight = 0.8f;
public EntityCloud(World world) {
super(world);
ignoreFrustumCheck = true;
}
@Override @Override
protected void entityInit() { protected void entityInit() {
super.entityInit(); super.entityInit();
@ -122,7 +115,7 @@ public class EntityCloud extends EntityFlying implements IAnimals {
@Override @Override
public int getBrightnessForRender() { public int getBrightnessForRender() {
return 15728640; return 0xF00000;
} }
@Override @Override
@ -140,6 +133,20 @@ public class EntityCloud extends EntityFlying implements IAnimals {
} }
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) {
if (world.rand.nextInt(20) == 0 && canRainHere()) {
setRaining();
if (world.rand.nextInt(20) == 0) {
setIsThundering(true);
}
}
setCloudSize(1 + rand.nextInt(4));
return super.onInitialSpawn(difficulty, livingdata);
}
@Override @Override
protected void collideWithEntity(Entity other) { protected void collideWithEntity(Entity other) {
if (other instanceof EntityCloud) { if (other instanceof EntityCloud) {
@ -322,26 +329,50 @@ public class EntityCloud extends EntityFlying implements IAnimals {
protected void updateAITasks() { protected void updateAITasks() {
if (!getStationary()) { if (!getStationary()) {
super.updateAITasks(); super.updateAITasks();
if (!isBeingRidden()) { if (!isBeingRidden()) {
double diffY = altitude - posZ; double distance = altitude - posY;
if (rand.nextInt(700) == 0 || diffY*diffY < 3f) { if (Math.abs(distance) < 1 && rand.nextInt(7000) == 0) {
altitude += rand.nextInt(10) - 5; altitude = getRandomFlyingHeight();
distance = altitude - posY;
} }
if (altitude > world.provider.getCloudHeight() - 8) { if (distance < 1) {
altitude = world.provider.getCloudHeight() - 18; distance = 0;
} else if (altitude < 70) {
altitude = posY + 10;
} }
double var3 = altitude + 0.1D - posY; motionX -= 0.01;
motionX -= 0.001; motionZ -= (Math.signum(distance) * 0.699999988079071D - motionZ) * 0.10000000149011612D;
motionY += (Math.signum(var3) * 0.699999988079071D - motionY) * 0.10000000149011612D; motionY += (Math.signum(distance) * 0.699999988079071D - motionY) * 0.10000000149011612D;
} }
} }
} }
protected float getRandomFlyingHeight() {
float a = getMaximumFlyingHeight();
float b = getMinimumFlyingHeight();
float min = Math.min(a, b);
float max = Math.max(a, b);
return min + world.rand.nextFloat() * (max - min);
}
protected float getMinimumFlyingHeight() {
float ground = world.provider.getAverageGroundLevel();
float cloud = world.provider.getCloudHeight();
float min = Math.min(ground, cloud);
float max = Math.max(ground, cloud);
return min + (max - min)/2;
}
protected float getMaximumFlyingHeight() {
return world.provider.getActualHeight() - 5;
}
@Override @Override
public EnumActionResult applyPlayerInteraction(EntityPlayer player, Vec3d vec, EnumHand hand) { public EnumActionResult applyPlayerInteraction(EntityPlayer player, Vec3d vec, EnumHand hand) {
if (!(isBeingRidden() || isRidingOrBeingRiddenBy(player)) && hand == EnumHand.MAIN_HAND) { if (!(isBeingRidden() || isRidingOrBeingRiddenBy(player)) && hand == EnumHand.MAIN_HAND) {

View file

@ -1,18 +1,17 @@
package com.minelittlepony.unicopia.entity; package com.minelittlepony.unicopia.entity;
import java.util.List;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.IEntityLivingData;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.DifficultyInstance; import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.biome.Biome.SpawnListEntry; import net.minecraft.world.biome.Biome.SpawnListEntry;
public class EntityWildCloud extends EntityCloud { public class EntityWildCloud extends EntityCloud {
public static final SpawnListEntry SPAWN_ENTRY_LAND = new SpawnListEntry(EntityWildCloud.class, 3, 2, 5); public static final SpawnListEntry SPAWN_ENTRY_LAND = new SpawnListEntry(EntityWildCloud.class, 1, 1, 3);
public static final SpawnListEntry SPAWN_ENTRY_OCEAN = new SpawnListEntry(EntityWildCloud.class, 3, 1, 2); public static final SpawnListEntry SPAWN_ENTRY_OCEAN = new SpawnListEntry(EntityWildCloud.class, 1, 1, 2);
public EntityWildCloud(World world) { public EntityWildCloud(World world) {
super(world); super(world);
@ -30,21 +29,30 @@ public class EntityWildCloud extends EntityCloud {
* @ref World.checkNoEntityCollision(AxisAlignedBB area, Entity entity) * @ref World.checkNoEntityCollision(AxisAlignedBB area, Entity entity)
*/ */
public boolean checkNoEntityCollision(AxisAlignedBB area, Entity entity) { public boolean checkNoEntityCollision(AxisAlignedBB area, Entity entity) {
List<Entity> list = world.getEntitiesWithinAABBExcludingEntity(null, area);
for (Entity i : list) { for (Entity i : world.getEntitiesWithinAABBExcludingEntity(entity, area)) {
if (!i.isDead && (i.preventEntitySpawning || i instanceof EntityCloud) && i != entity && (!entity.isRiding() || !entity.isRidingOrBeingRiddenBy(i))) { if (!i.isDead && (i.preventEntitySpawning || i instanceof EntityCloud) && (!entity.isRiding() || !entity.isRidingOrBeingRiddenBy(i))) {
return false; return false;
} }
} }
return true; return true;
} }
@Override
public boolean getCanSpawnHere() {
BlockPos pos = new BlockPos(this).down();
return world.getBlockState(pos).canEntitySpawn(this);
}
@Override @Override
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) { public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) {
float minSpawnHeight = world.provider.getAverageGroundLevel() + 18; float minSpawnHeight = getMinimumFlyingHeight();
altitude = getRandomFlyingHeight();
if (posY < minSpawnHeight) { if (posY < minSpawnHeight) {
minSpawnHeight += world.rand.nextInt(Math.max(1, world.provider.getActualHeight() - (int)minSpawnHeight)); minSpawnHeight += world.rand.nextInt(Math.max(1, (int)getMaximumFlyingHeight() - (int)minSpawnHeight));
setLocationAndAngles(posX, minSpawnHeight - 1, posZ, rotationYaw, rotationPitch); setLocationAndAngles(posX, minSpawnHeight - 1, posZ, rotationYaw, rotationPitch);
collideWithNearbyEntities(); collideWithNearbyEntities();