Fixed slime spawning in the Bayou. Closes #296
This commit is contained in:
parent
1193f82fb6
commit
8dcb99bcfb
3 changed files with 63 additions and 1 deletions
|
@ -13,6 +13,7 @@ import net.minecraft.world.EnumDifficulty;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
import biomesoplenty.BiomesOPlenty;
|
||||
import biomesoplenty.api.BOPItemHelper;
|
||||
import biomesoplenty.api.content.BOPCItems;
|
||||
|
@ -300,7 +301,7 @@ public class EntityGlob extends EntityLiving implements IMob
|
|||
{
|
||||
BiomeGenBase biomegenbase = worldObj.getBiomeGenForCoords(MathHelper.floor_double(posX), MathHelper.floor_double(posZ));
|
||||
|
||||
if (biomegenbase == BiomeGenBase.swampland && posY > 50.0D && posY < 70.0D && rand.nextFloat() < 0.5F && rand.nextFloat() < this.worldObj.getCurrentMoonPhaseFactor() && worldObj.getBlockLightValue(MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)) <= rand.nextInt(8))
|
||||
if (BiomeDictionary.isBiomeOfType(biomegenbase, BiomeDictionary.Type.SWAMP) && posY > 50.0D && posY < 70.0D && rand.nextFloat() < 0.5F && rand.nextFloat() < this.worldObj.getCurrentMoonPhaseFactor() && worldObj.getBlockLightValue(MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)) <= rand.nextInt(8))
|
||||
return super.getCanSpawnHere();
|
||||
|
||||
if (rand.nextInt(10) == 0 && chunk.getRandomWithSeed(987234911L).nextInt(10) == 0 && posY < 40.0D)
|
||||
|
|
|
@ -8,6 +8,7 @@ import biomesoplenty.common.eventhandler.client.gui.MainMenuEventHandler;
|
|||
import biomesoplenty.common.eventhandler.client.gui.StartupWarningEventHandler;
|
||||
import biomesoplenty.common.eventhandler.entity.DyeEventHandler;
|
||||
import biomesoplenty.common.eventhandler.entity.FlippersEventHandler;
|
||||
import biomesoplenty.common.eventhandler.entity.SlimeSpawnEventHandler;
|
||||
import biomesoplenty.common.eventhandler.entity.TemptEventHandler;
|
||||
import biomesoplenty.common.eventhandler.misc.BonemealEventHandler;
|
||||
import biomesoplenty.common.eventhandler.misc.BucketEventHandler;
|
||||
|
@ -46,6 +47,7 @@ public class BOPEventHandlers
|
|||
|
||||
private static void registerEntityEventHandlers()
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(new SlimeSpawnEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new DyeEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new FlippersEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new TemptEventHandler());
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package biomesoplenty.common.eventhandler.entity;
|
||||
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.monster.EntitySlime;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.EnumDifficulty;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
|
||||
import cpw.mods.fml.common.eventhandler.Event.Result;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
/**
|
||||
* A temporary (hopefully) measure to allow slimes to spawn
|
||||
* in biomes other than the swampland
|
||||
*/
|
||||
public class SlimeSpawnEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public void onCheckEntitySpawn(LivingSpawnEvent.CheckSpawn event)
|
||||
{
|
||||
World world = event.world;
|
||||
EntityLivingBase entity = event.entityLiving;
|
||||
|
||||
if (event.entityLiving instanceof EntitySlime)
|
||||
{
|
||||
BiomeGenBase biome = world.getBiomeGenForCoords(MathHelper.floor_double(entity.posX), MathHelper.floor_double(entity.posZ));
|
||||
|
||||
if (BiomeDictionary.isBiomeOfType(biome, BiomeDictionary.Type.SWAMP))
|
||||
{
|
||||
if (canSlimeSpawn((EntitySlime)entity)) event.setResult(Result.ALLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canSlimeSpawn(EntitySlime slime)
|
||||
{
|
||||
if (!slime.worldObj.getWorldInfo().getTerrainType().handleSlimeSpawnReduction(slime.getRNG(), slime.worldObj))
|
||||
{
|
||||
if (slime.getSlimeSize() == 1 || slime.worldObj.difficultySetting != EnumDifficulty.PEACEFUL)
|
||||
{
|
||||
if (slime.posY > 50.0D && slime.posY < 70.0D && slime.getRNG().nextFloat() < 0.5F && slime.getRNG().nextFloat() < slime.worldObj.getCurrentMoonPhaseFactor() && slime.worldObj.getBlockLightValue(MathHelper.floor_double(slime.posX), MathHelper.floor_double(slime.posY), MathHelper.floor_double(slime.posZ)) <= slime.getRNG().nextInt(8))
|
||||
{
|
||||
return getCanSpawnHere(slime);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean getCanSpawnHere(EntityLiving entity)
|
||||
{
|
||||
return entity.worldObj.checkNoEntityCollision(entity.boundingBox) && entity.worldObj.getCollidingBoundingBoxes(entity, entity.boundingBox).isEmpty() && !entity.worldObj.isAnyLiquid(entity.boundingBox);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue