mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-03-03 16:51:28 +01:00
Change spawning behaviour to work in packs
This commit is contained in:
parent
c5c608fd35
commit
76eb83e2d2
2 changed files with 68 additions and 12 deletions
|
@ -134,7 +134,7 @@ public class EntityCloud extends EntityFlying implements IAnimals {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) {
|
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData pack) {
|
||||||
if (world.rand.nextInt(20) == 0 && canRainHere()) {
|
if (world.rand.nextInt(20) == 0 && canRainHere()) {
|
||||||
setRaining();
|
setRaining();
|
||||||
if (world.rand.nextInt(20) == 0) {
|
if (world.rand.nextInt(20) == 0) {
|
||||||
|
@ -144,7 +144,7 @@ public class EntityCloud extends EntityFlying implements IAnimals {
|
||||||
|
|
||||||
setCloudSize(1 + rand.nextInt(4));
|
setCloudSize(1 + rand.nextInt(4));
|
||||||
|
|
||||||
return super.onInitialSpawn(difficulty, livingdata);
|
return super.onInitialSpawn(difficulty, pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,26 +1,57 @@
|
||||||
package com.minelittlepony.unicopia.entity;
|
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.Entity;
|
||||||
import net.minecraft.entity.IEntityLivingData;
|
import net.minecraft.entity.IEntityLivingData;
|
||||||
|
import net.minecraft.util.ClassInheritanceMultiMap;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
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;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
public class EntityWildCloud extends EntityCloud {
|
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 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);
|
||||||
|
|
||||||
|
this.preventEntitySpawning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNotColliding() {
|
public boolean isNotColliding() {
|
||||||
AxisAlignedBB boundingbox = getEntityBoundingBox();
|
int count = 0;
|
||||||
return checkNoEntityCollision(boundingbox, this) && world.getCollisionBoxes(this, boundingbox).isEmpty() && !world.containsAnyLiquid(boundingbox);
|
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) {
|
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData pack) {
|
||||||
float minSpawnHeight = getMinimumFlyingHeight();
|
if (!(pack instanceof PackData)) {
|
||||||
|
float minSpawnHeight = getMinimumFlyingHeight();
|
||||||
|
|
||||||
altitude = getRandomFlyingHeight();
|
altitude = getRandomFlyingHeight();
|
||||||
|
|
||||||
if (posY < minSpawnHeight) {
|
if (posY < minSpawnHeight) {
|
||||||
minSpawnHeight += world.rand.nextInt(Math.max(1, (int)getMaximumFlyingHeight() - (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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue