2019-02-04 14:25:12 +01:00
|
|
|
package com.minelittlepony.unicopia.entity;
|
|
|
|
|
2019-02-12 15:33:51 +01:00
|
|
|
import com.minelittlepony.unicopia.Race;
|
|
|
|
|
2019-02-16 20:30:19 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
2019-02-04 14:25:12 +01:00
|
|
|
import net.minecraft.entity.EntityLiving;
|
|
|
|
import net.minecraft.entity.effect.EntityWeatherEffect;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.util.SoundCategory;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.biome.Biome.SpawnListEntry;
|
|
|
|
|
2019-02-12 15:33:51 +01:00
|
|
|
public class EntityRainbow extends EntityWeatherEffect implements IInAnimate {
|
2019-02-04 14:25:12 +01:00
|
|
|
|
|
|
|
public static final SpawnListEntry SPAWN_ENTRY = new SpawnListEntry(EntityRainbow.Spawner.class, 1, 1, 1);
|
|
|
|
|
|
|
|
private int ticksAlive;
|
|
|
|
|
|
|
|
private double radius;
|
|
|
|
|
|
|
|
public static final int RAINBOW_MAX_SIZE = 180;
|
|
|
|
public static final int RAINBOW_MIN_SIZE = 50;
|
|
|
|
|
2019-02-16 20:30:19 +01:00
|
|
|
public static final AxisAlignedBB SPAWN_COLLISSION_RADIUS = new AxisAlignedBB(
|
|
|
|
-RAINBOW_MAX_SIZE, -RAINBOW_MAX_SIZE, -RAINBOW_MAX_SIZE,
|
|
|
|
RAINBOW_MAX_SIZE, RAINBOW_MAX_SIZE, RAINBOW_MAX_SIZE
|
|
|
|
).grow(RAINBOW_MAX_SIZE);
|
|
|
|
|
2019-02-04 14:25:12 +01:00
|
|
|
public EntityRainbow(World world) {
|
|
|
|
this(world, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityRainbow(World world, double x, double y, double z) {
|
|
|
|
super(world);
|
|
|
|
|
|
|
|
float yaw = (int)MathHelper.nextDouble((world == null ? rand : world.rand), 0, 360);
|
|
|
|
|
|
|
|
setLocationAndAngles(x, y, z, yaw, 0);
|
|
|
|
|
|
|
|
radius = MathHelper.nextDouble(world == null ? rand : world.rand, RAINBOW_MIN_SIZE, RAINBOW_MAX_SIZE);
|
|
|
|
ticksAlive = 10000;
|
|
|
|
|
|
|
|
ignoreFrustumCheck = true;
|
|
|
|
|
|
|
|
width = (float)radius;
|
|
|
|
height = width;
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:14:22 +01:00
|
|
|
@Override
|
|
|
|
public boolean shouldRenderInPass(int pass) {
|
|
|
|
return pass == 1;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:33:51 +01:00
|
|
|
@Override
|
|
|
|
public boolean canInteract(Race race) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-04 14:25:12 +01:00
|
|
|
@Override
|
|
|
|
public void setPosition(double x, double y, double z) {
|
|
|
|
posX = x;
|
|
|
|
posY = y;
|
|
|
|
posZ = z;
|
|
|
|
|
|
|
|
setEntityBoundingBox(new AxisAlignedBB(
|
|
|
|
x - width, y - radius/2, z,
|
|
|
|
x + width, y + radius/2, z
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SoundCategory getSoundCategory() {
|
|
|
|
return SoundCategory.WEATHER;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isInRangeToRenderDist(double distance) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getRadius() {
|
|
|
|
return radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate() {
|
|
|
|
super.onUpdate();
|
|
|
|
|
|
|
|
if (ticksAlive-- <= 0) {
|
|
|
|
setDead();
|
|
|
|
}
|
2019-02-16 20:30:19 +01:00
|
|
|
|
|
|
|
if (!isDead) {
|
|
|
|
AxisAlignedBB bounds = SPAWN_COLLISSION_RADIUS.offset(getPosition());
|
|
|
|
|
|
|
|
world.getEntitiesWithinAABB(EntityRainbow.class, bounds).forEach(this::attackCompetitor);
|
|
|
|
world.getEntitiesWithinAABB(EntityRainbow.Spawner.class, bounds).forEach(this::attackCompetitor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void attackCompetitor(Entity other) {
|
|
|
|
if (other != this) {
|
|
|
|
other.setDead();
|
|
|
|
}
|
2019-02-04 14:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void entityInit() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void readEntityFromNBT(NBTTagCompound compound) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void writeEntityToNBT(NBTTagCompound compound) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class Spawner extends EntityLiving {
|
|
|
|
|
|
|
|
public Spawner(World worldIn) {
|
|
|
|
super(worldIn);
|
|
|
|
this.setInvisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean getCanSpawnHere() {
|
2019-02-16 20:30:19 +01:00
|
|
|
AxisAlignedBB bounds = SPAWN_COLLISSION_RADIUS.offset(getPosition());
|
2019-02-04 14:25:12 +01:00
|
|
|
|
2019-02-16 20:30:19 +01:00
|
|
|
return super.getCanSpawnHere()
|
|
|
|
&& world.getEntitiesWithinAABB(EntityRainbow.class, bounds).isEmpty()
|
|
|
|
&& world.getEntitiesWithinAABB(EntityRainbow.Spawner.class, bounds).isEmpty();
|
2019-02-04 14:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxSpawnedInChunk() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate() {
|
|
|
|
super.onUpdate();
|
2019-02-16 20:30:19 +01:00
|
|
|
if (!this.dead) {
|
|
|
|
setDead();
|
|
|
|
trySpawnRainbow();
|
|
|
|
}
|
|
|
|
}
|
2019-02-04 14:25:12 +01:00
|
|
|
|
2019-02-16 20:30:19 +01:00
|
|
|
public void trySpawnRainbow() {
|
2019-02-04 14:25:12 +01:00
|
|
|
EntityRainbow rainbow = new EntityRainbow(world);
|
|
|
|
rainbow.setPosition(posX, posY, posZ);
|
|
|
|
world.spawnEntity(rainbow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|