2018-09-16 00:45:44 +02:00
|
|
|
package com.minelittlepony.unicopia.entity;
|
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.IEntityLivingData;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2019-01-29 15:23:42 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-09-16 00:45:44 +02:00
|
|
|
import net.minecraft.world.DifficultyInstance;
|
|
|
|
import net.minecraft.world.World;
|
2019-01-29 14:22:36 +01:00
|
|
|
import net.minecraft.world.biome.Biome.SpawnListEntry;
|
2018-09-16 00:45:44 +02:00
|
|
|
|
|
|
|
public class EntityWildCloud extends EntityCloud {
|
|
|
|
|
2019-01-29 15:23:42 +01:00
|
|
|
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, 1, 1, 2);
|
2019-01-29 14:22:36 +01:00
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
public EntityWildCloud(World world) {
|
|
|
|
super(world);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isNotColliding() {
|
|
|
|
AxisAlignedBB boundingbox = getEntityBoundingBox();
|
|
|
|
return checkNoEntityCollision(boundingbox, this) && world.getCollisionBoxes(this, boundingbox).isEmpty() && !world.containsAnyLiquid(boundingbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if there are no solid, live entities in the specified AxisAlignedBB, excluding the given entity
|
|
|
|
*
|
|
|
|
* @ref World.checkNoEntityCollision(AxisAlignedBB area, Entity entity)
|
|
|
|
*/
|
|
|
|
public boolean checkNoEntityCollision(AxisAlignedBB area, Entity entity) {
|
2019-01-29 15:23:42 +01:00
|
|
|
|
|
|
|
for (Entity i : world.getEntitiesWithinAABBExcludingEntity(entity, area)) {
|
|
|
|
if (!i.isDead && (i.preventEntitySpawning || i instanceof EntityCloud) && (!entity.isRiding() || !entity.isRidingOrBeingRiddenBy(i))) {
|
2018-09-16 00:45:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-29 15:23:42 +01:00
|
|
|
@Override
|
|
|
|
public boolean getCanSpawnHere() {
|
|
|
|
BlockPos pos = new BlockPos(this).down();
|
|
|
|
|
|
|
|
return world.getBlockState(pos).canEntitySpawn(this);
|
|
|
|
}
|
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
@Override
|
|
|
|
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) {
|
2019-01-29 15:23:42 +01:00
|
|
|
float minSpawnHeight = getMinimumFlyingHeight();
|
|
|
|
|
|
|
|
altitude = getRandomFlyingHeight();
|
2019-01-29 14:22:36 +01:00
|
|
|
|
|
|
|
if (posY < minSpawnHeight) {
|
2019-01-29 15:23:42 +01:00
|
|
|
minSpawnHeight += world.rand.nextInt(Math.max(1, (int)getMaximumFlyingHeight() - (int)minSpawnHeight));
|
2019-01-29 14:22:36 +01:00
|
|
|
|
|
|
|
setLocationAndAngles(posX, minSpawnHeight - 1, posZ, rotationYaw, rotationPitch);
|
|
|
|
collideWithNearbyEntities();
|
|
|
|
}
|
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
return super.onInitialSpawn(difficulty, livingdata);
|
|
|
|
}
|
|
|
|
}
|