Blacklist some biomes from flower spawning. Closes #3000

This commit is contained in:
Vincent Lee committed 2019-11-11 00:22:45 -06:00
1 parent a7e4e26e06
commit e9d8e2009b
3 files changed
+73 -13

No files matched your search

@@ -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<MysticalFlowerConfig> MYSTICAL_FLOWERS = new MysticalFlowerFeature(MysticalFlowerConfig::deserialize);
public static final Feature<MysticalFlowerConfig> MYSTICAL_MUSHROOMS = new MysticalMushroomFeature(MysticalFlowerConfig::deserialize);
public static final Set<BiomeDictionary.Type> 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<Feature<?>> event) {
IForgeRegistry<Feature<?>> 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));
}
}
}
@@ -36,6 +36,7 @@ public class MysticalFlowerFeature extends Feature<MysticalFlowerConfig> {
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<MysticalFlowerConfig> {
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<MysticalFlowerConfig> {
}
}
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;
}
}
@@ -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<MysticalFlowerConfig> {
public MysticalMushroomFeature(Function<Dynamic<?>, ? extends MysticalFlowerConfig> configFactory) {
super(configFactory);
}
@Override
public boolean place(@Nonnull IWorld world, @Nonnull ChunkGenerator<? extends GenerationSettings> 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;
}
}