From 4d0c2d1ea264261aab8bf6dace3fe5f031a203bc Mon Sep 17 00:00:00 2001 From: mezz Date: Mon, 13 Jun 2016 20:46:23 -0700 Subject: [PATCH] Fix all hives spawning with the same flower pattern around them --- .../apiculture/hives/IHiveDescription.java | 4 +- .../multiblock/TileAlvearySwarmer.java | 2 +- .../forestry/apiculture/worldgen/Hive.java | 5 ++- .../apiculture/worldgen/HiveDecorator.java | 16 ++++---- .../apiculture/worldgen/HiveDescription.java | 39 ++++++++++--------- .../worldgen/HiveDescriptionSwarmer.java | 3 +- 6 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/main/java/forestry/api/apiculture/hives/IHiveDescription.java b/src/main/java/forestry/api/apiculture/hives/IHiveDescription.java index 5b7996c2d..d86694608 100644 --- a/src/main/java/forestry/api/apiculture/hives/IHiveDescription.java +++ b/src/main/java/forestry/api/apiculture/hives/IHiveDescription.java @@ -5,6 +5,8 @@ ******************************************************************************/ package forestry.api.apiculture.hives; +import java.util.Random; + import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -46,5 +48,5 @@ public interface IHiveDescription { * Called after successful hive generation. * world, x, y, z give the location of the new hive. **/ - void postGen(World world, BlockPos pos); + void postGen(World world, Random rand, BlockPos pos); } diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearySwarmer.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearySwarmer.java index 015315ea1..27cc3ae3b 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearySwarmer.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearySwarmer.java @@ -137,7 +137,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory, int x = getPos().getX() + worldObj.rand.nextInt(40 * 2) - 40; int z = getPos().getZ() + worldObj.rand.nextInt(40 * 2) - 40; - if (HiveDecorator.tryGenHive(worldObj, x, z, hive)) { + if (HiveDecorator.tryGenHive(worldObj, worldObj.rand, x, z, hive)) { pendingSpawns.pop(); } } diff --git a/src/main/java/forestry/apiculture/worldgen/Hive.java b/src/main/java/forestry/apiculture/worldgen/Hive.java index 832ed8eba..358ec70b7 100644 --- a/src/main/java/forestry/apiculture/worldgen/Hive.java +++ b/src/main/java/forestry/apiculture/worldgen/Hive.java @@ -13,6 +13,7 @@ package forestry.apiculture.worldgen; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Random; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; @@ -52,8 +53,8 @@ public final class Hive { return hiveDescription.getGenChance(); } - public void postGen(World world, BlockPos pos) { - hiveDescription.postGen(world, pos); + public void postGen(World world, Random rand, BlockPos pos) { + hiveDescription.postGen(world, rand, pos); } public boolean isGoodBiome(Biome biome) { diff --git a/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java b/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java index 120fde160..acebc0661 100755 --- a/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java @@ -48,7 +48,7 @@ public abstract class HiveDecorator { List hives = PluginApiculture.hiveRegistry.getHives(); if (Config.generateBeehivesDebug) { - decorateHivesDebug(world, chunkX, chunkZ, hives); + decorateHivesDebug(world, rand, chunkX, chunkZ, hives); return; } @@ -72,7 +72,7 @@ public abstract class HiveDecorator { for (Hive hive : hives) { if (hive.genChance() * Config.getBeehivesAmount() >= rand.nextFloat() * 100.0f) { if (hive.isGoodBiome(biome) && hive.isGoodHumidity(humidity)) { - if (tryGenHive(world, x, z, hive)) { + if (tryGenHive(world, rand, x, z, hive)) { return; } } @@ -81,7 +81,7 @@ public abstract class HiveDecorator { } } - private static void decorateHivesDebug(World world, int chunkX, int chunkZ, List hives) { + private static void decorateHivesDebug(World world, Random rand, int chunkX, int chunkZ, List hives) { int worldX = (chunkX << 4) + 8; int worldZ = (chunkZ << 4) + 8; Biome biome = world.getBiome(new BlockPos(chunkX, 0, chunkZ)); @@ -95,13 +95,13 @@ public abstract class HiveDecorator { continue; } - tryGenHive(world, worldX + x, worldZ + z, hive); + tryGenHive(world, rand, worldX + x, worldZ + z, hive); } } } } - public static boolean tryGenHive(World world, int x, int z, Hive hive) { + public static boolean tryGenHive(World world, Random rand, int x, int z, Hive hive) { final BlockPos hivePos = hive.getPosForHive(world, x, z); @@ -123,10 +123,10 @@ public abstract class HiveDecorator { return false; } - return setHive(world, hivePos, hive); + return setHive(world, rand, hivePos, hive); } - private static boolean setHive(World world, BlockPos pos, Hive hive) { + private static boolean setHive(World world, Random rand, BlockPos pos, Hive hive) { IBlockState hiveState = hive.getHiveBlockState(); Block hiveBlock = hiveState.getBlock(); boolean placed = world.setBlockState(pos, hiveState, Constants.FLAG_BLOCK_SYNC); @@ -143,7 +143,7 @@ public abstract class HiveDecorator { hiveBlock.onBlockAdded(world, pos, state); if (!Config.generateBeehivesDebug) { - hive.postGen(world, pos); + hive.postGen(world, rand, pos); } if (Config.logHivePlacement) { diff --git a/src/main/java/forestry/apiculture/worldgen/HiveDescription.java b/src/main/java/forestry/apiculture/worldgen/HiveDescription.java index 30026f095..3cf0dcb10 100644 --- a/src/main/java/forestry/apiculture/worldgen/HiveDescription.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveDescription.java @@ -13,6 +13,7 @@ package forestry.apiculture.worldgen; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -41,23 +42,23 @@ public enum HiveDescription implements IHiveDescription { FOREST(IHiveRegistry.HiveType.FOREST, 3.0f, BeeDefinition.FOREST, HiveManager.genHelper.tree()) { @Override - public void postGen(World world, BlockPos pos) { - super.postGen(world, pos); - postGenFlowers(world, pos, flowerStates); + public void postGen(World world, Random rand, BlockPos pos) { + super.postGen(world, rand, pos); + postGenFlowers(world, rand, pos, flowerStates); } }, MEADOWS(IHiveRegistry.HiveType.MEADOWS, 1.0f, BeeDefinition.MEADOWS, HiveManager.genHelper.ground(Blocks.DIRT, Blocks.GRASS)) { @Override - public void postGen(World world, BlockPos pos) { - super.postGen(world, pos); - postGenFlowers(world, pos, flowerStates); + public void postGen(World world, Random rand, BlockPos pos) { + super.postGen(world, rand, pos); + postGenFlowers(world, rand, pos, flowerStates); } }, DESERT(IHiveRegistry.HiveType.DESERT, 1.0f, BeeDefinition.MODEST, HiveManager.genHelper.ground(Blocks.DIRT, Blocks.GRASS, Blocks.SAND, Blocks.SANDSTONE)) { @Override - public void postGen(World world, BlockPos pos) { - super.postGen(world, pos); - postGenFlowers(world, pos, cactusStates); + public void postGen(World world, Random rand, BlockPos pos) { + super.postGen(world, rand, pos); + postGenFlowers(world, rand, pos, cactusStates); } }, JUNGLE(IHiveRegistry.HiveType.JUNGLE, 6.0f, BeeDefinition.TROPICAL, HiveManager.genHelper.tree()), @@ -69,21 +70,21 @@ public enum HiveDescription implements IHiveDescription { }, SNOW(IHiveRegistry.HiveType.SNOW, 2.0f, BeeDefinition.WINTRY, HiveManager.genHelper.ground(Blocks.DIRT, Blocks.GRASS, Blocks.SNOW)) { @Override - public void postGen(World world, BlockPos pos) { + public void postGen(World world, Random rand, BlockPos pos) { BlockPos posAbove = pos.up(); if (world.isAirBlock(posAbove)) { world.setBlockState(posAbove, Blocks.SNOW_LAYER.getDefaultState(), Constants.FLAG_BLOCK_SYNC); } - postGenFlowers(world, pos, flowerStates); + postGenFlowers(world, rand, pos, flowerStates); } }, SWAMP(IHiveRegistry.HiveType.SWAMP, 2.0f, BeeDefinition.MARSHY, HiveManager.genHelper.ground(Blocks.DIRT, Blocks.GRASS)) { @Override - public void postGen(World world, BlockPos pos) { - super.postGen(world, pos); + public void postGen(World world, Random rand, BlockPos pos) { + super.postGen(world, rand, pos); - postGenFlowers(world, pos, mushroomStates); + postGenFlowers(world, rand, pos, mushroomStates); } }; @@ -146,15 +147,15 @@ public enum HiveDescription implements IHiveDescription { } @Override - public void postGen(World world, BlockPos pos) { + public void postGen(World world, Random rand, BlockPos pos) { } - protected static void postGenFlowers(World world, BlockPos hivePos, List flowerStates) { + protected static void postGenFlowers(World world, Random rand, BlockPos hivePos, List flowerStates) { int plantedCount = 0; for (int i = 0; i < 10; i++) { - int xOffset = world.rand.nextInt(8) - 4; - int zOffset = world.rand.nextInt(8) - 4; + int xOffset = rand.nextInt(8) - 4; + int zOffset = rand.nextInt(8) - 4; BlockPos blockPos = hivePos.add(xOffset, 0, zOffset); if ((xOffset == 0 && zOffset == 0) || !world.isBlockLoaded(blockPos)) { continue; @@ -165,7 +166,7 @@ public enum HiveDescription implements IHiveDescription { continue; } - IBlockState state = flowerStates.get(world.rand.nextInt(flowerStates.size())); + IBlockState state = flowerStates.get(rand.nextInt(flowerStates.size())); Block block = state.getBlock(); if (!block.canPlaceBlockAt(world, blockPos)) { continue; diff --git a/src/main/java/forestry/apiculture/worldgen/HiveDescriptionSwarmer.java b/src/main/java/forestry/apiculture/worldgen/HiveDescriptionSwarmer.java index dd195a9d6..bebcfff19 100644 --- a/src/main/java/forestry/apiculture/worldgen/HiveDescriptionSwarmer.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveDescriptionSwarmer.java @@ -12,6 +12,7 @@ package forestry.apiculture.worldgen; import java.util.Arrays; import java.util.List; +import java.util.Random; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -68,7 +69,7 @@ public class HiveDescriptionSwarmer implements IHiveDescription { } @Override - public void postGen(World world, BlockPos pos) { + public void postGen(World world, Random rand, BlockPos pos) { TileEntity tile = world.getTileEntity(pos); if (tile instanceof TileHive) { ((TileHive) tile).setContained(bees);