diff --git a/api/forestry b/api/forestry index 2ad2ee6d7..b41c05d38 160000 --- a/api/forestry +++ b/api/forestry @@ -1 +1 @@ -Subproject commit 2ad2ee6d7c4997cb463ca0a73b1463f1e6b47a2f +Subproject commit b41c05d38a2e000f1743a34aeba81a94b1c65856 diff --git a/src/main/java/forestry/apiculture/gadgets/BlockBeehives.java b/src/main/java/forestry/apiculture/gadgets/BlockBeehives.java index c40cd2514..f0f33c111 100755 --- a/src/main/java/forestry/apiculture/gadgets/BlockBeehives.java +++ b/src/main/java/forestry/apiculture/gadgets/BlockBeehives.java @@ -13,13 +13,15 @@ package forestry.apiculture.gadgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import forestry.api.apiculture.IHiveDrop; -import forestry.api.apiculture.hives.HiveManager; +import forestry.apiculture.worldgen.HiveRegistry; import forestry.api.core.Tabs; import forestry.apiculture.MaterialBeehive; import forestry.core.config.Config; import forestry.core.inventory.InvTools; import forestry.core.render.TextureManager; import forestry.core.utils.StackUtils; +import forestry.plugins.PluginApiculture; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -126,18 +128,18 @@ public class BlockBeehives extends BlockContainer { String hiveName = getHiveNameForMeta(meta); if (hiveName == null) return Collections.emptyList(); - return HiveManager.get(hiveName).getDrops(); + return PluginApiculture.hiveRegistry.getDrops(hiveName); } private String getHiveNameForMeta(int meta) { switch (meta) { - case 1: return HiveManager.forest; - case 2: return HiveManager.meadows; - case 3: return HiveManager.desert; - case 4: return HiveManager.jungle; - case 5: return HiveManager.end; - case 6: return HiveManager.snow; - case 7: return HiveManager.swamp; + case 1: return HiveRegistry.forest; + case 2: return HiveRegistry.meadows; + case 3: return HiveRegistry.desert; + case 4: return HiveRegistry.jungle; + case 5: return HiveRegistry.end; + case 6: return HiveRegistry.snow; + case 7: return HiveRegistry.swamp; } return null; } diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java index e73518279..74d6e05ac 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java @@ -25,8 +25,9 @@ import forestry.api.apiculture.IAlvearyComponent; import forestry.api.apiculture.IBee; import forestry.api.apiculture.IBeeHousing; import forestry.api.core.ForestryAPI; +import forestry.apiculture.worldgen.Hive; import forestry.apiculture.worldgen.HiveDecorator; -import forestry.apiculture.worldgen.HiveSwarmer; +import forestry.apiculture.worldgen.HiveDescriptionSwarmer; import forestry.core.inventory.TileInventoryAdapter; import forestry.core.inventory.wrappers.IInvSlot; import forestry.core.inventory.wrappers.InventoryIterator; @@ -127,7 +128,8 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory { private void trySpawnSwarm() { ItemStack toSpawn = pendingSpawns.peek(); - HiveSwarmer hive = new HiveSwarmer(128, toSpawn); + HiveDescriptionSwarmer hiveDescription = new HiveDescriptionSwarmer(toSpawn); + Hive hive = new Hive(hiveDescription); int chunkX = (xCoord + worldObj.rand.nextInt(40 * 2) - 40) / 16; int chunkZ = (zCoord + worldObj.rand.nextInt(40 * 2) - 40) / 16; diff --git a/src/main/java/forestry/apiculture/worldgen/Hive.java b/src/main/java/forestry/apiculture/worldgen/Hive.java new file mode 100644 index 000000000..ee26e6eb4 --- /dev/null +++ b/src/main/java/forestry/apiculture/worldgen/Hive.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.worldgen; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; + +import forestry.api.apiculture.IHiveDrop; +import forestry.api.apiculture.hives.IHiveDescription; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; + +public final class Hive { + + private final IHiveDescription hiveDescription; + private final List drops = new ArrayList(); + + public Hive(IHiveDescription hiveDescription) { + if (hiveDescription == null) + throw new IllegalArgumentException("Tried to create hive with null hive description"); + this.hiveDescription = hiveDescription; + } + + public Block getHiveBlock() { + return hiveDescription.getBlock(); + } + + public int getHiveMeta() { + return hiveDescription.getMeta(); + } + + public void addDrops(List drops) { + this.drops.addAll(drops); + } + + public List getDrops() { + return drops; + } + + public float genChance() { + return hiveDescription.getGenChance(); + } + + public void postGen(World world, int x, int y, int z) { + hiveDescription.postGen(world, x, y, z); + } + + public boolean isGoodBiome(BiomeGenBase biome) { + return hiveDescription.isGoodBiome(biome); + } + + public boolean isGoodHumidity(EnumHumidity humidity) { + return hiveDescription.isGoodHumidity(humidity); + } + + public boolean isGoodTemperature(EnumTemperature temperature) { + return hiveDescription.isGoodTemperature(temperature); + } + + public boolean isValidLocation(World world, int x, int y, int z) { + return hiveDescription.getHiveGen().isValidLocation(world, x, y, z); + } + + public boolean canReplace(World world, int x, int y, int z) { + return hiveDescription.getHiveGen().canReplace(world, x, y, z); + } + + public int getYForHive(World world, int x, int z) { + return hiveDescription.getHiveGen().getYForHive(world, x, z); + } +} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java b/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java index 5869040af..ce6253592 100755 --- a/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java @@ -10,22 +10,25 @@ ******************************************************************************/ package forestry.apiculture.worldgen; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import forestry.api.apiculture.hives.HiveManager; -import forestry.api.apiculture.hives.IHive; -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.core.config.Config; -import forestry.core.config.Defaults; import java.util.Random; + import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; + import net.minecraftforge.common.util.EnumHelper; import net.minecraftforge.event.terraingen.PopulateChunkEvent; import net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType; import net.minecraftforge.event.terraingen.TerrainGen; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.plugins.PluginApiculture; + /** * * @author CovertJaguar @@ -55,14 +58,15 @@ public class HiveDecorator { } private void decorateHives(World world, Random rand, int chunkX, int chunkZ) { - for (IHive hive : HiveManager.getHives()) + for (Hive hive : PluginApiculture.hiveRegistry.getHives()) { if (Config.generateBeehivesDebug) genHiveDebug(world, chunkX, chunkZ, hive); else genHive(world, rand, chunkX, chunkZ, hive); + } } - public boolean genHive(World world, Random rand, int chunkX, int chunkZ, IHive hive) { + public boolean genHive(World world, Random rand, int chunkX, int chunkZ, Hive hive) { if (hive.genChance() < rand.nextFloat() * 128.0f) return false; @@ -86,7 +90,9 @@ public class HiveDecorator { return false; } - private void genHiveDebug(World world, int worldX, int worldZ, IHive hive) { + private void genHiveDebug(World world, int chunkX, int chunkZ, Hive hive) { + int worldX = chunkX * 16; + int worldZ = chunkZ * 16; BiomeGenBase biome = world.getBiomeGenForCoords(worldX, worldZ); EnumHumidity humidity = EnumHumidity.getFromValue(biome.rainfall); @@ -98,7 +104,7 @@ public class HiveDecorator { tryGenHive(world, worldX + x, worldZ + z, hive); } - private boolean tryGenHive(World world, int x, int z, IHive hive) { + private boolean tryGenHive(World world, int x, int z, Hive hive) { int y = hive.getYForHive(world, x, z); @@ -113,13 +119,13 @@ public class HiveDecorator { if (!hive.isGoodTemperature(temperature)) return false; - if (!hive.isGoodLocation(world, x, y, z)) + if (!hive.isValidLocation(world, x, y, z)) return false; return setHive(world, x, y, z, hive); } - protected boolean setHive(World world, int x, int y, int z, IHive hive) { + protected boolean setHive(World world, int x, int y, int z, Hive hive) { Block hiveBlock = hive.getHiveBlock(); boolean placed = world.setBlock(x, y, z, hiveBlock, hive.getHiveMeta(), Defaults.FLAG_BLOCK_SYNCH); if (!placed) diff --git a/src/main/java/forestry/apiculture/worldgen/HiveDescription.java b/src/main/java/forestry/apiculture/worldgen/HiveDescription.java new file mode 100644 index 000000000..d11418b54 --- /dev/null +++ b/src/main/java/forestry/apiculture/worldgen/HiveDescription.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.worldgen; + +import java.util.EnumSet; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; + +import forestry.api.apiculture.hives.HiveManager; +import forestry.api.apiculture.hives.IHiveDescription; +import forestry.api.apiculture.hives.IHiveGen; +import forestry.api.core.BiomeHelper; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; +import forestry.core.config.ForestryBlock; + +public enum HiveDescription implements IHiveDescription { + + FOREST(1, 3.0f, EnumSet.of(EnumHumidity.NORMAL), EnumSet.of(EnumTemperature.NORMAL), HiveManager.genHelper.tree()), + MEADOWS(2, 1.0f, EnumSet.of(EnumHumidity.NORMAL), EnumSet.of(EnumTemperature.NORMAL), HiveManager.genHelper.ground(Blocks.dirt, Blocks.grass)), + DESERT(3, 1.0f, EnumSet.of(EnumHumidity.ARID), EnumSet.of(EnumTemperature.HOT), HiveManager.genHelper.ground(Blocks.sand, Blocks.sandstone)), + JUNGLE(4, 4.0f, EnumSet.of(EnumHumidity.DAMP), EnumSet.of(EnumTemperature.WARM), HiveManager.genHelper.tree()), + END(5, 4.0f, EnumSet.allOf(EnumHumidity.class), EnumSet.allOf(EnumTemperature.class), HiveManager.genHelper.ground(Blocks.end_stone)) { + @Override + public boolean isGoodBiome(BiomeGenBase biome) { + return biome.biomeID == BiomeGenBase.sky.biomeID; + } + }, + SNOW(6, 2.0f, EnumSet.allOf(EnumHumidity.class), EnumSet.of(EnumTemperature.COLD, EnumTemperature.ICY), HiveManager.genHelper.ground(Blocks.dirt, Blocks.grass, Blocks.snow)) { + @Override + public void postGen(World world, int x, int y, int z) { + if (world.isAirBlock(x, y + 1, z)) + world.setBlock(x, y + 1, z, Blocks.snow_layer, 0, 0); + } + }, + SWAMP(7, 2.0f, EnumSet.of(EnumHumidity.DAMP), EnumSet.of(EnumTemperature.NORMAL), HiveManager.genHelper.ground(Blocks.dirt, Blocks.grass)), + ; + + private final int meta; + private final float genChance; + private final EnumSet humidities; + private final EnumSet temperatures; + private final IHiveGen hiveGen; + + private HiveDescription(int meta, float genChance, EnumSet humidities, EnumSet temperatures, IHiveGen hiveGen) { + this.meta = meta; + this.genChance = genChance; + this.humidities = humidities; + this.temperatures = temperatures; + this.hiveGen = hiveGen; + } + + @Override + public IHiveGen getHiveGen() { + return hiveGen; + } + + @Override + public Block getBlock() { + return ForestryBlock.beehives.block(); + } + + @Override + public int getMeta() { + return meta; + } + + @Override + public boolean isGoodBiome(BiomeGenBase biome) { + return !BiomeHelper.isBiomeHellish(biome); + } + + @Override + public boolean isGoodHumidity(EnumHumidity humidity) { + return humidities.contains(humidity); + } + + @Override + public boolean isGoodTemperature(EnumTemperature temperature) { + return temperatures.contains(temperature); + } + + @Override + public float getGenChance() { + return genChance; + } + + @Override + public void postGen(World world, int x, int y, int z) { + + } +} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveSwarmer.java b/src/main/java/forestry/apiculture/worldgen/HiveDescriptionSwarmer.java similarity index 54% rename from src/main/java/forestry/apiculture/worldgen/HiveSwarmer.java rename to src/main/java/forestry/apiculture/worldgen/HiveDescriptionSwarmer.java index e06dca4bb..b796d70e4 100644 --- a/src/main/java/forestry/apiculture/worldgen/HiveSwarmer.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveDescriptionSwarmer.java @@ -10,23 +10,63 @@ ******************************************************************************/ package forestry.apiculture.worldgen; -import forestry.api.apiculture.hives.HiveGround; +import forestry.api.apiculture.hives.IHiveDescription; +import forestry.api.apiculture.hives.IHiveGen; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; import forestry.apiculture.gadgets.TileSwarm; import forestry.core.config.ForestryBlock; + +import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; -public class HiveSwarmer extends HiveGround { +public class HiveDescriptionSwarmer implements IHiveDescription { private final ItemStack[] bees; - public HiveSwarmer(float genChance, ItemStack... bees) { - super(ForestryBlock.beehives.block(), 8, genChance, Blocks.dirt, Blocks.grass); + public HiveDescriptionSwarmer(ItemStack... bees) { this.bees = bees; } + @Override + public IHiveGen getHiveGen() { + return new HiveGenGround(Blocks.dirt, Blocks.grass); + } + + @Override + public Block getBlock() { + return ForestryBlock.beehives.block(); + } + + @Override + public int getMeta() { + return 8; + } + + @Override + public boolean isGoodBiome(BiomeGenBase biome) { + return true; + } + + @Override + public boolean isGoodHumidity(EnumHumidity humidity) { + return true; + } + + @Override + public boolean isGoodTemperature(EnumTemperature temperature) { + return true; + } + + @Override + public float getGenChance() { + return 128.0f; + } + @Override public void postGen(World world, int x, int y, int z) { TileEntity tile = world.getTileEntity(x, y, z); diff --git a/src/main/java/forestry/apiculture/worldgen/HiveForest.java b/src/main/java/forestry/apiculture/worldgen/HiveForest.java deleted file mode 100644 index fdc25a5d7..000000000 --- a/src/main/java/forestry/apiculture/worldgen/HiveForest.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.apiculture.worldgen; - -import forestry.api.apiculture.hives.HiveTree; -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.core.config.ForestryBlock; - -public class HiveForest extends HiveTree { - - public HiveForest(float genChance) { - super(ForestryBlock.beehives.block(), 1, genChance); - } - - @Override - public boolean isGoodHumidity(EnumHumidity humidity) { - return humidity == EnumHumidity.NORMAL; - } - - @Override - public boolean isGoodTemperature(EnumTemperature temperature) { - return temperature == EnumTemperature.NORMAL; - } -} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveJungle.java b/src/main/java/forestry/apiculture/worldgen/HiveGen.java similarity index 54% rename from src/main/java/forestry/apiculture/worldgen/HiveJungle.java rename to src/main/java/forestry/apiculture/worldgen/HiveGen.java index 59e1b341d..4eadb38c9 100644 --- a/src/main/java/forestry/apiculture/worldgen/HiveJungle.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveGen.java @@ -1,33 +1,29 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.apiculture.worldgen; - -import forestry.api.apiculture.hives.HiveTree; -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.core.config.ForestryBlock; - -public class HiveJungle extends HiveTree { - - public HiveJungle(float genChance) { - super(ForestryBlock.beehives.block(), 4, genChance); - } - - @Override - public boolean isGoodHumidity(EnumHumidity humidity) { - return humidity == EnumHumidity.DAMP; - } - - @Override - public boolean isGoodTemperature(EnumTemperature temperature) { - return temperature == EnumTemperature.WARM; - } -} +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.worldgen; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.world.World; + +import forestry.api.apiculture.hives.IHiveGen; + +public abstract class HiveGen implements IHiveGen { + + @Override + public boolean canReplace(World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + Material material = block.getMaterial(); + return (material.isReplaceable() && !material.isLiquid()) || + material == Material.air || + material == Material.plants; + } +} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveGenGround.java b/src/main/java/forestry/apiculture/worldgen/HiveGenGround.java new file mode 100644 index 000000000..8d7c8da33 --- /dev/null +++ b/src/main/java/forestry/apiculture/worldgen/HiveGenGround.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.worldgen; + +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.world.World; + +public class HiveGenGround extends HiveGen { + + private final Set groundMaterials = new HashSet(); + + public HiveGenGround(Block... groundBlocks) { + for (Block block : groundBlocks) + groundMaterials.add(block.getMaterial()); + } + + @Override + public boolean isValidLocation(World world, int x, int y, int z) { + Block ground = world.getBlock(x, y - 1, z); + return groundMaterials.contains(ground.getMaterial()); + } + + @Override + public int getYForHive(World world, int x, int z) { + int y = world.getHeightValue(x, z); + + // get to the ground + while (y >= 0 && (world.getBlock(x, y - 1, z).isLeaves(world, x, y - 1, z) || canReplace(world, x, y - 1, z))) { + y--; + } + + return y; + } +} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveEnd.java b/src/main/java/forestry/apiculture/worldgen/HiveGenHelper.java similarity index 59% rename from src/main/java/forestry/apiculture/worldgen/HiveEnd.java rename to src/main/java/forestry/apiculture/worldgen/HiveGenHelper.java index 1a675700a..27f0fe03d 100644 --- a/src/main/java/forestry/apiculture/worldgen/HiveEnd.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveGenHelper.java @@ -1,28 +1,31 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.apiculture.worldgen; - -import forestry.api.apiculture.hives.HiveGround; -import forestry.core.config.ForestryBlock; -import net.minecraft.init.Blocks; -import net.minecraft.world.biome.BiomeGenBase; - -public class HiveEnd extends HiveGround { - - public HiveEnd(float genChance) { - super(ForestryBlock.beehives.block(), 5, genChance, Blocks.end_stone); - } - - @Override - public boolean isGoodBiome(BiomeGenBase biome) { - return biome.biomeID == BiomeGenBase.sky.biomeID; - } -} +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.worldgen; + +import net.minecraft.block.Block; + +import forestry.api.apiculture.hives.IHiveGen; +import forestry.api.apiculture.hives.IHiveGenHelper; + +public class HiveGenHelper implements IHiveGenHelper { + + private static IHiveGen treeGen = new HiveGenTree(); + + @Override + public IHiveGen ground(Block... validGroundBlocks) { + return new HiveGenGround(validGroundBlocks); + } + + @Override + public IHiveGen tree() { + return treeGen; + } +} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveGenTree.java b/src/main/java/forestry/apiculture/worldgen/HiveGenTree.java new file mode 100644 index 000000000..32e0079c7 --- /dev/null +++ b/src/main/java/forestry/apiculture/worldgen/HiveGenTree.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.worldgen; + +import net.minecraft.block.Block; +import net.minecraft.world.World; + +public class HiveGenTree extends HiveGen { + + @Override + public boolean isValidLocation(World world, int x, int y, int z) { + Block blockAbove = world.getBlock(x, y + 1, z); + if (!blockAbove.isLeaves(world, x, y + 1, z)) + return false; + + // not a good location if right on top of something + return canReplace(world, x, y - 1, z); + } + + @Override + public int getYForHive(World world, int x, int z) { + // get top leaf block + int y = world.getHeightValue(x, z) - 1; + if (!world.getBlock(x, y, z).isLeaves(world, x, y, z)) + return -1; + + // get to the bottom of the leaves + do { y--; } while (world.getBlock(x, y, z).isLeaves(world, x, y, z)); + + return y; + } +} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveMeadows.java b/src/main/java/forestry/apiculture/worldgen/HiveMeadows.java deleted file mode 100644 index 4917582cc..000000000 --- a/src/main/java/forestry/apiculture/worldgen/HiveMeadows.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.apiculture.worldgen; - -import forestry.api.apiculture.hives.HiveGround; -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.core.config.ForestryBlock; -import net.minecraft.init.Blocks; - -public class HiveMeadows extends HiveGround { - - public HiveMeadows(float genChance) { - super(ForestryBlock.beehives.block(), 2, genChance, Blocks.dirt, Blocks.grass); - } - - @Override - public boolean isGoodHumidity(EnumHumidity humidity) { - return humidity == EnumHumidity.NORMAL; - } - - @Override - public boolean isGoodTemperature(EnumTemperature temperature) { - return temperature == EnumTemperature.NORMAL; - } -} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveParched.java b/src/main/java/forestry/apiculture/worldgen/HiveParched.java deleted file mode 100644 index 45e478258..000000000 --- a/src/main/java/forestry/apiculture/worldgen/HiveParched.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.apiculture.worldgen; - -import forestry.api.apiculture.hives.HiveGround; -import forestry.api.core.BiomeHelper; -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.core.config.ForestryBlock; -import net.minecraft.init.Blocks; -import net.minecraft.world.biome.BiomeGenBase; - -public class HiveParched extends HiveGround { - - public HiveParched(float genChance) { - super(ForestryBlock.beehives.block(), 3, genChance, Blocks.sand, Blocks.sandstone); - } - - @Override - public boolean isGoodBiome(BiomeGenBase biome) { - return !BiomeHelper.canRainOrSnow(biome); - } - - @Override - public boolean isGoodHumidity(EnumHumidity humidity) { - return humidity == EnumHumidity.ARID; - } - - @Override - public boolean isGoodTemperature(EnumTemperature temperature) { - return temperature == EnumTemperature.HOT; - } -} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveRegistry.java b/src/main/java/forestry/apiculture/worldgen/HiveRegistry.java new file mode 100644 index 000000000..d15b3bc86 --- /dev/null +++ b/src/main/java/forestry/apiculture/worldgen/HiveRegistry.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.worldgen; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import forestry.api.apiculture.IHiveDrop; +import forestry.api.apiculture.hives.IHiveDescription; +import forestry.api.apiculture.hives.IHiveRegistry; + +public class HiveRegistry implements IHiveRegistry { + + private final Map hives = new HashMap(); + + @Override + public void registerHive(String hiveName, IHiveDescription hiveDescription) { + if (hives.containsKey(hiveName)) + throw new IllegalArgumentException("Hive already exists with name: " + hiveName); + + Hive hive = new Hive(hiveDescription); + hives.put(hiveName, hive); + } + + @Override + public void addDrops(String hiveName, List drops) { + Hive hive = hives.get(hiveName); + if (hive == null) + throw new IllegalArgumentException("No hive registered with name: " + hiveName); + + hive.addDrops(drops); + } + + public List getHives() { + return new ArrayList(hives.values()); + } + + public List getDrops(String hiveName) { + Hive hive = hives.get(hiveName); + if (hive == null) + throw new IllegalArgumentException("No hive registered with name: " + hiveName); + + return hive.getDrops(); + } +} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveSnow.java b/src/main/java/forestry/apiculture/worldgen/HiveSnow.java deleted file mode 100644 index deafc8802..000000000 --- a/src/main/java/forestry/apiculture/worldgen/HiveSnow.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.apiculture.worldgen; - -import forestry.api.apiculture.hives.HiveGround; -import forestry.api.core.EnumTemperature; -import forestry.core.config.ForestryBlock; -import net.minecraft.init.Blocks; -import net.minecraft.world.World; - -public class HiveSnow extends HiveGround { - - public HiveSnow(float genChance) { - super(ForestryBlock.beehives.block(), 6, genChance, Blocks.dirt, Blocks.grass, Blocks.snow); - } - - @Override - public boolean isGoodTemperature(EnumTemperature temperature) { - return temperature == EnumTemperature.COLD || temperature == EnumTemperature.ICY; - } - - @Override - public void postGen(World world, int x, int y, int z) { - if (world.isAirBlock(x, y + 1, z)) - world.setBlock(x, y + 1, z, Blocks.snow_layer, 0, 0); - } -} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveSwamp.java b/src/main/java/forestry/apiculture/worldgen/HiveSwamp.java deleted file mode 100644 index efa47f548..000000000 --- a/src/main/java/forestry/apiculture/worldgen/HiveSwamp.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.apiculture.worldgen; - -import forestry.api.apiculture.hives.HiveGround; -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.core.config.ForestryBlock; -import net.minecraft.init.Blocks; - -public class HiveSwamp extends HiveGround { - - public HiveSwamp(float genChance) { - super(ForestryBlock.beehives.block(), 7, genChance, Blocks.dirt, Blocks.grass); - } - - @Override - public boolean isGoodHumidity(EnumHumidity humidity) { - return humidity == EnumHumidity.DAMP; - } - - @Override - public boolean isGoodTemperature(EnumTemperature temperature) { - return temperature == EnumTemperature.NORMAL; - } -} diff --git a/src/main/java/forestry/plugins/PluginApiculture.java b/src/main/java/forestry/plugins/PluginApiculture.java index b8afe45e0..994ac171b 100644 --- a/src/main/java/forestry/plugins/PluginApiculture.java +++ b/src/main/java/forestry/plugins/PluginApiculture.java @@ -51,7 +51,6 @@ import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeRoot; import forestry.api.apiculture.IHiveDrop; import forestry.api.apiculture.hives.HiveManager; -import forestry.api.apiculture.hives.IHive; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.core.Tabs; @@ -132,13 +131,9 @@ import forestry.apiculture.items.ItemWaxCast; import forestry.apiculture.proxy.ProxyApiculture; import forestry.apiculture.trigger.ApicultureTriggers; import forestry.apiculture.worldgen.HiveDecorator; -import forestry.apiculture.worldgen.HiveEnd; -import forestry.apiculture.worldgen.HiveForest; -import forestry.apiculture.worldgen.HiveJungle; -import forestry.apiculture.worldgen.HiveMeadows; -import forestry.apiculture.worldgen.HiveParched; -import forestry.apiculture.worldgen.HiveSnow; -import forestry.apiculture.worldgen.HiveSwamp; +import forestry.apiculture.worldgen.HiveDescription; +import forestry.apiculture.worldgen.HiveGenHelper; +import forestry.apiculture.worldgen.HiveRegistry; import forestry.core.GameMode; import forestry.core.config.Config; import forestry.core.config.Configuration; @@ -186,6 +181,8 @@ public class PluginApiculture extends ForestryPlugin { * See {@link IBeeRoot} for details */ public static IBeeRoot beeInterface; + public static HiveRegistry hiveRegistry; + public static MachineDefinition definitionApiary; public static MachineDefinition definitionChest; public static MachineDefinition definitionBeehouse; @@ -198,6 +195,8 @@ public class PluginApiculture extends ForestryPlugin { MinecraftForge.EVENT_BUS.register(this); + HiveManager.hiveRegistry = hiveRegistry = new HiveRegistry(); + HiveManager.genHelper = new HiveGenHelper(); createHiveDropArrays(); ForestryBlock.apiculture.registerBlock(new BlockBase(Material.iron), ItemForestryBlock.class, "apiculture"); @@ -790,44 +789,23 @@ public class PluginApiculture extends ForestryPlugin { } private void createHives() { - HiveManager.put(HiveManager.forest, new HiveForest(3)); - HiveManager.put(HiveManager.meadows, new HiveMeadows(1)); - HiveManager.put(HiveManager.desert, new HiveParched(1)); - HiveManager.put(HiveManager.jungle, new HiveJungle(4)); - HiveManager.put(HiveManager.end, new HiveEnd(4)); - HiveManager.put(HiveManager.snow, new HiveSnow(2)); - HiveManager.put(HiveManager.swamp, new HiveSwamp(2)); + hiveRegistry.registerHive(HiveRegistry.forest, HiveDescription.FOREST); + hiveRegistry.registerHive(HiveRegistry.meadows, HiveDescription.MEADOWS); + hiveRegistry.registerHive(HiveRegistry.desert, HiveDescription.DESERT); + hiveRegistry.registerHive(HiveRegistry.jungle, HiveDescription.JUNGLE); + hiveRegistry.registerHive(HiveRegistry.end, HiveDescription.END); + hiveRegistry.registerHive(HiveRegistry.snow, HiveDescription.SNOW); + hiveRegistry.registerHive(HiveRegistry.swamp, HiveDescription.SWAMP); } - @Deprecated // deprecated since 3.1. remove when BeeManager.hiveDrops is removed private void updateHiveDrops() { - IHive hive = HiveManager.getForestHive(); - for (IHiveDrop drop : forestDrops) - hive.addDrop(drop); - - hive = HiveManager.getMeadowsHive(); - for (IHiveDrop drop : meadowsDrops) - hive.addDrop(drop); - - hive = HiveManager.getDesertHive(); - for (IHiveDrop drop : desertDrops) - hive.addDrop(drop); - - hive = HiveManager.getJungleHive(); - for (IHiveDrop drop : jungleDrops) - hive.addDrop(drop); - - hive = HiveManager.getEndHive(); - for (IHiveDrop drop : endDrops) - hive.addDrop(drop); - - hive = HiveManager.getSnowHive(); - for (IHiveDrop drop : snowDrops) - hive.addDrop(drop); - - hive = HiveManager.getSwampHive(); - for (IHiveDrop drop : swampDrops) - hive.addDrop(drop); + hiveRegistry.addDrops(HiveRegistry.forest, forestDrops); + hiveRegistry.addDrops(HiveRegistry.meadows, meadowsDrops); + hiveRegistry.addDrops(HiveRegistry.desert, desertDrops); + hiveRegistry.addDrops(HiveRegistry.jungle, jungleDrops); + hiveRegistry.addDrops(HiveRegistry.end, endDrops); + hiveRegistry.addDrops(HiveRegistry.snow, snowDrops); + hiveRegistry.addDrops(HiveRegistry.swamp, swampDrops); } private void createAlleles() {