package com.lothrazar.cyclicmagic.block;
import java.util.Random;
import com.lothrazar.cyclicmagic.module.WorldGenModule;
import com.lothrazar.cyclicmagic.util.Const;
import net.minecraft.block.BlockOre;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityEndermite;
import net.minecraft.entity.monster.EntitySilverfish;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class BlockDimensionOre extends BlockOre {
  private Item dropped;
  private int droppedMeta;
  private int randomMax;
  private int spawnChance = 0;
  private SpawnType spawn = null;
  public static enum SpawnType {
    ENDERMITE, SILVERFISH
  }
  public BlockDimensionOre(Item drop) {
    this(drop, 0);
  }
  public BlockDimensionOre(Item drop, int dmg) {
    this(drop, 0, 1);
  }
  public BlockDimensionOre(Item drop, int dmg, int max) {
    super();
    dropped = drop;
    droppedMeta = dmg;
    randomMax = max;
    this.setSoundType(SoundType.STONE);
    this.setHardness(3.0F).setResistance(5.0F);
    this.setHarvestLevel(Const.ToolStrings.axe, 0);
    this.setHarvestLevel(Const.ToolStrings.shovel, 0);
  }
  public BlockDimensionOre setPickaxeHarvestLevel(int h) {
    this.setHarvestLevel(Const.ToolStrings.pickaxe, h);
    return this;
  }
  public void setSpawnType(SpawnType t, int chance) {
    this.spawn = t;
    this.spawnChance = chance;
  }
  public void registerSmeltingOutput(Item out) {
    this.registerSmeltingOutput(new ItemStack(out));
  }
  public void registerSmeltingOutput(ItemStack out) {
    GameRegistry.addSmelting(this, out, 1);
  }
  public void trySpawnTriggeredEntity(World world, BlockPos pos) {
    if (WorldGenModule.oreSpawns == false) { return;//config has disabled spawning no matter what
    }
    if (this.spawn != null) {
      int rand = world.rand.nextInt(100);
      if (rand < this.spawnChance) {
        Entity e;
        switch (this.spawn) {
          case ENDERMITE:
            e = new EntityEndermite(world);
            e.setPosition(pos.getX(), pos.getY(), pos.getZ());
          break;
          case SILVERFISH:
            e = new EntitySilverfish(world);
            //magma cube: setSlimeSize is private BOO
            e.setPosition(pos.getX(), pos.getY(), pos.getZ());
          break;
          default:
            e = null;
          break;
        }
        if (e != null) {
          world.spawnEntity(e);
        }
      }
    }
  }
  public int damageDropped(IBlockState state) {
    return droppedMeta;
  }
  @Override
  public int quantityDroppedWithBonus(int fortune, Random random) {
    return super.quantityDroppedWithBonus(fortune, random);
  }
  @Override
  public Item getItemDropped(IBlockState state, Random rand, int fortune) {
    return dropped;
  }
  public int quantityDropped(Random random) {
    if (randomMax == 1) { return 1; }
    return 1 + random.nextInt(randomMax);
  }
  @Override
  public int getExpDrop(IBlockState state, net.minecraft.world.IBlockAccess world, BlockPos pos, int fortune) {
    Random rand = world instanceof World ? ((World) world).rand : new Random();
    return MathHelper.getInt(rand, 2, 5);
  }
  @Override
  public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
    return true;
  }
}

@@ -2019,16 +2019,19 @@
  return;
+ %7D 
 //config
@@ -2068,22 +2068,16 @@
 er what%0A
-    %7D%0A
     if (
@@ -2193,16 +2193,23 @@
 Entity e
+ = null
 ;%0A      
@@ -2306,71 +2306,8 @@
 d);%0A
-            e.setPosition(pos.getX(), pos.getY(), pos.getZ());%0A
     
@@ -2405,54 +2405,50 @@
     
-  //magma cube: setSlimeSize is private BOO%0A  
+break;%0A        %7D%0A        if (e != null) %7B%0A
     
@@ -2477,16 +2477,22 @@
 s.getX()
+ + 0.5
 , pos.ge
@@ -2495,16 +2495,22 @@
 s.getY()
+ + 0.5
 , pos.ge
@@ -2517,120 +2517,16 @@
 tZ()
-);%0A          break;%0A          default:%0A            e = null;%0A          break;%0A        %7D%0A        if (e != null) %7B
+ + 0.5);
 %0A   

fix infested ores dying on spawn within block