Fix worldgen

This commit is contained in:
Vincent Lee committed 2020-06-28 16:02:32 -05:00
1 parent 3eaf807132
commit 368a67cc46
8 files changed
+61 -116

No files matched your search

@@ -1,21 +0,0 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.api.item;
import net.minecraft.world.IWorld;
/**
* A Biome that implements this will not have Botania flowers generated.
*/
public interface IFlowerlessBiome {
/**
* @return Should this world be allowed to generate flowers?
*/
public boolean canGenerateFlowers(IWorld world, int x, int z);
}
@@ -1,22 +0,0 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.api.item;
import net.minecraft.world.IWorld;
/**
* A {@link net.minecraft.world.dimension.Dimension} that implements this will not have Botania flowers generated.
*/
public interface IFlowerlessWorld {
/**
* @return Should this world be allowed to generate flowers?
*/
public boolean generateFlowers(IWorld world);
}
@@ -140,7 +140,6 @@ public class Botania {
modBus.addListener(IMCHandler::handle);
modBus.addListener(this::loadComplete);
modBus.addListener(DataGenerators::gatherData);
modBus.addGenericListener(ChunkGeneratorType.class, ModFeatures::registerChunkGenerators);
modBus.addGenericListener(Feature.class, ModFeatures::registerFeatures);
modBus.addGenericListener(Item.class, ModItems::registerItems);
modBus.addGenericListener(ContainerType.class, ModItems::registerContainers);
@@ -25,8 +25,8 @@ import java.util.Set;
import static vazkii.botania.common.block.ModBlocks.register;
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 Feature<MysticalFlowerConfig> MYSTICAL_FLOWERS = new MysticalFlowerFeature();
public static final Feature<MysticalFlowerConfig> MYSTICAL_MUSHROOMS = new MysticalMushroomFeature();
public static final Set<BiomeDictionary.Type> TYPE_BLACKLIST = ImmutableSet.of(
BiomeDictionary.Type.DEAD,
@@ -44,16 +44,12 @@ public class ModFeatures {
register(r, "mystical_mushrooms", MYSTICAL_MUSHROOMS);
}
public static void registerChunkGenerators(RegistryEvent.Register<ChunkGeneratorType<?, ?>> evt) {
register(evt.getRegistry(), "garden_of_glass", SkyblockChunkGenerator.TYPE);
}
public static void addWorldgen() {
for (Biome biome : Registry.BIOME) {
if (BiomeDictionary.getTypes(biome).stream().noneMatch(TYPE_BLACKLIST::contains)) {
biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, MYSTICAL_FLOWERS.withConfiguration(new MysticalFlowerConfig()).withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG)));
biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, MYSTICAL_FLOWERS.withConfiguration(MysticalFlowerConfig.fromConfig()).withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG)));
}
biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, MYSTICAL_MUSHROOMS.withConfiguration(new MysticalFlowerConfig()).withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG)));
biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, MYSTICAL_MUSHROOMS.withConfiguration(MysticalFlowerConfig.fromConfig()).withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG)));
}
}
}
@@ -9,46 +9,70 @@
package vazkii.botania.common.world;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.world.gen.feature.IFeatureConfig;
import vazkii.botania.common.core.handler.ConfigHandler;
import javax.annotation.Nonnull;
public class MysticalFlowerConfig implements IFeatureConfig {
public int getPatchSize() {
return ConfigHandler.COMMON.flowerPatchSize.get();
public static final Codec<MysticalFlowerConfig> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.INT.fieldOf("flower_patch_size").forGetter(MysticalFlowerConfig::getFlowerPatchSize),
Codec.INT.fieldOf("mushroom_patch_size").forGetter(MysticalFlowerConfig::getMushroomPatchSize),
Codec.INT.fieldOf("patch_count").forGetter(MysticalFlowerConfig::getPatchCount),
Codec.INT.fieldOf("patch_density").forGetter(MysticalFlowerConfig::getPatchDensity),
Codec.INT.fieldOf("patch_chance").forGetter(MysticalFlowerConfig::getPatchChance),
Codec.DOUBLE.fieldOf("tall_chance").forGetter(MysticalFlowerConfig::getTallChance)
).apply(instance, MysticalFlowerConfig::new));
private final int flowerPatchSize;
private final int mushroomPatchSize;
private final int patchCount;
private final int patchDensity;
private final int patchChance;
private final double tallChance;
public static MysticalFlowerConfig fromConfig() {
return new MysticalFlowerConfig(
ConfigHandler.COMMON.flowerPatchSize.get(),
ConfigHandler.COMMON.mushroomQuantity.get(),
ConfigHandler.COMMON.flowerPatchSize.get(),
ConfigHandler.COMMON.flowerDensity.get(),
ConfigHandler.COMMON.flowerPatchChance.get(),
ConfigHandler.COMMON.flowerTallChance.get()
);
}
public MysticalFlowerConfig(int flowerPatchSize, int mushroomPatchSize, int patchCount, int patchDensity, int patchChance, double tallChance) {
this.flowerPatchSize = flowerPatchSize;
this.mushroomPatchSize = mushroomPatchSize;
this.patchCount = patchCount;
this.patchDensity = patchDensity;
this.patchChance = patchChance;
this.tallChance = tallChance;
}
public int getFlowerPatchSize() {
return flowerPatchSize;
}
public int getPatchCount() {
return ConfigHandler.COMMON.flowerQuantity.get();
return patchCount;
}
public int getPatchDensity() {
return ConfigHandler.COMMON.flowerDensity.get();
return patchDensity;
}
public int getPatchChance() {
return ConfigHandler.COMMON.flowerPatchChance.get();
return patchChance;
}
public double getTallChance() {
return ConfigHandler.COMMON.flowerTallChance.get();
return tallChance;
}
public int getMushroomPatchSize() {
return ConfigHandler.COMMON.mushroomQuantity.get();
}
@Nonnull
@Override
public <T> Dynamic<T> serialize(@Nonnull DynamicOps<T> ops) {
return new Dynamic<>(ops);
}
public static MysticalFlowerConfig deserialize(Dynamic<?> dynamic) {
return new MysticalFlowerConfig();
return mushroomPatchSize;
}
}
@@ -8,48 +8,33 @@
*/
package vazkii.botania.common.world;
import com.mojang.serialization.Dynamic;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.DoublePlantBlock;
import net.minecraft.item.DyeColor;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.ISeedReader;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.GenerationSettings;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.feature.Feature;
import vazkii.botania.api.item.IFlowerlessBiome;
import vazkii.botania.api.item.IFlowerlessWorld;
import net.minecraft.world.gen.feature.structure.StructureManager;
import vazkii.botania.common.block.BlockModFlower;
import vazkii.botania.common.block.ModBlocks;
import javax.annotation.Nonnull;
import java.util.Random;
import java.util.function.Function;
public class MysticalFlowerFeature extends Feature<MysticalFlowerConfig> {
public MysticalFlowerFeature(Function<Dynamic<?>, ? extends MysticalFlowerConfig> configFactoryIn) {
super(configFactoryIn);
public MysticalFlowerFeature() {
super(MysticalFlowerConfig.CODEC);
}
@Override
public boolean place(@Nonnull IWorld world, @Nonnull ChunkGenerator<? extends GenerationSettings> generator, @Nonnull Random rand, @Nonnull BlockPos pos, @Nonnull MysticalFlowerConfig config) {
boolean flowers = true;
if (world.getDimension() instanceof IFlowerlessWorld) {
flowers = ((IFlowerlessWorld) world.getDimension()).generateFlowers(world);
} else if (world.getBiome(pos) instanceof IFlowerlessBiome) {
flowers = ((IFlowerlessBiome) world.getBiome(pos)).canGenerateFlowers(world, pos.getX(), pos.getZ());
}
if (!flowers) {
return false;
}
public boolean func_230362_a_(@Nonnull ISeedReader world, @Nonnull StructureManager structures, @Nonnull ChunkGenerator generator, @Nonnull Random rand, @Nonnull BlockPos pos, @Nonnull MysticalFlowerConfig config) {
boolean any = false;
int dist = Math.min(8, Math.max(1, config.getPatchSize()));
int dist = Math.min(8, Math.max(1, config.getFlowerPatchSize()));
for (int i = 0; i < config.getPatchCount(); i++) {
if (rand.nextInt(config.getPatchChance()) == 0) {
int x = pos.getX() + rand.nextInt(16);
@@ -18,33 +18,17 @@ import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.structure.StructureManager;
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);
public MysticalMushroomFeature() {
super(MysticalFlowerConfig.CODEC);
}
@Override
public boolean func_230362_a_(ISeedReader world, StructureManager structureManager, ChunkGenerator generator, Random rand, BlockPos pos, 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;