diff --git a/src/main/java/magicbees/bees/HiveDescription.java b/src/main/java/magicbees/bees/HiveDescription.java new file mode 100644 index 0000000..2252131 --- /dev/null +++ b/src/main/java/magicbees/bees/HiveDescription.java @@ -0,0 +1,211 @@ +package magicbees.bees; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; + +import net.minecraftforge.common.BiomeDictionary; + +import forestry.api.apiculture.hives.HiveManager; +import forestry.api.apiculture.hives.IHiveDescription; +import forestry.api.apiculture.hives.IHiveGen; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; + +import magicbees.block.types.HiveType; +import magicbees.main.Config; +import magicbees.main.utils.BlockUtil; +import magicbees.main.utils.LogHelper; +import magicbees.world.feature.FeatureOreVein; +import magicbees.world.feature.HiveGenNether; +import magicbees.world.feature.HiveGenOblivion; +import magicbees.world.feature.HiveGenUnderground; + +public enum HiveDescription implements IHiveDescription { + CURIOUS(HiveType.CURIOUS, 3.0f, HiveManager.genHelper.tree()), + UNUSUAL(HiveType.UNUSUAL, 1.0f, HiveManager.genHelper.ground(Blocks.dirt, Blocks.grass)), + RESONANT(HiveType.RESONANT, 0.5f, HiveManager.genHelper.ground(Blocks.sand, Blocks.sandstone)), + DEEP(HiveType.DEEP, 2.0f, new HiveGenUnderground(10, 10, 6)) { + @Override + public void postGen(World world, int x, int y, int z) + { + super.postGen(world, x, y, z); + Random random = world.rand; + FeatureOreVein.redstoneGen.generateVein(world, random, x + 1, y, z, 2); + FeatureOreVein.redstoneGen.generateVein(world, random, x - 1, y, z, 2); + FeatureOreVein.redstoneGen.generateVein(world, random, x, y + 1, z, 2); + FeatureOreVein.redstoneGen.generateVein(world, random, x, y - 1, z, 2); + FeatureOreVein.redstoneGen.generateVein(world, random, x, y, z + 1, 2); + FeatureOreVein.redstoneGen.generateVein(world, random, x, y, z - 1, 2); + } + }, + INFERNAL(HiveType.INFERNAL, 50.0f, new HiveGenNether(0, 175, 6)) { + @Override + public void postGen(World world, int x, int y, int z) + { + super.postGen(world, x, y, z); + Random random = world.rand; + FeatureOreVein.netherQuartzGen.generateVein(world, random, x + 1, y, z, 4); + FeatureOreVein.netherQuartzGen.generateVein(world, random, x - 1, y, z, 4); + FeatureOreVein.netherQuartzGen.generateVein(world, random, x, y + 1, z, 4); + FeatureOreVein.netherQuartzGen.generateVein(world, random, x, y - 1, z, 4); + FeatureOreVein.netherQuartzGen.generateVein(world, random, x, y, z + 1, 4); + FeatureOreVein.netherQuartzGen.generateVein(world, random, x, y, z - 1, 4); + } + }, + INFERNAL_OVERWORLD(HiveType.INFERNAL, 1.0f, new HiveGenUnderground(5, 13, 6)) { + @Override + public void postGen(World world, int x, int y, int z) + { + super.postGen(world, x, y, z); + Random random = world.rand; + FeatureOreVein.glowstoneGen.generateVein(world, random, x + 1, y, z, world.rand.nextInt(4) + 1); + FeatureOreVein.glowstoneGen.generateVein(world, random, x - 1, y, z, world.rand.nextInt(4) + 1); + + if (BlockUtil.canBlockReplaceAt(world, x, y + 1, z, Blocks.stone)) + { + world.setBlock(x, y + 1, z, Blocks.glowstone, 0, 3); + } + + if (BlockUtil.canBlockReplaceAt(world, x, y - 1, z, Blocks.stone)) + { + world.setBlock(x, y - 1, z, Blocks.glowstone, 0, 3); + } + + FeatureOreVein.glowstoneGen.generateVein(world, random, x, y, z + 1, world.rand.nextInt(4) + 1); + FeatureOreVein.glowstoneGen.generateVein(world, random, x, y, z - 1, world.rand.nextInt(4) + 1); + } + }, + OBLIVION(HiveType.OBLIVION, 20.0f, new HiveGenOblivion()) { + @Override + public void postGen(World world, int x, int y, int z) + { + super.postGen(world, x, y, z); + int obsidianSpikeHeight = world.rand.nextInt(8) + 3; + + for (int i = 1; i < obsidianSpikeHeight && y - i > 0; ++i) + { + world.setBlock(x, y - i, z, Blocks.obsidian, 0, 2); + } + } + }, + OBLIVION_OVERWORLD(HiveType.OBLIVION, 1.0f, new HiveGenUnderground(5, 5, 5)) { + @Override + public void postGen(World world, int x, int y, int z) + { + super.postGen(world, x, y, z); + Random random = world.rand; + + FeatureOreVein.endStoneGen.generateVein(world, random, x + 1, y, z, world.rand.nextInt(6) + 1); + FeatureOreVein.endStoneGen.generateVein(world, random, x - 1, y, z, world.rand.nextInt(6) + 1); + FeatureOreVein.endStoneGen.generateVein(world, random, x, y + 1, z, world.rand.nextInt(3) + 1); + FeatureOreVein.endStoneGen.generateVein(world, random, x, y - 1, z, world.rand.nextInt(3) + 1); + FeatureOreVein.endStoneGen.generateVein(world, random, x, y, z + 1, world.rand.nextInt(6) + 1); + FeatureOreVein.endStoneGen.generateVein(world, random, x, y, z - 1, world.rand.nextInt(6) + 1); + } + }; + + private static boolean logSpawns = Config.logHiveSpawns; + + private final HiveType hiveType; + private final float genChance; + private final List biomes = new ArrayList(); + private final IHiveGen hiveGen; + + private HiveDescription(HiveType hiveType, float genChance, IHiveGen hiveGen) + { + this.hiveType = hiveType; + this.genChance = genChance; + this.hiveGen = hiveGen; + } + + public static void initHiveData() + { + CURIOUS.biomes.add(BiomeDictionary.Type.FOREST); + CURIOUS.biomes.add(BiomeDictionary.Type.JUNGLE); + CURIOUS.biomes.add(BiomeDictionary.Type.HILLS); + + UNUSUAL.biomes.add(BiomeDictionary.Type.PLAINS); + UNUSUAL.biomes.add(BiomeDictionary.Type.MOUNTAIN); + UNUSUAL.biomes.add(BiomeDictionary.Type.HILLS); + + RESONANT.biomes.add(BiomeDictionary.Type.SANDY); + RESONANT.biomes.add(BiomeDictionary.Type.MAGICAL); + + DEEP.biomes.add(BiomeDictionary.Type.HILLS); + DEEP.biomes.add(BiomeDictionary.Type.MOUNTAIN); + DEEP.biomes.add(BiomeDictionary.Type.MAGICAL); + + INFERNAL.biomes.add(BiomeDictionary.Type.NETHER); + INFERNAL_OVERWORLD.biomes.add(BiomeDictionary.Type.MAGICAL); + + OBLIVION.biomes.add(BiomeDictionary.Type.END); + OBLIVION_OVERWORLD.biomes.add(BiomeDictionary.Type.MAGICAL); + } + + @Override + public IHiveGen getHiveGen() + { + return hiveGen; + } + + @Override + public Block getBlock() + { + return Config.hive; + } + + @Override + public int getMeta() + { + return hiveType.ordinal(); + } + + @Override + public boolean isGoodBiome(BiomeGenBase biome) + { + BiomeDictionary.Type[] types = BiomeDictionary.getTypesForBiome(biome); + for (BiomeDictionary.Type type : types) + { + if (biomes.contains(type)) + { + return true; + } + } + + return false; + } + + @Override + public boolean isGoodHumidity(EnumHumidity humidity) + { + return true; + } + + @Override + public boolean isGoodTemperature(EnumTemperature temperature) + { + return true; + } + + @Override + public float getGenChance() + { + return genChance; + } + + @Override + public void postGen(World world, int x, int y, int z) + { + if (logSpawns) + { + LogHelper.info("Spawned " + this.toString().toLowerCase(Locale.ENGLISH) + " hive at: X " + x + ", Y: " + y + ", Z: " + z); + } + } +} diff --git a/src/main/java/magicbees/block/types/HiveType.java b/src/main/java/magicbees/block/types/HiveType.java index 5431d0e..584d2a3 100644 --- a/src/main/java/magicbees/block/types/HiveType.java +++ b/src/main/java/magicbees/block/types/HiveType.java @@ -1,10 +1,18 @@ package magicbees.block.types; import java.util.ArrayList; -import java.util.Random; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; + +import forestry.api.apiculture.IHiveDrop; + import magicbees.bees.BeeGenomeManager; import magicbees.bees.BeeSpecies; import magicbees.bees.HiveDrop; @@ -12,16 +20,6 @@ import magicbees.item.types.CombType; import magicbees.main.CommonProxy; import magicbees.main.Config; import magicbees.main.utils.compat.ForestryHelper; -import magicbees.world.feature.FeatureHive; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; -import net.minecraftforge.common.BiomeDictionary; -import net.minecraftforge.common.BiomeDictionary.Type; -import forestry.api.apiculture.IHiveDrop; public enum HiveType { @@ -39,7 +37,7 @@ public enum HiveType public boolean show; private int lightLevel; private ArrayList drops; - private ArrayList validBiomes; + @SideOnly(Side.CLIENT) private IIcon[] icons; @@ -60,44 +58,29 @@ public enum HiveType ItemStack[] combs = new ItemStack[] { Config.combs.getStackForType(CombType.MUNDANE) }; HiveDrop valiantDrop = new HiveDrop(BeeGenomeManager.addRainResist(ForestryHelper.getTemplateForestryForSpecies("Valiant")), combs, 5); - CURIOUS.validBiomes.add(Type.FOREST); - CURIOUS.validBiomes.add(Type.JUNGLE); - CURIOUS.validBiomes.add(Type.HILLS); CURIOUS.drops.add(new HiveDrop(BeeSpecies.MYSTICAL.getGenome(), combs, 80).setIgnoblePercentage(0.7f)); CURIOUS.drops.add(new HiveDrop(BeeGenomeManager.addRainResist(BeeSpecies.MYSTICAL.getGenome()), combs, 15)); CURIOUS.drops.add(valiantDrop); - - UNUSUAL.validBiomes.add(Type.PLAINS); - UNUSUAL.validBiomes.add(Type.MOUNTAIN); - UNUSUAL.validBiomes.add(Type.HILLS); + UNUSUAL.drops.add(new HiveDrop(BeeSpecies.UNUSUAL.getGenome(), combs, 80).setIgnoblePercentage(0.7f)); UNUSUAL.drops.add(new HiveDrop(BeeGenomeManager.addRainResist(BeeSpecies.UNUSUAL.getGenome()), combs, 15)); UNUSUAL.drops.add(valiantDrop); - RESONANT.validBiomes.add(Type.SANDY); - RESONANT.validBiomes.add(Type.MAGICAL); RESONANT.drops.add(new HiveDrop(BeeSpecies.SORCEROUS.getGenome(), combs, 80).setIgnoblePercentage(0.7f)); RESONANT.drops.add(new HiveDrop(BeeGenomeManager.addRainResist(BeeSpecies.SORCEROUS.getGenome()), combs, 20)); RESONANT.drops.add(valiantDrop); - - DEEP.validBiomes.add(Type.HILLS); - DEEP.validBiomes.add(Type.MOUNTAIN); - DEEP.validBiomes.add(Type.MAGICAL); + DEEP.drops.add(new HiveDrop(BeeSpecies.ATTUNED.getGenome(), combs, 80).setIgnoblePercentage(0.65f)); DEEP.drops.add(new HiveDrop(BeeGenomeManager.addRainResist(BeeSpecies.ATTUNED.getGenome()), combs, 20)); DEEP.drops.add(valiantDrop); - + combs = new ItemStack[] { Config.combs.getStackForType(CombType.MOLTEN), new ItemStack(Items.glowstone_dust, 6) }; - - INFERNAL.validBiomes.add(Type.NETHER); - INFERNAL.validBiomes.add(Type.MAGICAL); + INFERNAL.drops.add(new HiveDrop(BeeSpecies.INFERNAL.getGenome(), combs, 80).setIgnoblePercentage(0.5f)); INFERNAL.drops.add(new HiveDrop(ForestryHelper.getTemplateForestryForSpecies("Steadfast"), combs, 3)); - + combs = new ItemStack[] { Config.combs.getStackForType(CombType.FORGOTTEN), new ItemStack(Items.ender_pearl, 1) }; - - OBLIVION.validBiomes.add(Type.END); - OBLIVION.validBiomes.add(Type.MAGICAL); + OBLIVION.drops.add(new HiveDrop(BeeSpecies.OBLIVION.getGenome(), combs, 80)); OBLIVION.drops.add(new HiveDrop(ForestryHelper.getTemplateForestryForSpecies("Steadfast"), combs, 9)); } @@ -108,7 +91,6 @@ public enum HiveType this.lightLevel = light; this.show = visible; this.drops = new ArrayList(); - this.validBiomes = new ArrayList(); } @SideOnly(Side.CLIENT) @@ -122,17 +104,7 @@ public enum HiveType type.icons[1] = register.registerIcon(CommonProxy.DOMAIN + ":beehive." + type.ordinal() + ".side"); } } - - private HiveType() - { - this.drops = new ArrayList(); - } - - public void addDrop(IHiveDrop drop) - { - this.drops.add(drop); - } - + @SideOnly(Side.CLIENT) public IIcon getIconForSide(int side) { @@ -210,99 +182,4 @@ public enum HiveType } return names; } - - public void generateHive(World world, Random random, int chunkX, int chunkZ, boolean initialGen) - { - if (spawnsInBiome(world.getBiomeGenForCoordsBody(chunkX * 16, chunkZ * 16))) - { - switch (this) - { - case CURIOUS: - for (int i = 0; i < 3; ++i) - { - int coordX = chunkX * 16 + random.nextInt(16); - int coordZ = chunkZ * 16 + random.nextInt(16); - if (FeatureHive.generateHiveCurious(world, random, coordX, coordZ, initialGen)) - { - break; - } - } - break; - case UNUSUAL: - for (int i = 0; i < 3; ++i) - { - int coordX = chunkX * 16 + random.nextInt(16); - int coordZ = chunkZ * 16 + random.nextInt(16); - if (FeatureHive.generateHiveUnusual(world, random, coordX, coordZ, initialGen)) - { - break; - } - } - break; - case RESONANT: - for (int i = 0; i < 3; ++i) - { - int coordX = chunkX * 16 + random.nextInt(16); - int coordZ = chunkZ * 16 + random.nextInt(16); - if (FeatureHive.generateHiveResonant(world, random, coordX, coordZ, initialGen)) - { - break; - } - } - break; - case DEEP: - if (chunkX % 2 == 0 && chunkZ % 2 == 0) - { - for (int i = 0; i < 1; ++i) - { - int coordX = chunkX * 16 + random.nextInt(16); - int coordZ = chunkZ * 16 + random.nextInt(16); - if (FeatureHive.generateHiveDeep(world, random, coordX, coordZ, initialGen)) - { - break; - } - } - } - break; - case INFERNAL: - for (int i = 0; i < 2; ++i) - { - int coordX = chunkX * 16 + random.nextInt(16); - int coordZ = chunkZ * 16 + random.nextInt(16); - if (FeatureHive.generateHiveInfernal(world, random, coordX, coordZ, initialGen)) - { - break; - } - } - break; - case OBLIVION: - for (int i = 0; i < 3; ++i) - { - int coordX = chunkX * 16 + random.nextInt(16); - int coordZ = chunkZ * 16 + random.nextInt(16); - if (FeatureHive.generateHiveOblivion(world, random, coordX, coordZ, initialGen)) - { - break; - } - } - break; - } - } - } - - public boolean spawnsInBiome(BiomeGenBase biomeGen) - { - boolean found = false; - BiomeDictionary.Type[] types = BiomeDictionary.getTypesForBiome(biomeGen); - for (int i = 0; i < types.length; ++i) - { - if (this.validBiomes.contains(types[i])) - { - found = true; - break; - } - } - - return found; - } } diff --git a/src/main/java/magicbees/main/Config.java b/src/main/java/magicbees/main/Config.java index b9615f2..9538761 100644 --- a/src/main/java/magicbees/main/Config.java +++ b/src/main/java/magicbees/main/Config.java @@ -72,8 +72,6 @@ public class Config public static boolean doSpecialHiveGen; public static String thaumaturgeExtraItems; public static int capsuleStackSizeMax; - public static boolean doHiveRetrogen; - public static boolean forceHiveRegen; public static boolean logHiveSpawns; public static double thaumcraftSaplingDroprate; @@ -485,25 +483,6 @@ public class Config p = configuration.get("general", "doSpecialHiveGen", true); p.comment = "Set to false if you hate fun and do not want special hives generating in Magic biomes."; doSpecialHiveGen = p.getBoolean(true); - - p = configuration.get("Retrogen", "doHiveRetrogen", false); - p.comment = "Set to true to enable retroactive worldgen of Magic Bees hives."; - doHiveRetrogen = p.getBoolean(false); - - p = configuration.get("Retrogen", "forceHiveRegen", false); - p.comment = "Set to true to force a regeneration of Magic Bees hives. Will set config option to false after parsed. (Implies doHiveRetrogen=true)"; - forceHiveRegen = p.getBoolean(false); - - if (forceHiveRegen) - { - FMLLog.info("Magic Bees will aggressively regenerate hives in all chunks for this game instance. Config option set to false."); - p.set(false); - doHiveRetrogen = true; - } - else if (doHiveRetrogen) - { - FMLLog.info("Magic Bees will attempt to regenerate hives in chunks that were generated before the mod was added."); - } p = configuration.get("general", "magnetRangeBase", 3.0); p.comment = "Base range (in blocks) of the Mysterious Magnet"; diff --git a/src/main/java/magicbees/main/MagicBees.java b/src/main/java/magicbees/main/MagicBees.java index 91fd128..c694aa5 100644 --- a/src/main/java/magicbees/main/MagicBees.java +++ b/src/main/java/magicbees/main/MagicBees.java @@ -8,7 +8,7 @@ import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkRegistry; -import cpw.mods.fml.common.registry.GameRegistry; + import magicbees.bees.BeeManager; import magicbees.bees.TransmutationEffectController; import magicbees.client.gui.GUIHandler; @@ -17,7 +17,6 @@ import magicbees.main.utils.IMCManager; import magicbees.main.utils.LogHelper; import magicbees.main.utils.VersionInfo; import magicbees.main.utils.compat.ModHelper; -import magicbees.world.WorldGeneratorHandler; @Mod( modid = VersionInfo.ModName, @@ -36,7 +35,6 @@ public class MagicBees public GUIHandler guiHandler; private String configsPath; private Config modConfig; - private WorldGeneratorHandler worldHandler; @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) @@ -62,9 +60,6 @@ public class MagicBees { ModHelper.init(); - worldHandler = new WorldGeneratorHandler(); - GameRegistry.registerWorldGenerator(worldHandler, 0); - LogHelper.info("Init completed"); } diff --git a/src/main/java/magicbees/main/utils/BlockUtil.java b/src/main/java/magicbees/main/utils/BlockUtil.java new file mode 100644 index 0000000..3fca28e --- /dev/null +++ b/src/main/java/magicbees/main/utils/BlockUtil.java @@ -0,0 +1,55 @@ +package magicbees.main.utils; + +import net.minecraft.block.Block; +import net.minecraft.world.World; + +public class BlockUtil { + + public static int getSurroundCount(World world, int x, int y, int z, Block blockType) + { + int surroundCount = 0; + + if (canBlockReplaceAt(world, x + 1, y, z, blockType)) + { + ++surroundCount; + } + + if (canBlockReplaceAt(world, x - 1, y, z, blockType)) + { + ++surroundCount; + } + + if (canBlockReplaceAt(world, x, y + 1, z, blockType)) + { + ++surroundCount; + } + + if (canBlockReplaceAt(world, x, y - 1, z, blockType)) + { + ++surroundCount; + } + + if (canBlockReplaceAt(world, x, y, z + 1, blockType)) + { + ++surroundCount; + } + + if (canBlockReplaceAt(world, x, y, z - 1, blockType)) + { + ++surroundCount; + } + + return surroundCount; + } + + public static boolean canBlockReplaceAt(World world, int x, int y, int z, Block target) + { + // don't cause new chunks to load + if (!world.blockExists(x, y, z)) + { + return true; + } + Block block = world.getBlock(x, y, z); + return block.isReplaceableOreGen(world, x, y, z, target); + } +} diff --git a/src/main/java/magicbees/main/utils/compat/ForestryHelper.java b/src/main/java/magicbees/main/utils/compat/ForestryHelper.java index eacc427..47c1ea3 100644 --- a/src/main/java/magicbees/main/utils/compat/ForestryHelper.java +++ b/src/main/java/magicbees/main/utils/compat/ForestryHelper.java @@ -1,9 +1,17 @@ package magicbees.main.utils.compat; +import java.util.Locale; + import magicbees.bees.BeeManager; +import magicbees.bees.HiveDescription; +import magicbees.block.types.HiveType; import magicbees.main.Config; import magicbees.main.utils.BlockInterface; import magicbees.main.utils.ItemInterface; +import magicbees.main.utils.VersionInfo; + +import forestry.api.apiculture.hives.HiveManager; +import forestry.api.apiculture.hives.IHiveRegistry; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.genetics.IAllele; @@ -90,6 +98,27 @@ public class ForestryHelper public static void preInit() { + IHiveRegistry hiveRegistry = HiveManager.hiveRegistry; + + HiveDescription.initHiveData(); + + registerHive(hiveRegistry, HiveDescription.CURIOUS); + registerHive(hiveRegistry, HiveDescription.UNUSUAL); + registerHive(hiveRegistry, HiveDescription.RESONANT); + registerHive(hiveRegistry, HiveDescription.DEEP); + registerHive(hiveRegistry, HiveDescription.INFERNAL); + registerHive(hiveRegistry, HiveDescription.OBLIVION); + + if (Config.doSpecialHiveGen) + { + registerHive(hiveRegistry, HiveDescription.INFERNAL_OVERWORLD); + registerHive(hiveRegistry, HiveDescription.OBLIVION_OVERWORLD); + } + } + + private static void registerHive(IHiveRegistry hiveRegistry, HiveDescription hiveDescription) { + String hiveName = VersionInfo.ModName + ":" + hiveDescription.toString().toLowerCase(Locale.ENGLISH); + hiveRegistry.registerHive(hiveName, hiveDescription); } public static void init() diff --git a/src/main/java/magicbees/world/WorldGeneratorHandler.java b/src/main/java/magicbees/world/WorldGeneratorHandler.java deleted file mode 100644 index ba60a58..0000000 --- a/src/main/java/magicbees/world/WorldGeneratorHandler.java +++ /dev/null @@ -1,94 +0,0 @@ -package magicbees.world; - -import java.util.Random; - -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.IWorldGenerator; -import cpw.mods.fml.common.Mod; - -import magicbees.main.Config; -import magicbees.main.utils.ChunkCoords; -import magicbees.world.feature.FeatureHive; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; -import net.minecraft.world.WorldType; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.world.ChunkDataEvent; - -public class WorldGeneratorHandler implements IWorldGenerator -{ - public WorldTicker ticker; - - public WorldGeneratorHandler() - { - this.ticker = new WorldTicker(this); - FMLCommonHandler.instance().bus().register(ticker); - MinecraftForge.EVENT_BUS.register(this); - - FeatureHive.initialize(); - } - - @Mod.EventHandler - public void chunkSaveEventHandler(ChunkDataEvent.Save event) - { - NBTTagCompound tag = new NBTTagCompound(); - if (Config.doHiveRetrogen) - { - tag.setBoolean("hiveRetrogen", true); - } - - event.getData().setTag("MagicBees", tag); - } - - @Mod.EventHandler - public void chunkLoadEventHandler(ChunkDataEvent.Load event) - { - boolean doRetrogen = false; - - NBTTagCompound tag = (NBTTagCompound)event.getData().getTag("MagicBees"); - if (tag == null) - { - doRetrogen = true; - } - else if (Config.doHiveRetrogen) - { - if (!tag.hasKey("hiveRetrogen") || Config.forceHiveRegen) - { - doRetrogen = true; - } - } - - if (doRetrogen) - { - ChunkCoords coords = new ChunkCoords(event.getChunk()); - ticker.queueChunkCoords(coords); - } - } - - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) - { - generateWorld(world, random, chunkX, chunkZ, true); - } - - public void generateWorld(World world, Random random, int chunkX, int chunkZ, boolean initialGen) - { - boolean modified = false; - - if (world.provider.terrainType != WorldType.FLAT) - { - if (initialGen || Config.doHiveRetrogen) - { - FeatureHive.generateHives(world, random, chunkX, chunkZ, initialGen); - modified = true; - } - } - - if (!initialGen && modified) - { - world.getChunkFromChunkCoords(chunkX, chunkZ).setChunkModified(); - } - } - -} \ No newline at end of file diff --git a/src/main/java/magicbees/world/WorldTicker.java b/src/main/java/magicbees/world/WorldTicker.java deleted file mode 100644 index b9aee84..0000000 --- a/src/main/java/magicbees/world/WorldTicker.java +++ /dev/null @@ -1,62 +0,0 @@ -package magicbees.world; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Random; - -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.gameevent.TickEvent; -import magicbees.main.utils.ChunkCoords; -import net.minecraft.world.World; - -public class WorldTicker -{ - private WorldGeneratorHandler parent; - private HashMap> chunkRegenList; - - public WorldTicker(WorldGeneratorHandler p) - { - this.parent = p; - this.chunkRegenList = new HashMap>(); - } - - @SubscribeEvent - public void onTick(TickEvent.WorldTickEvent event) - { - if (event.phase == TickEvent.Phase.END) - { - World world = event.world; - int dimensionID = world.provider.dimensionId; - LinkedList chunkList = chunkRegenList.get(dimensionID); - - if (chunkList != null && chunkList.peekFirst() != null) - { - ChunkCoords coords = chunkList.removeFirst(); - - // This bit is from FML's GameRegistry.generateWorld where the seed is constructed. - long worldSeed = world.getSeed(); - Random random = new Random(worldSeed); - long xSeed = random.nextLong() >> 2 + 1L; - long zSeed = random.nextLong() >> 2 + 1L; - random.setSeed((xSeed * coords.xCoord + zSeed * coords.zCoord) ^ worldSeed); - - parent.generateWorld(world, random, coords.xCoord, coords.zCoord, false); - } - } - } - - public void queueChunkCoords(ChunkCoords coords) - { - if (!chunkRegenList.containsKey(coords.dimension)) - { - chunkRegenList.put(coords.dimension, new LinkedList()); - } - chunkRegenList.get(coords.dimension).addLast(coords); - } - - public LinkedList getChunksToGen(int dimensionId) - { - return chunkRegenList.get(dimensionId); - } - -} diff --git a/src/main/java/magicbees/world/feature/FeatureHive.java b/src/main/java/magicbees/world/feature/FeatureHive.java deleted file mode 100644 index 7615f2b..0000000 --- a/src/main/java/magicbees/world/feature/FeatureHive.java +++ /dev/null @@ -1,322 +0,0 @@ -package magicbees.world.feature; - -import java.util.Random; - -import magicbees.block.types.HiveType; -import magicbees.main.Config; -import magicbees.main.utils.LogHelper; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; - -public class FeatureHive -{ - private static FeatureOreVein redstoneGen; - private static FeatureOreVein netherQuartzGen; - private static FeatureOreVein glowstoneGen; - private static FeatureOreVein endStoneGen; - - private static boolean logSpawns = Config.logHiveSpawns; - - public static void initialize() - { - redstoneGen = new FeatureOreVein(Blocks.redstone_ore, Blocks.stone); - netherQuartzGen = new FeatureOreVein(Blocks.quartz_ore, Blocks.netherrack); - glowstoneGen = new FeatureOreVein(Blocks.glowstone, Blocks.stone); - endStoneGen = new FeatureOreVein(Blocks.end_stone, Blocks.stone); - } - - public static void generateHives(World world, Random random, int chunkX, int chunkZ, boolean initialGen) - { - for (HiveType type : HiveType.values()) - { - type.generateHive(world, random, chunkX, chunkZ, initialGen); - } - } - - public static boolean generateHiveCurious(World world, Random random, int coordX, int coordZ, boolean initialGen) - { - int coordY = getHeight(world, random, coordX, coordZ); - boolean doSpawn = false; - - Block b = world.getBlock(coordX, coordY + 1, coordZ); - if (world.isAirBlock(coordX, coordY - 1, coordZ) && - world.isAirBlock(coordX, coordY, coordZ) && - b != null && b.isLeaves(world, coordX, coordY + 1, coordZ)) - { - world.setBlock(coordX, coordY, coordZ, Config.hive, HiveType.CURIOUS.ordinal(), 3); - if (logSpawns) - LogHelper.info("Spawning curious hive at: X " + coordX + ", Y: " + coordY + ", Z: " + coordZ); - doSpawn = true; - } - - return doSpawn; - } - - public static boolean generateHiveUnusual(World world, Random random, int coordX, int coordZ, boolean initialGen) - { - int coordY = getHeight(world, random, coordX, coordZ); - - boolean doSpawn = false; - if (world.isAirBlock(coordX, coordY + 1, coordZ) && - world.isAirBlock(coordX, coordY, coordZ) && - canBlockReplaceAt(world, coordX, coordY - 1, coordZ, Blocks.grass)) - { - doSpawn = true; - } - - if (doSpawn) - { - world.setBlock(coordX, coordY, coordZ, Config.hive, HiveType.UNUSUAL.ordinal(), 3); - if (logSpawns) - LogHelper.info("Spawning unusual hive at: X " + coordX + ", Y: " + coordY + ", Z: " + coordZ); - } - - return doSpawn; - } - - public static boolean generateHiveResonant(World world, Random random, int coordX, int coordZ, boolean initialGen) - { - int coordY = getHeight(world, random, coordX, coordZ); - boolean doSpawn = false; - if (world.rand.nextInt() < 40 && world.isAirBlock(coordX, coordY + 1, coordZ) && - (world.isAirBlock(coordX, coordY, coordZ) || canBlockReplaceAt(world, coordX, coordY, coordZ, - Blocks.tallgrass)) && - (canBlockReplaceAt(world, coordX, coordY - 1, coordZ, Blocks.grass) || - canBlockReplaceAt(world, coordX, coordY - 1, coordZ, Blocks.sand))) - { - doSpawn = true; - } - - if (doSpawn) - { - world.setBlock(coordX, coordY, coordZ, Config.hive, HiveType.RESONANT.ordinal(), 3); - if (logSpawns) - LogHelper.info("Spawning resonant hive at: X " + coordX + ", Y: " + coordY + ", Z: " + coordZ); - } - - return doSpawn; - } - - public static boolean generateHiveDeep(World world, Random random, int coordX, int coordZ, boolean initialGen) - { - - BiomeGenBase biome = world.getBiomeGenForCoords(coordX, coordZ); - int coordY = 10 + random.nextInt(10); - - boolean doSpawn = false; - - if (random.nextInt(100) < 40 && - !world.isAirBlock(coordX, coordY, coordZ) && canBlockReplaceAt(world, coordX, coordY, coordZ, - Blocks.stone)) - { - doSpawn = getSurroundCount(world, coordX, coordY, coordZ, Blocks.stone) >= 6; - } - - if (doSpawn) - { - world.setBlock(coordX, coordY, coordZ, Config.hive, HiveType.DEEP.ordinal(), 3); - if (logSpawns) LogHelper.info("Spawning deep hive at: X " + coordX + ", Y: " + coordY + ", Z: " + coordZ); - - - redstoneGen.generateVein(world, random, coordX + 1, coordY, coordZ, 2); - redstoneGen.generateVein(world, random, coordX - 1, coordY, coordZ, 2); - redstoneGen.generateVein(world, random, coordX, coordY + 1, coordZ, 2); - redstoneGen.generateVein(world, random, coordX, coordY - 1, coordZ, 2); - redstoneGen.generateVein(world, random, coordX, coordY, coordZ + 1, 2); - redstoneGen.generateVein(world, random, coordX, coordY, coordZ - 1, 2); - } - - return doSpawn; - } - - public static boolean generateHiveInfernal(World world, Random random, int coordX, int coordZ, boolean initialGen) - { - boolean doSpawn = false; - if (!world.provider.isSurfaceWorld()) - { - int chop = random.nextInt(2) + 1; - int coordY = random.nextInt(60 / chop) + random.nextInt(chop) * (120 / chop) - 5; - - if (!world.isAirBlock(coordX, coordY, coordZ) && world.getBlock(coordX, coordY, coordZ) != null && - world.getBlock(coordX, coordY, coordZ).isReplaceableOreGen(world, coordX, coordY, coordZ, - Blocks.netherrack)) - { - doSpawn = getSurroundCount(world, coordX, coordY, coordZ, Blocks.netherrack) >= 5; - } - - if (doSpawn) - { - world.setBlock(coordX, coordY, coordZ, Config.hive, HiveType.INFERNAL.ordinal(), 3); - if (logSpawns) - LogHelper.info("Spawning infernal hive at: X " + coordX + ", Y: " + coordY + ", Z: " + coordZ); - - netherQuartzGen.generateVein(world, random, coordX + 1, coordY, coordZ, 4); - netherQuartzGen.generateVein(world, random, coordX - 1, coordY, coordZ, 4); - netherQuartzGen.generateVein(world, random, coordX, coordY + 1, coordZ, 4); - netherQuartzGen.generateVein(world, random, coordX, coordY - 1, coordZ, 4); - netherQuartzGen.generateVein(world, random, coordX, coordY, coordZ + 1, 4); - netherQuartzGen.generateVein(world, random, coordX, coordY, coordZ - 1, 4); - } - } - else if (Config.doSpecialHiveGen && world.rand.nextInt() < 11) - { - int coordY = random.nextInt(13) + 5; - - if (!world.isAirBlock(coordX, coordY, coordZ) && - canBlockReplaceAt(world, coordX, coordY, coordZ, Blocks.stone)) - { - - doSpawn = getSurroundCount(world, coordX, coordY, coordZ, Blocks.stone) >= 6; - } - - if (doSpawn) - { - world.setBlock(coordX, coordY, coordZ, Config.hive, HiveType.INFERNAL.ordinal(), 3); - if (logSpawns) - LogHelper.info("Spawning infernal hive at: X " + coordX + ", Y: " + coordY + ", Z: " + coordZ); - - glowstoneGen.generateVein(world, random, coordX + 1, coordY, coordZ, world.rand.nextInt(4) + 1); - glowstoneGen.generateVein(world, random, coordX - 1, coordY, coordZ, world.rand.nextInt(4) + 1); - - if (canBlockReplaceAt(world, coordX, coordY + 1, coordZ, Blocks.stone) || - canBlockReplaceAt(world, coordX, coordY + 1, coordZ, Blocks.netherrack)) - { - world.setBlock(coordX, coordY + 1, coordZ, Blocks.glowstone, 0, 3); - } - - if (canBlockReplaceAt(world, coordX, coordY - 1, coordZ, Blocks.stone) || - canBlockReplaceAt(world, coordX, coordY + 1, coordZ, Blocks.netherrack)) - { - world.setBlock(coordX, coordY - 1, coordZ, Blocks.glowstone, 0, 3); - } - - glowstoneGen.generateVein(world, random, coordX, coordY, coordZ + 1, world.rand.nextInt(4) + 1); - glowstoneGen.generateVein(world, random, coordX, coordY, coordZ - 1, world.rand.nextInt(4) + 1); - } - } - - return doSpawn; - } - - public static boolean generateHiveOblivion(World world, Random random, int coordX, int coordZ, boolean initialGen) - { - boolean doSpawn = false; - if (!world.provider.isSurfaceWorld()) - { - // 1 per gen - int coordY = 10 + random.nextInt(25); - - if (world.isAirBlock(coordX, coordY - 2, coordZ) && - canBlockReplaceAt(world, coordX, coordY - 1, coordZ, Blocks.end_stone) && - canBlockReplaceAt(world, coordX, coordY, coordZ, Blocks.end_stone)) - { - doSpawn = true; - } - - if (doSpawn) - { - world.setBlock(coordX, coordY, coordZ, Config.hive, HiveType.OBLIVION.ordinal(), 3); - if (logSpawns) - LogHelper.info("Spawning oblivion hive at: X " + coordX + ", Y: " + coordY + ", Z: " + coordZ); - - int obsidianSpikeHeight = random.nextInt(8) + 2; - - for (int i = 1; i < obsidianSpikeHeight && coordY - i > 0; ++i) - { - world.setBlock(coordX, coordY - i, coordZ, Blocks.obsidian, 0, 2); - } - } - } - else if (Config.doSpecialHiveGen && world.rand.nextInt() < 8) - { - // 1 per gen - int coordY = random.nextInt(5) + 5; - - do - { - --coordY; - - if (!world.isAirBlock(coordX, coordY, coordZ) && - canBlockReplaceAt(world, coordX, coordY, coordZ, Blocks.stone) || - canBlockReplaceAt(world, coordX, coordY, coordZ, Blocks.end_stone)) - { - doSpawn = getSurroundCount(world, coordX, coordY, coordZ, Blocks.end_stone) >= 5 || - getSurroundCount(world, coordX, coordY, coordZ, Blocks.stone) >= 5; - } - } - while (!doSpawn && coordY > 5); - - if (doSpawn) - { - world.setBlock(coordX, coordY, coordZ, Config.hive, HiveType.OBLIVION.ordinal(), 3); - if (logSpawns) - LogHelper.info("Spawning oblivion hive at: X " + coordX + ", Y: " + coordY + ", Z: " + coordZ); - - endStoneGen.generateVein(world, random, coordX + 1, coordY, coordZ, world.rand.nextInt(6) + 1); - endStoneGen.generateVein(world, random, coordX - 1, coordY, coordZ, world.rand.nextInt(6) + 1); - endStoneGen.generateVein(world, random, coordX, coordY + 1, coordZ, world.rand.nextInt(3) + 1); - endStoneGen.generateVein(world, random, coordX, coordY - 1, coordZ, world.rand.nextInt(3) + 1); - endStoneGen.generateVein(world, random, coordX, coordY, coordZ + 1, world.rand.nextInt(6) + 1); - endStoneGen.generateVein(world, random, coordX, coordY, coordZ - 1, world.rand.nextInt(6) + 1); - } - } - return doSpawn; - } - - private static int getHeight(World world, Random random, int coordX, int coordZ) - { - BiomeGenBase biome = world.getBiomeGenForCoords(coordX, coordZ); - int min = (int)(biome.rootHeight/*minHeight*/ * 64 + 62); - int max = (int)(biome.heightVariation/*maxHeight*/ * 64); - // sanity - min = (min > 1) ? min : 1; - max = (max > 10) ? max : 10; - return min + random.nextInt(max); - } - - // Determines if surrounding material is "equivalent" to provided block using isGenMineableReplaceable. - private static int getSurroundCount(World world, int x, int y, int z, Block blockType) - { - int surroundCount = 0; - - if (canBlockReplaceAt(world, x + 1, y, z, blockType)) - { - ++surroundCount; - } - - if (canBlockReplaceAt(world, x - 1, y, z, blockType)) - { - ++surroundCount; - } - - if (canBlockReplaceAt(world, x, y + 1, z, blockType)) - { - ++surroundCount; - } - - if (canBlockReplaceAt(world, x, y - 1, z, blockType)) - { - ++surroundCount; - } - - if (canBlockReplaceAt(world, x, y, z + 1, blockType)) - { - ++surroundCount; - } - - if (canBlockReplaceAt(world, x, y, z - 1, blockType)) - { - ++surroundCount; - } - - return surroundCount; - } - - private static boolean canBlockReplaceAt(World world, int x, int y, int z, Block block) - { - return world.getBlock(x, y, z) != null && - world.getBlock(x, y, z).isReplaceableOreGen(world, x, y, z, block); - } -} diff --git a/src/main/java/magicbees/world/feature/FeatureOreVein.java b/src/main/java/magicbees/world/feature/FeatureOreVein.java index 661a695..814861f 100644 --- a/src/main/java/magicbees/world/feature/FeatureOreVein.java +++ b/src/main/java/magicbees/world/feature/FeatureOreVein.java @@ -3,13 +3,29 @@ package magicbees.world.feature; import java.util.Random; import net.minecraft.block.Block; +import net.minecraft.init.Blocks; import net.minecraft.world.World; +import magicbees.main.utils.BlockUtil; + public class FeatureOreVein { - private Block veinBlock; - private int veinBlockMeta; - private Block replacesBlock; + public static final FeatureOreVein redstoneGen; + public static final FeatureOreVein netherQuartzGen; + public static final FeatureOreVein glowstoneGen; + public static final FeatureOreVein endStoneGen; + + static + { + redstoneGen = new FeatureOreVein(Blocks.redstone_ore, Blocks.stone); + netherQuartzGen = new FeatureOreVein(Blocks.quartz_ore, Blocks.netherrack); + glowstoneGen = new FeatureOreVein(Blocks.glowstone, Blocks.stone); + endStoneGen = new FeatureOreVein(Blocks.end_stone, Blocks.stone); + } + + private final Block veinBlock; + private final int veinBlockMeta; + private final Block replacesBlock; public FeatureOreVein(Block block, Block replacesBlock) { @@ -35,7 +51,7 @@ public class FeatureOreVein { ++spawnAttempts; - if (!world.isAirBlock(currentX, currentY, currentZ) && canBlockReplaceAt(world, currentX, currentY, currentZ, replacesBlock)) + if (!world.isAirBlock(currentX, currentY, currentZ) && BlockUtil.canBlockReplaceAt(world, currentX, currentY, currentZ, replacesBlock)) { world.setBlock(currentX, currentY, currentZ, this.veinBlock, this.veinBlockMeta, 2); ++spawnCount; @@ -64,10 +80,4 @@ public class FeatureOreVein } } } - - private static boolean canBlockReplaceAt(World world, int x, int y, int z, Block block) - { - return world.getBlock(x, y, z) != null && - world.getBlock(x, y, z).isReplaceableOreGen(world, x, y, z, block); - } } diff --git a/src/main/java/magicbees/world/feature/HiveGenNether.java b/src/main/java/magicbees/world/feature/HiveGenNether.java new file mode 100644 index 0000000..436a573 --- /dev/null +++ b/src/main/java/magicbees/world/feature/HiveGenNether.java @@ -0,0 +1,34 @@ +package magicbees.world.feature; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +public class HiveGenNether extends HiveGenUnderground { + + public HiveGenNether(int minLevel, int range, int surroundCount) + { + super(minLevel, range, Blocks.netherrack, surroundCount); + } + + @Override + public int getYForHive(World world, int x, int z) + { + int y = super.getYForHive(world, x, z); + + if (!isValidLocation(world, x, y, z)) + { + int searchDirection = world.rand.nextBoolean() ? 4 : -4; + while (!Block.isEqualTo(world.getBlock(x, y, z), replace)) + { + y += searchDirection; + if (y < minLevel || y > minLevel + range) + { + return -1; + } + } + } + + return y; + } +} diff --git a/src/main/java/magicbees/world/feature/HiveGenOblivion.java b/src/main/java/magicbees/world/feature/HiveGenOblivion.java new file mode 100644 index 0000000..671305d --- /dev/null +++ b/src/main/java/magicbees/world/feature/HiveGenOblivion.java @@ -0,0 +1,63 @@ +package magicbees.world.feature; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import forestry.api.apiculture.hives.IHiveGen; + +import magicbees.main.utils.BlockUtil; + +public class HiveGenOblivion implements IHiveGen { + + @Override + public int getYForHive(World world, int x, int z) { + + int surface = world.getHeightValue(x, z); + if (surface == 0) + { + return -1; + } + + int y = 10; + + // get to the end stone + while (!Block.isEqualTo(world.getBlock(x, y - 1, z), Blocks.end_stone) && y < surface) + { + y += 8; + } + + // hive must be embedded one deep into the stone + while (!Block.isEqualTo(world.getBlock(x, y - 2, z), Blocks.air) && y > -1) + { + y--; + } + + return y; + } + + @Override + public boolean isValidLocation(World world, int x, int y, int z) { + + if (BlockUtil.getSurroundCount(world, x, y, z, Blocks.end_stone) != 6) + { + return false; + } + + for (int i = 2; i < 4; i++) + { + if (!world.isAirBlock(x, y - i, z)) + { + return false; + } + } + + return true; + } + + @Override + public boolean canReplace(World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + return Block.isEqualTo(block, Blocks.end_stone); + } +} diff --git a/src/main/java/magicbees/world/feature/HiveGenUnderground.java b/src/main/java/magicbees/world/feature/HiveGenUnderground.java new file mode 100644 index 0000000..6a628fd --- /dev/null +++ b/src/main/java/magicbees/world/feature/HiveGenUnderground.java @@ -0,0 +1,47 @@ +package magicbees.world.feature; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import forestry.api.apiculture.hives.IHiveGen; + +import magicbees.main.utils.BlockUtil; + +public class HiveGenUnderground implements IHiveGen +{ + protected final int minLevel; + protected final int range; + protected final Block replace; + private final int surroundCount; + + public HiveGenUnderground(int minLevel, int range, int surroundCount) { + this(minLevel, range, Blocks.stone, surroundCount); + } + + public HiveGenUnderground(int minLevel, int range, Block replace, int surroundCount) + { + this.minLevel = minLevel; + this.range = range; + this.replace = replace; + this.surroundCount = surroundCount; + } + + @Override + public int getYForHive(World world, int x, int z) + { + return minLevel + world.rand.nextInt(range); + } + + @Override + public boolean isValidLocation(World world, int x, int y, int z) + { + return BlockUtil.getSurroundCount(world, x, y, z, replace) >= surroundCount; + } + + @Override + public boolean canReplace(World world, int x, int y, int z) + { + return !world.isAirBlock(x, y, z) && BlockUtil.canBlockReplaceAt(world, x, y, z, replace); + } +}