mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-25 14:24:42 +00:00
Clean and simplify the implementation of hives through the API
This commit is contained in:
1 parent
fae3b3d24e
commit
04d6b979ab
18 files changed
+487
-310
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<IHiveDrop> drops = new ArrayList<IHiveDrop>();
|
||||
|
||||
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<IHiveDrop> drops) {
|
||||
this.drops.addAll(drops);
|
||||
}
|
||||
|
||||
public List<IHiveDrop> 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);
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.railcraft.info/>
|
||||
@@ -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)
|
||||
|
||||
@@ -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<EnumHumidity> humidities;
|
||||
private final EnumSet<EnumTemperature> temperatures;
|
||||
private final IHiveGen hiveGen;
|
||||
|
||||
private HiveDescription(int meta, float genChance, EnumSet<EnumHumidity> humidities, EnumSet<EnumTemperature> 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) {
|
||||
|
||||
}
|
||||
}
|
||||
+44
-4
@@ -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);
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+29
-33
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<Material> groundMaterials = new HashSet<Material>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
+31
-28
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<String, Hive> hives = new HashMap<String, Hive>();
|
||||
|
||||
@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<IHiveDrop> drops) {
|
||||
Hive hive = hives.get(hiveName);
|
||||
if (hive == null)
|
||||
throw new IllegalArgumentException("No hive registered with name: " + hiveName);
|
||||
|
||||
hive.addDrops(drops);
|
||||
}
|
||||
|
||||
public List<Hive> getHives() {
|
||||
return new ArrayList<Hive>(hives.values());
|
||||
}
|
||||
|
||||
public List<IHiveDrop> getDrops(String hiveName) {
|
||||
Hive hive = hives.get(hiveName);
|
||||
if (hive == null)
|
||||
throw new IllegalArgumentException("No hive registered with name: " + hiveName);
|
||||
|
||||
return hive.getDrops();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user