Change spawning behaviour to work in packs

This commit is contained in:
Sollace 2019-01-29 17:18:32 +02:00
parent c5c608fd35
commit 76eb83e2d2
2 changed files with 68 additions and 12 deletions

View file

@ -134,7 +134,7 @@ public class EntityCloud extends EntityFlying implements IAnimals {
}
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) {
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData pack) {
if (world.rand.nextInt(20) == 0 && canRainHere()) {
setRaining();
if (world.rand.nextInt(20) == 0) {
@ -144,7 +144,7 @@ public class EntityCloud extends EntityFlying implements IAnimals {
setCloudSize(1 + rand.nextInt(4));
return super.onInitialSpawn(difficulty, livingdata);
return super.onInitialSpawn(difficulty, pack);
}
@Override

View file

@ -1,26 +1,57 @@
package com.minelittlepony.unicopia.entity;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.util.ClassInheritanceMultiMap;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome.SpawnListEntry;
import net.minecraft.world.chunk.Chunk;
public class EntityWildCloud extends EntityCloud {
public static final SpawnListEntry SPAWN_ENTRY_LAND = new SpawnListEntry(EntityWildCloud.class, 1, 1, 3);
public static final SpawnListEntry SPAWN_ENTRY_LAND = new SpawnListEntry(EntityWildCloud.class, 1, 1, 15);
public static final SpawnListEntry SPAWN_ENTRY_OCEAN = new SpawnListEntry(EntityWildCloud.class, 1, 1, 2);
public EntityWildCloud(World world) {
super(world);
this.preventEntitySpawning = true;
}
@Override
public boolean isNotColliding() {
AxisAlignedBB boundingbox = getEntityBoundingBox();
return checkNoEntityCollision(boundingbox, this) && world.getCollisionBoxes(this, boundingbox).isEmpty() && !world.containsAnyLiquid(boundingbox);
int count = 0;
BlockPos pos = new BlockPos(this);
Chunk chunk = world.getChunk(pos);
for (ClassInheritanceMultiMap<Entity> i : chunk.getEntityLists()) {
Iterator<EntityCloud> iter = i.getByClass(EntityCloud.class).iterator();
while (iter.hasNext()) {
iter.next();
count++;
if (count > 2) {
return false;
}
}
}
AxisAlignedBB boundingbox = getEntityBoundingBox();
return checkNoEntityCollision(boundingbox, this)
&& world.canBlockSeeSky(pos)
&& world.getCollisionBoxes(this, boundingbox).isEmpty()
&& !world.containsAnyLiquid(boundingbox);
}
/**
@ -46,18 +77,43 @@ public class EntityWildCloud extends EntityCloud {
}
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) {
float minSpawnHeight = getMinimumFlyingHeight();
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData pack) {
if (!(pack instanceof PackData)) {
float minSpawnHeight = getMinimumFlyingHeight();
altitude = getRandomFlyingHeight();
altitude = getRandomFlyingHeight();
if (posY < minSpawnHeight) {
minSpawnHeight += world.rand.nextInt(Math.max(1, (int)getMaximumFlyingHeight() - (int)minSpawnHeight));
if (posY < 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();
}
pack = new PackData(this);
} else {
PackData packData = (PackData)pack;
altitude = packData.leader.altitude;
Vec3d position = packData.getUnOccupiedPosition(getCloudSize());
setLocationAndAngles(position.x, position.y, position.z, packData.leader.rotationYaw, packData.leader.rotationPitch);
collideWithNearbyEntities();
}
return super.onInitialSpawn(difficulty, livingdata);
return super.onInitialSpawn(difficulty, pack);
}
static class PackData implements IEntityLivingData {
EntityCloud leader;
PackData(EntityCloud leader) {
this.leader = leader;
}
Vec3d getUnOccupiedPosition(int size) {
return leader.getPositionVector();
}
}
}