mirror of
https://github.com/allaryin/FairyFactions.git
synced 2026-04-25 16:19:54 -05:00
Fairies actually spawn in the wild, sort of :)
This commit is contained in:
parent
6a08cdd5f3
commit
baba10e79f
|
|
@ -8,6 +8,7 @@ import cpw.mods.fml.common.SidedProxy;
|
|||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import fairies.entity.EntityFairy;
|
||||
import fairies.event.FairyEventListener;
|
||||
import fairies.proxy.CommonProxy;
|
||||
|
|
@ -74,10 +75,13 @@ public class FairyFactions {
|
|||
final int freqNum = 8;
|
||||
fairySpawner.setMaxAnimals(maxNum);
|
||||
fairySpawner.AddCustomSpawn(EntityFairy.class, freqNum, EnumCreatureType.creature);
|
||||
FMLCommonHandler.instance().bus().register(fairySpawner);
|
||||
|
||||
// TODO: register egg
|
||||
// TODO: register entity localization
|
||||
LOGGER.debug("Spawner is a modified version of CustomSpawner, created by DrZhark.");
|
||||
|
||||
proxy.postInit();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import net.minecraft.util.MovingObjectPosition;
|
|||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.EnumDifficulty;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.EmptyChunk;
|
||||
|
||||
|
|
@ -2426,5 +2427,43 @@ public class EntityFairy extends EntityAnimal {
|
|||
// No fairy breeding.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSpawnedInChunk() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getCanSpawnHere() {
|
||||
if (super.getCanSpawnHere()) {
|
||||
int x = MathHelper.floor_double(posX);
|
||||
int z = MathHelper.floor_double(posZ);
|
||||
BiomeGenBase biome = worldObj.getBiomeGenForCoords(x, z);
|
||||
|
||||
if (biome != null && biome.rootHeight > -0.25F
|
||||
&& (biome.rootHeight + biome.heightVariation) <= 0.5F && biome.temperature >= 0.1F
|
||||
&& biome.temperature <= 1.0F && biome.rainfall > 0.0F
|
||||
&& biome.rainfall <= 0.8F) {
|
||||
List list = worldObj.getEntitiesWithinAABB(
|
||||
EntityFairy.class, this.boundingBox.expand(32D, 32D, 32D));
|
||||
|
||||
if (( list == null || list.size() < 1 ) && !worldObj.isRemote) {
|
||||
setJob(0);
|
||||
setSpecialJob(true);
|
||||
heal(30);
|
||||
setHealth(30);
|
||||
int i = rand.nextInt(15) + 1;
|
||||
setFaction(i);
|
||||
setSkin(rand.nextInt(4));
|
||||
cower = false;
|
||||
createGroup = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import fairies.entity.EntityFairy;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
|
@ -83,6 +85,21 @@ public final class Spawner {
|
|||
throw new RuntimeException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(TickEvent.WorldTickEvent event) {
|
||||
final World world = event.world;
|
||||
if( world != null && !world.isRemote
|
||||
&& world.difficultySetting.getDifficultyId() > 0
|
||||
&& world.getWorldInfo().getWorldTime() % 300L == 0L ) {
|
||||
final List list = world.playerEntities;
|
||||
if( list != null && list.size() > 0 ) {
|
||||
final int maxNum = 12 + (list.size() * 6);
|
||||
this.setMaxAnimals(maxNum);
|
||||
}
|
||||
this.doCustomSpawning(world, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
protected ChunkPosition getRandomSpawningPointInChunk(World world, int i, int j) {
|
||||
int k = i + world.rand.nextInt(16);
|
||||
|
|
@ -511,7 +528,7 @@ public final class Spawner {
|
|||
public int countSpawnedEntities(World world, EnumCreatureType enumcreaturetype) {
|
||||
int i = getEnumIndex(enumcreaturetype);
|
||||
int finalcount = 0;
|
||||
{
|
||||
if( i > -1 ) {
|
||||
boolean flag = false;
|
||||
|
||||
for (Iterator iterator = entityClasses[i].iterator(); iterator.hasNext();) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user