mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 19:46:42 +01:00
Fixed rainbows spawning too close together (they just have to fight it out)
This commit is contained in:
parent
bbcfba31b7
commit
6bec00ab57
1 changed files with 29 additions and 10 deletions
|
@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.entity;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityLiving;
|
import net.minecraft.entity.EntityLiving;
|
||||||
import net.minecraft.entity.effect.EntityWeatherEffect;
|
import net.minecraft.entity.effect.EntityWeatherEffect;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@ -22,6 +23,11 @@ public class EntityRainbow extends EntityWeatherEffect implements IInAnimate {
|
||||||
public static final int RAINBOW_MAX_SIZE = 180;
|
public static final int RAINBOW_MAX_SIZE = 180;
|
||||||
public static final int RAINBOW_MIN_SIZE = 50;
|
public static final int RAINBOW_MIN_SIZE = 50;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
public EntityRainbow(World world) {
|
public EntityRainbow(World world) {
|
||||||
this(world, 0, 0, 0);
|
this(world, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
@ -85,6 +91,19 @@ public class EntityRainbow extends EntityWeatherEffect implements IInAnimate {
|
||||||
if (ticksAlive-- <= 0) {
|
if (ticksAlive-- <= 0) {
|
||||||
setDead();
|
setDead();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,11 +120,6 @@ public class EntityRainbow extends EntityWeatherEffect implements IInAnimate {
|
||||||
|
|
||||||
public static class Spawner extends EntityLiving {
|
public static class Spawner extends EntityLiving {
|
||||||
|
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
public Spawner(World worldIn) {
|
public Spawner(World worldIn) {
|
||||||
super(worldIn);
|
super(worldIn);
|
||||||
this.setInvisible(true);
|
this.setInvisible(true);
|
||||||
|
@ -113,11 +127,11 @@ public class EntityRainbow extends EntityWeatherEffect implements IInAnimate {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getCanSpawnHere() {
|
public boolean getCanSpawnHere() {
|
||||||
if (super.getCanSpawnHere()) {
|
AxisAlignedBB bounds = SPAWN_COLLISSION_RADIUS.offset(getPosition());
|
||||||
return world.getEntitiesWithinAABB(EntityRainbow.class, SPAWN_COLLISSION_RADIUS.offset(getPosition())).size() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return super.getCanSpawnHere()
|
||||||
|
&& world.getEntitiesWithinAABB(EntityRainbow.class, bounds).isEmpty()
|
||||||
|
&& world.getEntitiesWithinAABB(EntityRainbow.Spawner.class, bounds).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -128,8 +142,13 @@ public class EntityRainbow extends EntityWeatherEffect implements IInAnimate {
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate() {
|
public void onUpdate() {
|
||||||
super.onUpdate();
|
super.onUpdate();
|
||||||
|
if (!this.dead) {
|
||||||
setDead();
|
setDead();
|
||||||
|
trySpawnRainbow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void trySpawnRainbow() {
|
||||||
EntityRainbow rainbow = new EntityRainbow(world);
|
EntityRainbow rainbow = new EntityRainbow(world);
|
||||||
rainbow.setPosition(posX, posY, posZ);
|
rainbow.setPosition(posX, posY, posZ);
|
||||||
world.spawnEntity(rainbow);
|
world.spawnEntity(rainbow);
|
||||||
|
|
Loading…
Reference in a new issue