diff --git a/src/main/java/vazkii/botania/common/world/ModFeatures.java b/src/main/java/vazkii/botania/common/world/ModFeatures.java index dfb8fd5c7..ed39d9913 100644 --- a/src/main/java/vazkii/botania/common/world/ModFeatures.java +++ b/src/main/java/vazkii/botania/common/world/ModFeatures.java @@ -10,11 +10,13 @@ */ package vazkii.botania.common.world; +import com.google.common.collect.ImmutableSet; import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.GenerationStage; import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.placement.IPlacementConfig; import net.minecraft.world.gen.placement.Placement; +import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -22,22 +24,38 @@ import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.IForgeRegistry; import vazkii.botania.common.lib.LibMisc; +import java.util.Set; + import static vazkii.botania.common.block.ModBlocks.register; @Mod.EventBusSubscriber(modid = LibMisc.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class ModFeatures { public static final Feature MYSTICAL_FLOWERS = new MysticalFlowerFeature(MysticalFlowerConfig::deserialize); + public static final Feature MYSTICAL_MUSHROOMS = new MysticalMushroomFeature(MysticalFlowerConfig::deserialize); + + public static final Set TYPE_BLACKLIST = ImmutableSet.of( + BiomeDictionary.Type.DEAD, + BiomeDictionary.Type.NETHER, + BiomeDictionary.Type.END, + BiomeDictionary.Type.SNOWY, + BiomeDictionary.Type.WASTELAND, + BiomeDictionary.Type.VOID + ); @SubscribeEvent public static void registerFeatures(RegistryEvent.Register> event) { IForgeRegistry> r = event.getRegistry(); register(r, MYSTICAL_FLOWERS, "mystical_flowers"); + register(r, MYSTICAL_MUSHROOMS, "mystical_mushrooms"); } public static void addWorldgen() { - for(Biome biome : ForgeRegistries.BIOMES) { //todo should this be more specific? - biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Biome.createDecoratedFeature(MYSTICAL_FLOWERS, new MysticalFlowerConfig(), Placement.NOPE, IPlacementConfig.NO_PLACEMENT_CONFIG)); + for(Biome biome : ForgeRegistries.BIOMES) { + if (BiomeDictionary.getTypes(biome).stream().noneMatch(TYPE_BLACKLIST::contains)) { + biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Biome.createDecoratedFeature(MYSTICAL_FLOWERS, new MysticalFlowerConfig(), Placement.NOPE, IPlacementConfig.NO_PLACEMENT_CONFIG)); + } + biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Biome.createDecoratedFeature(MYSTICAL_MUSHROOMS, new MysticalFlowerConfig(), Placement.NOPE, IPlacementConfig.NO_PLACEMENT_CONFIG)); } } } diff --git a/src/main/java/vazkii/botania/common/world/MysticalFlowerFeature.java b/src/main/java/vazkii/botania/common/world/MysticalFlowerFeature.java index e83fcbc91..8138e88f5 100644 --- a/src/main/java/vazkii/botania/common/world/MysticalFlowerFeature.java +++ b/src/main/java/vazkii/botania/common/world/MysticalFlowerFeature.java @@ -36,6 +36,7 @@ public class MysticalFlowerFeature extends Feature { if(!flowers) return false; + boolean any = false; int dist = Math.min(8, Math.max(1, config.getPatchSize())); for(int i = 0; i < config.getPatchCount(); i++) { if(rand.nextInt(config.getPatchChance()) == 0) { @@ -53,6 +54,7 @@ public class MysticalFlowerFeature extends Feature { BlockPos pos2 = new BlockPos(x1, y1, z1); if(world.isAirBlock(pos2) && (!world.getDimension().isNether() || y1 < 127) && flower.isValidPosition(world, pos2)) { world.setBlockState(pos2, flower, 2); + any = true; if(rand.nextDouble() < config.getTallChance() && ((BlockModFlower) flower.getBlock()).canGrow(world, pos2, world.getBlockState(pos2), false)) { Block block = ModBlocks.getDoubleFlower(color); @@ -65,16 +67,6 @@ public class MysticalFlowerFeature extends Feature { } } - for(int i = 0; i < config.getMushroomPatchSize(); i++) { - int x = pos.getX() + rand.nextInt(16) + 8; - int z = pos.getZ() + rand.nextInt(16) + 8; - int y = rand.nextInt(26) + 4; - BlockPos pos3 = new BlockPos(x, y, z); - DyeColor color = DyeColor.byId(rand.nextInt(16)); - BlockState mushroom = ModBlocks.getMushroom(color).getDefaultState(); - if(world.isAirBlock(pos3) && mushroom.isValidPosition(world, pos3)) - world.setBlockState(pos3, mushroom, 2); - } - return false; + return any; } } diff --git a/src/main/java/vazkii/botania/common/world/MysticalMushroomFeature.java b/src/main/java/vazkii/botania/common/world/MysticalMushroomFeature.java new file mode 100644 index 000000000..9b0838396 --- /dev/null +++ b/src/main/java/vazkii/botania/common/world/MysticalMushroomFeature.java @@ -0,0 +1,50 @@ +package vazkii.botania.common.world; + +import com.mojang.datafixers.Dynamic; +import net.minecraft.block.BlockState; +import net.minecraft.item.DyeColor; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IWorld; +import net.minecraft.world.gen.ChunkGenerator; +import net.minecraft.world.gen.GenerationSettings; +import net.minecraft.world.gen.feature.Feature; +import vazkii.botania.api.item.IFlowerlessBiome; +import vazkii.botania.api.item.IFlowerlessWorld; +import vazkii.botania.common.block.ModBlocks; + +import javax.annotation.Nonnull; +import java.util.Random; +import java.util.function.Function; + +public class MysticalMushroomFeature extends Feature { + public MysticalMushroomFeature(Function, ? extends MysticalFlowerConfig> configFactory) { + super(configFactory); + } + + @Override + public boolean place(@Nonnull IWorld world, @Nonnull ChunkGenerator generator, @Nonnull Random rand, @Nonnull BlockPos pos, @Nonnull MysticalFlowerConfig config) { + boolean spawn = true; + if(world.getDimension() instanceof IFlowerlessWorld) + spawn = ((IFlowerlessWorld) world.getDimension()).generateFlowers(world); + else if(world.getBiome(pos) instanceof IFlowerlessBiome) + spawn = ((IFlowerlessBiome) world.getBiome(pos)).canGenerateFlowers(world, pos.getX(), pos.getZ()); + + if(!spawn) + return false; + + boolean any = false; + for(int i = 0; i < config.getMushroomPatchSize(); i++) { + int x = pos.getX() + rand.nextInt(16) + 8; + int z = pos.getZ() + rand.nextInt(16) + 8; + int y = rand.nextInt(26) + 4; + BlockPos pos3 = new BlockPos(x, y, z); + DyeColor color = DyeColor.byId(rand.nextInt(16)); + BlockState mushroom = ModBlocks.getMushroom(color).getDefaultState(); + if(world.isAirBlock(pos3) && mushroom.isValidPosition(world, pos3)) { + world.setBlockState(pos3, mushroom, 2); + any = true; + } + } + return any; + } +}