From 1fda3b3b2ef84bb6cb49636502966a45573ee370 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Fri, 21 Apr 2017 11:27:41 +1000 Subject: [PATCH] Added hive generation --- .../biomesoplenty/api/biome/BOPBiomes.java | 1 + .../common/biome/nether/BOPHellBiome.java | 5 + .../common/biome/vanilla/BiomeExtHell.java | 37 +++ .../biomesoplenty/common/init/ModBiomes.java | 131 +--------- .../common/init/ModGenerators.java | 21 +- .../common/item/ItemFlippers.java | 115 --------- .../common/util/biome/GeneratorUtils.java | 7 +- .../common/world/generator/GeneratorHive.java | 241 ++++++++++++++++++ 8 files changed, 295 insertions(+), 263 deletions(-) create mode 100644 src/main/java/biomesoplenty/common/biome/vanilla/BiomeExtHell.java create mode 100644 src/main/java/biomesoplenty/common/world/generator/GeneratorHive.java diff --git a/src/main/java/biomesoplenty/api/biome/BOPBiomes.java b/src/main/java/biomesoplenty/api/biome/BOPBiomes.java index a2bb03e0b..116a2aa08 100644 --- a/src/main/java/biomesoplenty/api/biome/BOPBiomes.java +++ b/src/main/java/biomesoplenty/api/biome/BOPBiomes.java @@ -129,6 +129,7 @@ public class BOPBiomes public static IExtendedBiome cold_taiga_hills_extension; public static IExtendedBiome mega_taiga_extension; public static IExtendedBiome mega_taiga_hills_extension; + public static IExtendedBiome hell_extension; private static IBiomeRegistry createRegistry() { diff --git a/src/main/java/biomesoplenty/common/biome/nether/BOPHellBiome.java b/src/main/java/biomesoplenty/common/biome/nether/BOPHellBiome.java index 4915df353..eef0cf29d 100644 --- a/src/main/java/biomesoplenty/common/biome/nether/BOPHellBiome.java +++ b/src/main/java/biomesoplenty/common/biome/nether/BOPHellBiome.java @@ -17,6 +17,9 @@ import biomesoplenty.api.generation.GeneratorStage; import biomesoplenty.api.generation.IGenerationManager; import biomesoplenty.api.generation.IGenerator; import biomesoplenty.common.biome.BOPBiome; +import biomesoplenty.common.util.biome.GeneratorUtils; +import biomesoplenty.common.world.generator.GeneratorHive; +import biomesoplenty.common.world.generator.GeneratorSplatter; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.monster.EntityEnderman; @@ -54,6 +57,8 @@ public class BOPHellBiome extends BOPBiome this.spawnableMonsterList.add(new Biome.SpawnListEntry(EntityPigZombie.class, 100, 4, 4)); this.spawnableMonsterList.add(new Biome.SpawnListEntry(EntityMagmaCube.class, 2, 4, 4)); this.spawnableMonsterList.add(new Biome.SpawnListEntry(EntityEnderman.class, 1, 4, 4)); + + this.addGenerator("hive", GeneratorStage.PRE, (new GeneratorHive.Builder()).amountPerChunk(4.0F).create()); } @Override diff --git a/src/main/java/biomesoplenty/common/biome/vanilla/BiomeExtHell.java b/src/main/java/biomesoplenty/common/biome/vanilla/BiomeExtHell.java new file mode 100644 index 000000000..37745477b --- /dev/null +++ b/src/main/java/biomesoplenty/common/biome/vanilla/BiomeExtHell.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright 2014-2017, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ +package biomesoplenty.common.biome.vanilla; + +import biomesoplenty.api.generation.GeneratorStage; +import biomesoplenty.common.world.generator.GeneratorHive; +import net.minecraft.init.Biomes; +import net.minecraft.init.Blocks; +import net.minecraft.world.biome.BiomeDecorator; + +public class BiomeExtHell extends ExtendedBiomeWrapper +{ + public BiomeExtHell() + { + super(Biomes.HELL); + + // setup hell as a properly decorated biome + Biomes.HELL.topBlock = Blocks.NETHERRACK.getDefaultState(); + Biomes.HELL.fillerBlock = Blocks.NETHERRACK.getDefaultState(); + + Biomes.HELL.theBiomeDecorator = new BiomeDecorator(); + Biomes.HELL.theBiomeDecorator.treesPerChunk = -999; + Biomes.HELL.theBiomeDecorator.flowersPerChunk = -999; + Biomes.HELL.theBiomeDecorator.grassPerChunk = -999; + Biomes.HELL.theBiomeDecorator.sandPerChunk = -999; + Biomes.HELL.theBiomeDecorator.sandPerChunk2 = -999; + //this.theBiomeDecorator.generateLakes = false; + + this.addGenerator("hive", GeneratorStage.PRE, (new GeneratorHive.Builder()).amountPerChunk(4.0F).create()); + } +} + diff --git a/src/main/java/biomesoplenty/common/init/ModBiomes.java b/src/main/java/biomesoplenty/common/init/ModBiomes.java index 9a8ea45c4..134a22e2f 100644 --- a/src/main/java/biomesoplenty/common/init/ModBiomes.java +++ b/src/main/java/biomesoplenty/common/init/ModBiomes.java @@ -8,105 +8,7 @@ package biomesoplenty.common.init; -import static biomesoplenty.api.biome.BOPBiomes.alps; -import static biomesoplenty.api.biome.BOPBiomes.bamboo_forest; -import static biomesoplenty.api.biome.BOPBiomes.bayou; -import static biomesoplenty.api.biome.BOPBiomes.birch_forest_extension; -import static biomesoplenty.api.biome.BOPBiomes.birch_forest_hills_extension; -import static biomesoplenty.api.biome.BOPBiomes.bog; -import static biomesoplenty.api.biome.BOPBiomes.boneyard; -import static biomesoplenty.api.biome.BOPBiomes.boreal_forest; -import static biomesoplenty.api.biome.BOPBiomes.brushland; -import static biomesoplenty.api.biome.BOPBiomes.chaparral; -import static biomesoplenty.api.biome.BOPBiomes.cherry_blossom_grove; -import static biomesoplenty.api.biome.BOPBiomes.cold_desert; -import static biomesoplenty.api.biome.BOPBiomes.cold_taiga_extension; -import static biomesoplenty.api.biome.BOPBiomes.cold_taiga_hills_extension; -import static biomesoplenty.api.biome.BOPBiomes.coniferous_forest; -import static biomesoplenty.api.biome.BOPBiomes.coral_reef; -import static biomesoplenty.api.biome.BOPBiomes.corrupted_sands; -import static biomesoplenty.api.biome.BOPBiomes.crag; -import static biomesoplenty.api.biome.BOPBiomes.dead_forest; -import static biomesoplenty.api.biome.BOPBiomes.dead_swamp; -import static biomesoplenty.api.biome.BOPBiomes.desert_extension; -import static biomesoplenty.api.biome.BOPBiomes.desert_hills_extension; -import static biomesoplenty.api.biome.BOPBiomes.end_extension; -import static biomesoplenty.api.biome.BOPBiomes.eucalyptus_forest; -import static biomesoplenty.api.biome.BOPBiomes.excludedDecoratedWorldTypes; -import static biomesoplenty.api.biome.BOPBiomes.extreme_hills_extension; -import static biomesoplenty.api.biome.BOPBiomes.extreme_hills_plus_extension; -import static biomesoplenty.api.biome.BOPBiomes.fen; -import static biomesoplenty.api.biome.BOPBiomes.flower_field; -import static biomesoplenty.api.biome.BOPBiomes.flower_island; -import static biomesoplenty.api.biome.BOPBiomes.forest_extension; -import static biomesoplenty.api.biome.BOPBiomes.forest_hills_extension; -import static biomesoplenty.api.biome.BOPBiomes.fungi_forest; -import static biomesoplenty.api.biome.BOPBiomes.glacier; -import static biomesoplenty.api.biome.BOPBiomes.grassland; -import static biomesoplenty.api.biome.BOPBiomes.gravel_beach; -import static biomesoplenty.api.biome.BOPBiomes.grove; -import static biomesoplenty.api.biome.BOPBiomes.heathland; -import static biomesoplenty.api.biome.BOPBiomes.highland; -import static biomesoplenty.api.biome.BOPBiomes.ice_mountains_extension; -import static biomesoplenty.api.biome.BOPBiomes.ice_plains_extension; -import static biomesoplenty.api.biome.BOPBiomes.jungle_extension; -import static biomesoplenty.api.biome.BOPBiomes.jungle_hills_extension; -import static biomesoplenty.api.biome.BOPBiomes.kelp_forest; -import static biomesoplenty.api.biome.BOPBiomes.land_of_lakes; -import static biomesoplenty.api.biome.BOPBiomes.lavender_fields; -import static biomesoplenty.api.biome.BOPBiomes.lush_desert; -import static biomesoplenty.api.biome.BOPBiomes.lush_swamp; -import static biomesoplenty.api.biome.BOPBiomes.mangrove; -import static biomesoplenty.api.biome.BOPBiomes.maple_woods; -import static biomesoplenty.api.biome.BOPBiomes.marsh; -import static biomesoplenty.api.biome.BOPBiomes.meadow; -import static biomesoplenty.api.biome.BOPBiomes.mega_taiga_extension; -import static biomesoplenty.api.biome.BOPBiomes.mega_taiga_hills_extension; -import static biomesoplenty.api.biome.BOPBiomes.mesa_extension; -import static biomesoplenty.api.biome.BOPBiomes.mesa_plateau_extension; -import static biomesoplenty.api.biome.BOPBiomes.moor; -import static biomesoplenty.api.biome.BOPBiomes.mountain; -import static biomesoplenty.api.biome.BOPBiomes.mountain_foothills; -import static biomesoplenty.api.biome.BOPBiomes.mushroom_island_extension; -import static biomesoplenty.api.biome.BOPBiomes.mystic_grove; -import static biomesoplenty.api.biome.BOPBiomes.oasis; -import static biomesoplenty.api.biome.BOPBiomes.ocean_extension; -import static biomesoplenty.api.biome.BOPBiomes.ominous_woods; -import static biomesoplenty.api.biome.BOPBiomes.orchard; -import static biomesoplenty.api.biome.BOPBiomes.origin_island; -import static biomesoplenty.api.biome.BOPBiomes.outback; -import static biomesoplenty.api.biome.BOPBiomes.overgrown_cliffs; -import static biomesoplenty.api.biome.BOPBiomes.phantasmagoric_inferno; -import static biomesoplenty.api.biome.BOPBiomes.plains_extension; -import static biomesoplenty.api.biome.BOPBiomes.polar_chasm; -import static biomesoplenty.api.biome.BOPBiomes.prairie; -import static biomesoplenty.api.biome.BOPBiomes.quagmire; -import static biomesoplenty.api.biome.BOPBiomes.rainforest; -import static biomesoplenty.api.biome.BOPBiomes.redwood_forest; -import static biomesoplenty.api.biome.BOPBiomes.roofed_forest_extension; -import static biomesoplenty.api.biome.BOPBiomes.sacred_springs; -import static biomesoplenty.api.biome.BOPBiomes.savanna_extension; -import static biomesoplenty.api.biome.BOPBiomes.savanna_plateau_extension; -import static biomesoplenty.api.biome.BOPBiomes.seasonal_forest; -import static biomesoplenty.api.biome.BOPBiomes.shield; -import static biomesoplenty.api.biome.BOPBiomes.shrubland; -import static biomesoplenty.api.biome.BOPBiomes.snowy_coniferous_forest; -import static biomesoplenty.api.biome.BOPBiomes.snowy_forest; -import static biomesoplenty.api.biome.BOPBiomes.steppe; -import static biomesoplenty.api.biome.BOPBiomes.swampland_extension; -import static biomesoplenty.api.biome.BOPBiomes.taiga_extension; -import static biomesoplenty.api.biome.BOPBiomes.taiga_hills_extension; -import static biomesoplenty.api.biome.BOPBiomes.temperate_rainforest; -import static biomesoplenty.api.biome.BOPBiomes.tropical_island; -import static biomesoplenty.api.biome.BOPBiomes.tropical_rainforest; -import static biomesoplenty.api.biome.BOPBiomes.tundra; -import static biomesoplenty.api.biome.BOPBiomes.undergarden; -import static biomesoplenty.api.biome.BOPBiomes.visceral_heap; -import static biomesoplenty.api.biome.BOPBiomes.volcanic_island; -import static biomesoplenty.api.biome.BOPBiomes.wasteland; -import static biomesoplenty.api.biome.BOPBiomes.wetland; -import static biomesoplenty.api.biome.BOPBiomes.woodland; -import static biomesoplenty.api.biome.BOPBiomes.xeric_shrubland; +import static biomesoplenty.api.biome.BOPBiomes.*; import java.io.File; import java.io.IOException; @@ -118,6 +20,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import biomesoplenty.common.biome.vanilla.*; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; @@ -197,34 +100,6 @@ import biomesoplenty.common.biome.overworld.BiomeGenWasteland; import biomesoplenty.common.biome.overworld.BiomeGenWetland; import biomesoplenty.common.biome.overworld.BiomeGenWoodland; import biomesoplenty.common.biome.overworld.BiomeGenXericShrubland; -import biomesoplenty.common.biome.vanilla.BiomeExtBirchForest; -import biomesoplenty.common.biome.vanilla.BiomeExtBirchForestHills; -import biomesoplenty.common.biome.vanilla.BiomeExtColdTaiga; -import biomesoplenty.common.biome.vanilla.BiomeExtColdTaigaHills; -import biomesoplenty.common.biome.vanilla.BiomeExtDesert; -import biomesoplenty.common.biome.vanilla.BiomeExtDesertHills; -import biomesoplenty.common.biome.vanilla.BiomeExtEnd; -import biomesoplenty.common.biome.vanilla.BiomeExtExtremeHills; -import biomesoplenty.common.biome.vanilla.BiomeExtExtremeHillsPlus; -import biomesoplenty.common.biome.vanilla.BiomeExtForest; -import biomesoplenty.common.biome.vanilla.BiomeExtForestHills; -import biomesoplenty.common.biome.vanilla.BiomeExtIceMountains; -import biomesoplenty.common.biome.vanilla.BiomeExtIcePlains; -import biomesoplenty.common.biome.vanilla.BiomeExtJungle; -import biomesoplenty.common.biome.vanilla.BiomeExtJungleHills; -import biomesoplenty.common.biome.vanilla.BiomeExtMegaTaiga; -import biomesoplenty.common.biome.vanilla.BiomeExtMegaTaigaHills; -import biomesoplenty.common.biome.vanilla.BiomeExtMesa; -import biomesoplenty.common.biome.vanilla.BiomeExtMesaPlateau; -import biomesoplenty.common.biome.vanilla.BiomeExtMushroomIsland; -import biomesoplenty.common.biome.vanilla.BiomeExtOcean; -import biomesoplenty.common.biome.vanilla.BiomeExtPlains; -import biomesoplenty.common.biome.vanilla.BiomeExtRoofedForest; -import biomesoplenty.common.biome.vanilla.BiomeExtSavanna; -import biomesoplenty.common.biome.vanilla.BiomeExtSavannaPlateau; -import biomesoplenty.common.biome.vanilla.BiomeExtSwampland; -import biomesoplenty.common.biome.vanilla.BiomeExtTaiga; -import biomesoplenty.common.biome.vanilla.BiomeExtTaigaHills; import biomesoplenty.common.command.BOPCommand; import biomesoplenty.common.util.config.BOPConfig; import biomesoplenty.common.world.WorldProviderBOPHell; @@ -468,7 +343,7 @@ public class ModBiomes implements BOPBiomes.IBiomeRegistry swampland_extension = registerWrappedBiome(new BiomeExtSwampland(), "swampland"); taiga_extension = registerWrappedBiome(new BiomeExtTaiga(), "taiga"); taiga_hills_extension = registerWrappedBiome(new BiomeExtTaigaHills(), "taiga_hills"); - + hell_extension = registerWrappedBiome(new BiomeExtHell(), "hell"); } private static void registerBiomeDictionaryTags() diff --git a/src/main/java/biomesoplenty/common/init/ModGenerators.java b/src/main/java/biomesoplenty/common/init/ModGenerators.java index 2088f7971..2e2fac230 100644 --- a/src/main/java/biomesoplenty/common/init/ModGenerators.java +++ b/src/main/java/biomesoplenty/common/init/ModGenerators.java @@ -10,25 +10,7 @@ package biomesoplenty.common.init; import static biomesoplenty.common.world.GeneratorRegistry.registerGenerator; -import biomesoplenty.common.world.generator.GeneratorBigFlower; -import biomesoplenty.common.world.generator.GeneratorBigMushroom; -import biomesoplenty.common.world.generator.GeneratorBlobs; -import biomesoplenty.common.world.generator.GeneratorColumns; -import biomesoplenty.common.world.generator.GeneratorCrystals; -import biomesoplenty.common.world.generator.GeneratorDoubleFlora; -import biomesoplenty.common.world.generator.GeneratorFlora; -import biomesoplenty.common.world.generator.GeneratorGrass; -import biomesoplenty.common.world.generator.GeneratorLakes; -import biomesoplenty.common.world.generator.GeneratorLogs; -import biomesoplenty.common.world.generator.GeneratorMixedLily; -import biomesoplenty.common.world.generator.GeneratorOreCluster; -import biomesoplenty.common.world.generator.GeneratorOreSingle; -import biomesoplenty.common.world.generator.GeneratorSpike; -import biomesoplenty.common.world.generator.GeneratorSplatter; -import biomesoplenty.common.world.generator.GeneratorSplotches; -import biomesoplenty.common.world.generator.GeneratorVines; -import biomesoplenty.common.world.generator.GeneratorWaterside; -import biomesoplenty.common.world.generator.GeneratorWeighted; +import biomesoplenty.common.world.generator.*; import biomesoplenty.common.world.generator.tree.GeneratorBasicTree; import biomesoplenty.common.world.generator.tree.GeneratorBayouTree; import biomesoplenty.common.world.generator.tree.GeneratorBigTree; @@ -79,6 +61,7 @@ public class ModGenerators registerGenerator("mixed_lily", GeneratorMixedLily.class, new GeneratorMixedLily.Builder()); registerGenerator("crystals", GeneratorCrystals.class, new GeneratorCrystals.Builder()); registerGenerator("spike", GeneratorSpike.class, new GeneratorSpike.Builder()); + registerGenerator("hive", GeneratorHive.class, new GeneratorHive.Builder()); registerGenerator("redwood_tree", GeneratorRedwoodTree.class, new GeneratorRedwoodTree.Builder()); registerGenerator("redwood_tree_thin", GeneratorRedwoodTreeThin.class, new GeneratorRedwoodTreeThin.Builder()); registerGenerator("mahogany_tree", GeneratorMahoganyTree.class, new GeneratorMahoganyTree.Builder()); diff --git a/src/main/java/biomesoplenty/common/item/ItemFlippers.java b/src/main/java/biomesoplenty/common/item/ItemFlippers.java index 691e6041b..104722efa 100644 --- a/src/main/java/biomesoplenty/common/item/ItemFlippers.java +++ b/src/main/java/biomesoplenty/common/item/ItemFlippers.java @@ -30,120 +30,5 @@ public class ItemFlippers extends ItemArmor // flippers are always on your feet - armorType = 3 super(material, renderIndex, EntityEquipmentSlot.FEET); } - - @Override - public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) - { - ItemStack stack = player.getHeldItem(hand); - RayTraceResult rayTrace = this.rayTrace(world, player, false); - - /* if (rayTrace != null && rayTrace.typeOfHit == RayTraceResult.Type.BLOCK) - { - int halfHeight = 7; - int maxRadius = 9; - int layerSize = 3; - int bottomExtra = 4; - boolean empty = true; - BlockPos hitPos = rayTrace.getBlockPos(); - - // create the top and bottom halves of the hive, and a little bit extra on the bottom for the sake of looking - // slightly more like a hive - for (int yOffset = halfHeight; yOffset >= -halfHeight - bottomExtra; yOffset--) - { - // y is already negative, so add it rather than subtract - int radius = maxRadius + (yOffset / layerSize) * (yOffset >= 0 ? -1 : 1); - - for (int xOffset = -radius; xOffset <= radius; xOffset++) - { - for (int zOffset = -radius; zOffset <= radius; zOffset++) - { - int x2_z2 = xOffset * xOffset + zOffset * zOffset; - - // used to determine where to fill with honey - boolean bottomHalf = yOffset <= 0; - - // check to fill the top and bottom of the two layers - boolean outerCap = yOffset == -halfHeight - bottomExtra || yOffset == halfHeight; - boolean innerCap = yOffset == -halfHeight - bottomExtra + 1 || yOffset == halfHeight - 1; - - // create a circular outline for the hive. the bottom and top layers should be filled. - // add a bit extra (1) to make the circles nicer too - - // inner layer. inset by one block - if (x2_z2 <= (radius - 1) * (radius - 1) + 1 && (x2_z2 >= (radius - 2) * (radius - 2) || innerCap)) - { - IBlockState honeyComb = BOPBlocks.hive.getDefaultState().withProperty(BlockBOPHive.VARIANT, BlockBOPHive.HiveType.EMPTY_HONEYCOMB); - float f = world.rand.nextFloat(); - - if (!empty && f <= 0.95) - { - honeyComb = BOPBlocks.hive.getDefaultState().withProperty(BlockBOPHive.VARIANT, BlockBOPHive.HiveType.HONEYCOMB); - - // if on the bottom half of the hive bias more towards filled honeycomb. - // the rest of the hive can still have filled blocks though - if (f <= 0.2 || (f <= 0.65 && bottomHalf)) - { - honeyComb = BOPBlocks.hive.getDefaultState().withProperty(BlockBOPHive.VARIANT, BlockBOPHive.HiveType.FILLED_HONEYCOMB); - } - } - else if (empty && f <= 0.2) - { - honeyComb = Blocks.AIR.getDefaultState(); - } - - // offset so we're placing the hive underneath the initial y coordinate - world.setBlockState(hitPos.add(xOffset, yOffset - halfHeight, zOffset), honeyComb); - } - - // inner fill - if (!empty && bottomHalf && x2_z2 <= (radius - 2) * (radius - 2) + 1) - { - // fill the centre of the hive with honey blocks honey - IBlockState fillBlock = yOffset == 0 ? BOPBlocks.honey_block.getDefaultState() : BOPBlocks.honey.getDefaultState(); - world.setBlockState(hitPos.add(xOffset, yOffset - halfHeight, zOffset), fillBlock); - } - - // place a wasp spawner in the middle of the hive - if (!empty && yOffset == 0 && xOffset == 0 && zOffset == 0) - { - BlockPos spawnerPos = hitPos.add(xOffset, yOffset - halfHeight, zOffset); - - world.setBlockState(spawnerPos, Blocks.MOB_SPAWNER.getDefaultState(), 2); - TileEntity tileentity = world.getTileEntity(spawnerPos); - - if (tileentity instanceof TileEntityMobSpawner) - { - MobSpawnerBaseLogic spawnerLogic = ((TileEntityMobSpawner)tileentity).getSpawnerBaseLogic(); - - NBTTagCompound spawnerConfig = new NBTTagCompound(); - spawnerConfig.setShort("MinSpawnDelay", (short)100); - spawnerConfig.setShort("MaxSpawnDelay", (short)400); - spawnerConfig.setShort("SpawnCount", (short)6); - spawnerConfig.setShort("MaxNearbyEntities", (short)16); - spawnerConfig.setShort("RequiredPlayerRange", (short)24); - - spawnerLogic.readFromNBT(spawnerConfig); - spawnerLogic.setEntityId(new ResourceLocation(BiomesOPlenty.MOD_ID, "wasp")); - } - else - { - BiomesOPlenty.logger.error("Failed to fetch mob spawner entity at ({}, {}, {})", new Object[] {Integer.valueOf(spawnerPos.getX()), Integer.valueOf(spawnerPos.getY()), Integer.valueOf(spawnerPos.getZ())}); - } - } - - // outer layer - if (x2_z2 <= radius * radius + 1 && (x2_z2 >= (radius - 1) * (radius - 1) || outerCap)) - { - // offset so we're placing the hive underneath the initial y coordinate - world.setBlockState(hitPos.add(xOffset, yOffset - halfHeight, zOffset), BOPBlocks.hive.getDefaultState()); - } - } - } - } - }*/ - - - return new ActionResult(EnumActionResult.SUCCESS, stack); - } } diff --git a/src/main/java/biomesoplenty/common/util/biome/GeneratorUtils.java b/src/main/java/biomesoplenty/common/util/biome/GeneratorUtils.java index 062c9cf9f..c806bdb9c 100644 --- a/src/main/java/biomesoplenty/common/util/biome/GeneratorUtils.java +++ b/src/main/java/biomesoplenty/common/util/biome/GeneratorUtils.java @@ -83,7 +83,7 @@ public class GeneratorUtils public static enum ScatterYMethod { - ANYWHERE, NETHER_SURFACE, AT_SURFACE, AT_GROUND, BELOW_SURFACE, BELOW_GROUND, ABOVE_SURFACE, ABOVE_GROUND; + ANYWHERE, NETHER_SURFACE, NETHER_ROOF, AT_SURFACE, AT_GROUND, BELOW_SURFACE, BELOW_GROUND, ABOVE_SURFACE, ABOVE_GROUND; public BlockPos getBlockPos(World world, Random random, int x, int z) { int tempY; @@ -119,6 +119,11 @@ public class GeneratorUtils tempY = world.getHeight(new BlockPos(x, 0, z)).getY(); pos = getFirstBlockMatching(world, new BlockPos(x, nextIntBetween(random, 1, 127), z), BlockQuery.buildAnd().add(BlockQueries.solid).withAirAbove().create()); return (pos == null ? new BlockPos(x, 1, z) : pos.up()); + case NETHER_ROOF: + // random point above the nether surface + tempY = world.getHeight(new BlockPos(x, 0, z)).getY(); + pos = getFirstBlockMatching(world, new BlockPos(x, nextIntBetween(random, 1, 127), z), BlockQuery.buildAnd().add(BlockQueries.solid).withAirBelow().create()); + return (pos == null ? new BlockPos(x, 1, z) : pos.down()); case ANYWHERE: default: // random y coord return new BlockPos(x, nextIntBetween(random, 1, 255), z); diff --git a/src/main/java/biomesoplenty/common/world/generator/GeneratorHive.java b/src/main/java/biomesoplenty/common/world/generator/GeneratorHive.java new file mode 100644 index 000000000..c83ccae81 --- /dev/null +++ b/src/main/java/biomesoplenty/common/world/generator/GeneratorHive.java @@ -0,0 +1,241 @@ +/******************************************************************************* + * Copyright 2014-2017, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ +package biomesoplenty.common.world.generator; + +import biomesoplenty.api.block.BOPBlocks; +import biomesoplenty.api.block.BlockQueries; +import biomesoplenty.api.block.IBlockPosQuery; +import biomesoplenty.api.config.IConfigObj; +import biomesoplenty.common.block.BlockBOPHive; +import biomesoplenty.common.util.biome.GeneratorUtils; +import biomesoplenty.common.util.block.BlockQuery; +import biomesoplenty.core.BiomesOPlenty; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Biomes; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.MobSpawnerBaseLogic; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityMobSpawner; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.Random; + +public class GeneratorHive extends GeneratorReplacing +{ + public static class Builder extends GeneratorReplacing.InnerBuilder implements IGeneratorBuilder + { + protected int halfHeight; + protected int maxRadius; + protected int layerSize; + protected int bottomExtra; + protected float emptyChance; + + public GeneratorHive.Builder halfHeight(int a) {this.halfHeight = a; return this.self();} + public GeneratorHive.Builder maxRadius(int a) {this.maxRadius = a; return this.self();} + public GeneratorHive.Builder layerSize(int a) {this.layerSize = a; return this.self();} + public GeneratorHive.Builder bottomExtra(int a) {this.bottomExtra = a; return this.self();} + public GeneratorHive.Builder emptyChance(float a) {this.emptyChance = a; return this.self();} + + public Builder() + { + // defaults + this.amountPerChunk = 1.0F; + this.placeOn = BlockQuery.buildAnd().states(Blocks.NETHERRACK.getDefaultState()).withAirBelow().create();; + this.replace = new BlockQuery.BlockQueryMaterial(Material.AIR); + this.with = null; + this.scatterYMethod = GeneratorUtils.ScatterYMethod.NETHER_ROOF; + this.halfHeight = 7; + this.maxRadius = 9; + this.layerSize = 3; + this.bottomExtra = 4; + this.emptyChance = 0.25F; + } + + @Override + public GeneratorHive create() + { + return new GeneratorHive(this.amountPerChunk, this.placeOn, this.replace, this.with, this.scatterYMethod, this.halfHeight, this.maxRadius, this.layerSize, this.bottomExtra, this.emptyChance); + } + } + + protected int halfHeight; + protected int maxRadius; + protected int layerSize; + protected int bottomExtra; + protected float emptyChance; + + public GeneratorHive(float amountPerChunk, IBlockPosQuery placeOn, IBlockPosQuery replace, IBlockState with, GeneratorUtils.ScatterYMethod scatterYMethod, int halfHeight, int maxRadius, int layerSize, int bottomExtra, float emptyChance) + { + super(amountPerChunk, placeOn, replace, with, scatterYMethod); + this.halfHeight = halfHeight; + this.maxRadius = maxRadius; + this.layerSize = layerSize; + this.bottomExtra = bottomExtra; + this.emptyChance = emptyChance; + } + + @Override + public boolean generate(World world, Random rand, BlockPos position) + { + // check that there's room and if the blocks below are suitable + if (!this.canPlaceHere(world, position, this.halfHeight * 2 + this.bottomExtra, this.maxRadius)) {return false;} + + boolean empty = rand.nextFloat() <= this.emptyChance; + + // create the top and bottom halves of the hive, and a little bit extra on the bottom for the sake of looking + // slightly more like a hive + for (int yOffset = this.halfHeight; yOffset >= -this.halfHeight - this.bottomExtra; yOffset--) + { + // y is already negative, so add it rather than subtract + int radius = this.maxRadius + (yOffset / this.layerSize) * (yOffset >= 0 ? -1 : 1); + + for (int xOffset = -radius; xOffset <= radius; xOffset++) + { + for (int zOffset = -radius; zOffset <= radius; zOffset++) + { + int x2_z2 = xOffset * xOffset + zOffset * zOffset; + + // used to determine where to fill with honey + boolean bottomHalf = yOffset <= 0; + + // check to fill the top and bottom of the two layers + boolean outerCap = yOffset == -this.halfHeight - this.bottomExtra || yOffset == this.halfHeight; + boolean innerCap = yOffset == -this.halfHeight - this.bottomExtra + 1 || yOffset == this.halfHeight - 1; + + // create a circular outline for the hive. the bottom and top layers should be filled. + // add a bit extra (1) to make the circles nicer too + + // inner layer. inset by one block + if (x2_z2 <= (radius - 1) * (radius - 1) + 1 && (x2_z2 >= (radius - 2) * (radius - 2) || innerCap)) + { + IBlockState honeyComb = BOPBlocks.hive.getDefaultState().withProperty(BlockBOPHive.VARIANT, BlockBOPHive.HiveType.EMPTY_HONEYCOMB); + float f = rand.nextFloat(); + + if (!empty && f <= 0.95) + { + honeyComb = BOPBlocks.hive.getDefaultState().withProperty(BlockBOPHive.VARIANT, BlockBOPHive.HiveType.HONEYCOMB); + + // if on the bottom half of the hive bias more towards filled honeycomb. + // the rest of the hive can still have filled blocks though + if (f <= 0.2 || (f <= 0.65 && bottomHalf)) + { + honeyComb = BOPBlocks.hive.getDefaultState().withProperty(BlockBOPHive.VARIANT, BlockBOPHive.HiveType.FILLED_HONEYCOMB); + } + } + else if (empty && f <= 0.2) + { + honeyComb = Blocks.AIR.getDefaultState(); + } + + // offset so we're placing the hive underneath the initial y coordinate + world.setBlockState(position.add(xOffset, yOffset - this.halfHeight, zOffset), honeyComb); + } + + // inner fill + if (!empty && bottomHalf && x2_z2 <= (radius - 2) * (radius - 2) + 1) + { + // fill the centre of the hive with honey blocks honey + IBlockState fillBlock = yOffset == 0 ? BOPBlocks.honey_block.getDefaultState() : BOPBlocks.honey.getDefaultState(); + world.setBlockState(position.add(xOffset, yOffset - this.halfHeight, zOffset), fillBlock); + } + + // place a wasp spawner in the middle of the hive + if (!empty && yOffset == 0 && xOffset == 0 && zOffset == 0) + { + BlockPos spawnerPos = position.add(xOffset, yOffset - this.halfHeight, zOffset); + + world.setBlockState(spawnerPos, Blocks.MOB_SPAWNER.getDefaultState(), 2); + TileEntity tileentity = world.getTileEntity(spawnerPos); + + if (tileentity instanceof TileEntityMobSpawner) + { + MobSpawnerBaseLogic spawnerLogic = ((TileEntityMobSpawner)tileentity).getSpawnerBaseLogic(); + + NBTTagCompound spawnerConfig = new NBTTagCompound(); + spawnerConfig.setShort("MinSpawnDelay", (short)100); + spawnerConfig.setShort("MaxSpawnDelay", (short)400); + spawnerConfig.setShort("SpawnCount", (short)6); + spawnerConfig.setShort("MaxNearbyEntities", (short)16); + spawnerConfig.setShort("RequiredPlayerRange", (short)24); + + spawnerLogic.readFromNBT(spawnerConfig); + spawnerLogic.setEntityId(new ResourceLocation(BiomesOPlenty.MOD_ID, "wasp")); + } + else + { + BiomesOPlenty.logger.error("Failed to fetch mob spawner entity at ({}, {}, {})", new Object[] {Integer.valueOf(spawnerPos.getX()), Integer.valueOf(spawnerPos.getY()), Integer.valueOf(spawnerPos.getZ())}); + } + } + + // outer layer + if (x2_z2 <= radius * radius + 1 && (x2_z2 >= (radius - 1) * (radius - 1) || outerCap)) + { + // offset so we're placing the hive underneath the initial y coordinate + world.setBlockState(position.add(xOffset, yOffset - halfHeight, zOffset), BOPBlocks.hive.getDefaultState()); + } + } + } + } + + return true; + } + + public boolean canPlaceHere(World world, BlockPos pos, int height, int radius) + { + + + if (world.getBiome(pos) == Biomes.HELL) + { + System.out.println(world.getBlockState(pos).getBlock() == Blocks.NETHERRACK); + } + + if (pos.getY() <= 1 || pos.getY() > 255) + { + return false; + } + for (int y = pos.getY(); y >= pos.getY() - height; --y) + { + for (int x = pos.getX() - radius; x <= pos.getX() + radius; ++x) + { + for (int z = pos.getZ() - radius; z <= pos.getZ() + radius; ++z) + { + if (y == pos.getY() && !this.placeOn.matches(world, new BlockPos(x, y + 1, z))) + { + return false; + } + + if (!this.replace.matches(world, new BlockPos(x, y, z))) + { + return false; + } + } + } + } + return true; + } + + @Override + public void configure(IConfigObj conf) + { + this.amountPerChunk = conf.getFloat("amountPerChunk", this.amountPerChunk); + this.placeOn = conf.getBlockPosQuery("placeUnder", this.placeOn); + this.replace = conf.getBlockPosQuery("replace", this.replace); + this.scatterYMethod = conf.getEnum("scatterYMethod", this.scatterYMethod, GeneratorUtils.ScatterYMethod.class); + + this.halfHeight = conf.getInt("halfHeight", this.halfHeight); + this.maxRadius = conf.getInt("maxRadius", this.maxRadius); + this.layerSize = conf.getInt("layerSize", this.layerSize); + this.bottomExtra = conf.getInt("bottomExtra", this.bottomExtra); + this.emptyChance = conf.getFloat("emptyChance", this.emptyChance); + } +}