public boolean genHive(World world, Random rand, int chunkX, int chunkZ, Hive hive) {
    if (hive.genChance() * Config.getBeehivesRate() < rand.nextFloat() * 100.0f) {
      return false;
    }

    int worldX = chunkX * 16;
    int worldZ = chunkZ * 16;

    BiomeGenBase biome = world.getBiomeGenForCoords(worldX, worldZ);
    EnumHumidity humidity = EnumHumidity.getFromValue(biome.rainfall);

    if (!hive.isGoodBiome(biome) || !hive.isGoodHumidity(humidity)) {
      return false;
    }

    for (int tries = 0; tries < 4; tries++) {
      int x = worldX + rand.nextInt(16);
      int z = worldZ + rand.nextInt(16);

      if (tryGenHive(world, x, z, hive)) {
        return true;
      }
    }

    return false;
  }
示例#2
0
 // Verify that Duplicate Quourms added to the Hive Fails
 @Test
 public void testDuplicateQuorumFailure() {
   try {
     quorum1 = new Quorum("q1test", hive, channel1);
     quorumOne = new Quorum("q1test", hive, channel1);
     fail();
   } catch (IOException e) {
   }
   assertTrue(quorum1.getList().getNodesMap().containsValue(channel1));
   assertTrue(hive.contains("q1test"));
   assertTrue(hive.getQuorumsMap().containsValue(quorum1));
   assertFalse(hive.getQuorumsMap().containsValue(quorumOne));
   assertTrue(quorum1.isAlive());
 }
示例#3
0
 // Verify that the Quorum Creation behave appropriately
 @Test
 public void testQuorumCreation() throws IOException {
   quorum1 = new Quorum("q1test", hive, channel1);
   assertEquals(quorum1.Id, "q1test");
   assertTrue(quorum1.getList().getNodesMap().containsValue(channel1));
   assertTrue(hive.contains("q1test"));
   assertTrue(quorum1.isAlive());
 }
  private void decorateHivesDebug(World world, int chunkX, int chunkZ, List<Hive> hives) {
    int worldX = chunkX * 16;
    int worldZ = chunkZ * 16;
    BiomeGenBase biome = world.getBiomeGenForCoords(worldX, worldZ);
    EnumHumidity humidity = EnumHumidity.getFromValue(biome.rainfall);

    for (int x = 0; x < 16; x++) {
      for (int z = 0; z < 16; z++) {
        Collections.shuffle(hives, world.rand);
        for (Hive hive : hives) {
          if (!hive.isGoodBiome(biome) || !hive.isGoodHumidity(humidity)) {
            continue;
          }

          tryGenHive(world, worldX + x, worldZ + z, hive);
        }
      }
    }
  }
示例#5
0
  // Remove all channels from Quorum and verify that the Quorum is removed
  @Test
  public void testRemoveAllChannels() throws IOException {
    quorum1 = new Quorum("q1test", hive, channel1);
    quorum1.addChannel(channel2);
    assertTrue(quorum1.getList().getNodesMap().containsValue(channel2));
    quorum1.addChannel(channel3);
    assertTrue(quorum1.getList().getNodesMap().containsValue(channel3));

    quorum1.removeChannel(channel1);
    quorum1.removeChannel(channel2);
    quorum1.removeChannel(channel3);
    Utility.pause(500);

    assertFalse(quorum1.getList().getNodesMap().containsValue(channel2));
    assertFalse(quorum1.getList().getNodesMap().containsValue(channel1));
    assertFalse(quorum1.getList().getNodesMap().containsValue(channel3));

    assertFalse(hive.contains("q1test"));
    assertFalse(hive.getQuorumsMap().containsValue(quorum1));
    assertFalse(quorum1.isAlive());
  }
  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) {
      return false;
    }

    Block placedBlock = world.getBlock(x, y, z);
    if (!Block.isEqualTo(hiveBlock, placedBlock)) {
      return false;
    }

    hiveBlock.onBlockAdded(world, x, y, z);
    world.markBlockForUpdate(x, y, z);

    if (!Config.generateBeehivesDebug) {
      hive.postGen(world, x, y, z);
    }
    return true;
  }
  private boolean tryGenHive(World world, int x, int z, Hive hive) {

    int y = hive.getYForHive(world, x, z);

    if (y < 0) {
      return false;
    }

    if (!hive.canReplace(world, x, y, z)) {
      return false;
    }

    BiomeGenBase biome = world.getBiomeGenForCoords(x, z);
    EnumTemperature temperature = EnumTemperature.getFromValue(biome.getFloatTemperature(x, y, z));
    if (!hive.isGoodTemperature(temperature)) {
      return false;
    }

    if (!hive.isValidLocation(world, x, y, z)) {
      return false;
    }

    return setHive(world, x, y, z, hive);
  }