Add whitelist and blacklist for generating flowers / mushrooms

This commit is contained in:
miozune committed 2022-08-19 11:48:24 +09:00
1 parent 19a4028e94
commit 21ce111286
2 files changed
+91 -32

No files matched your search

@@ -23,6 +23,8 @@ import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import java.util.Arrays;
public class BiomeDecorationHandler {
@SubscribeEvent(priority = EventPriority.LOWEST)
@@ -37,47 +39,73 @@ public class BiomeDecorationHandler {
if(!flowers)
return;
int dist = Math.min(8, Math.max(1, ConfigHandler.flowerPatchSize));
for(int i = 0; i < ConfigHandler.flowerQuantity; i++) {
if(event.rand.nextInt(ConfigHandler.flowerPatchChance) == 0) {
int x = event.chunkX + event.rand.nextInt(16) + 8;
int z = event.chunkZ + event.rand.nextInt(16) + 8;
int y = event.world.getTopSolidOrLiquidBlock(x, z);
if (ConfigHandler.flowerDimensionWhitelist.length == 0
|| Arrays.stream(ConfigHandler.flowerDimensionWhitelist).anyMatch(
d -> d == event.world.provider.dimensionId
)) {
if (Arrays.stream(ConfigHandler.flowerDimensionBlacklist).noneMatch(
d -> d == event.world.provider.dimensionId
)) {
generateFlowers(event);
}
}
int color = event.rand.nextInt(16);
boolean primus = event.rand.nextInt(380) == 0;
if (ConfigHandler.mushroomDimensionWhitelist.length == 0
|| Arrays.stream(ConfigHandler.mushroomDimensionWhitelist).anyMatch(
d -> d == event.world.provider.dimensionId
)) {
if (Arrays.stream(ConfigHandler.mushroomDimensionBlacklist).noneMatch(
d -> d == event.world.provider.dimensionId
)) {
generateMushrooms(event);
}
}
}
}
for(int j = 0; j < ConfigHandler.flowerDensity * ConfigHandler.flowerPatchChance; j++) {
int x1 = x + event.rand.nextInt(dist * 2) - dist;
int y1 = y + event.rand.nextInt(4) - event.rand.nextInt(4);
int z1 = z + event.rand.nextInt(dist * 2) - dist;
private void generateFlowers(DecorateBiomeEvent.Decorate event) {
int dist = Math.min(8, Math.max(1, ConfigHandler.flowerPatchSize));
for(int i = 0; i < ConfigHandler.flowerQuantity; i++) {
if(event.rand.nextInt(ConfigHandler.flowerPatchChance) == 0) {
int x = event.chunkX + event.rand.nextInt(16) + 8;
int z = event.chunkZ + event.rand.nextInt(16) + 8;
int y = event.world.getTopSolidOrLiquidBlock(x, z);
if(event.world.isAirBlock(x1, y1, z1) && (!event.world.provider.hasNoSky || y1 < 127) && ModBlocks.flower.canBlockStay(event.world, x1, y1, z1)) {
if(primus) {
event.world.setBlock(x1, y1, z1, ModBlocks.specialFlower, 0, 2);
TileSpecialFlower flower = (TileSpecialFlower) event.world.getTileEntity(x1, y1, z1);
flower.setSubTile(event.rand.nextBoolean() ? LibBlockNames.SUBTILE_NIGHTSHADE_PRIME : LibBlockNames.SUBTILE_DAYBLOOM_PRIME);
SubTileDaybloom subtile = (SubTileDaybloom) flower.getSubTile();
subtile.setPrimusPosition();
} else {
event.world.setBlock(x1, y1, z1, ModBlocks.flower, color, 2);
if(event.rand.nextDouble() < ConfigHandler.flowerTallChance && ((BlockModFlower) ModBlocks.flower).func_149851_a(event.world, x1, y1, z1, false))
BlockModFlower.placeDoubleFlower(event.world, x1, y1, z1, color, 0);
}
int color = event.rand.nextInt(16);
boolean primus = event.rand.nextInt(380) == 0;
for(int j = 0; j < ConfigHandler.flowerDensity * ConfigHandler.flowerPatchChance; j++) {
int x1 = x + event.rand.nextInt(dist * 2) - dist;
int y1 = y + event.rand.nextInt(4) - event.rand.nextInt(4);
int z1 = z + event.rand.nextInt(dist * 2) - dist;
if(event.world.isAirBlock(x1, y1, z1) && (!event.world.provider.hasNoSky || y1 < 127) && ModBlocks.flower.canBlockStay(event.world, x1, y1, z1)) {
if(primus) {
event.world.setBlock(x1, y1, z1, ModBlocks.specialFlower, 0, 2);
TileSpecialFlower flower = (TileSpecialFlower) event.world.getTileEntity(x1, y1, z1);
flower.setSubTile(event.rand.nextBoolean() ? LibBlockNames.SUBTILE_NIGHTSHADE_PRIME : LibBlockNames.SUBTILE_DAYBLOOM_PRIME);
SubTileDaybloom subtile = (SubTileDaybloom) flower.getSubTile();
subtile.setPrimusPosition();
} else {
event.world.setBlock(x1, y1, z1, ModBlocks.flower, color, 2);
if(event.rand.nextDouble() < ConfigHandler.flowerTallChance && ((BlockModFlower) ModBlocks.flower).func_149851_a(event.world, x1, y1, z1, false))
BlockModFlower.placeDoubleFlower(event.world, x1, y1, z1, color, 0);
}
}
}
}
}
}
for(int i = 0; i < ConfigHandler.mushroomQuantity; i++) {
int x = event.chunkX + event.rand.nextInt(16) + 8;
int z = event.chunkZ + event.rand.nextInt(16) + 8;
int y = event.rand.nextInt(26) + 4;
private void generateMushrooms(DecorateBiomeEvent.Decorate event) {
for(int i = 0; i < ConfigHandler.mushroomQuantity; i++) {
int x = event.chunkX + event.rand.nextInt(16) + 8;
int z = event.chunkZ + event.rand.nextInt(16) + 8;
int y = event.rand.nextInt(26) + 4;
int color = event.rand.nextInt(16);
if(event.world.isAirBlock(x, y, z) && ModBlocks.mushroom.canBlockStay(event.world, x, y, z))
event.world.setBlock(x, y, z, ModBlocks.mushroom, color, 2);
}
int color = event.rand.nextInt(16);
if(event.world.isAirBlock(x, y, z) && ModBlocks.mushroom.canBlockStay(event.world, x, y, z))
event.world.setBlock(x, y, z, ModBlocks.mushroom, color, 2);
}
}
}
@@ -101,6 +101,11 @@ public final class ConfigHandler {
public static double flowerTallChance = 0.05;
public static int mushroomQuantity = 40;
public static int[] flowerDimensionWhitelist = new int[]{};
public static int[] flowerDimensionBlacklist = new int[]{};
public static int[] mushroomDimensionWhitelist = new int[]{};
public static int[] mushroomDimensionBlacklist = new int[]{};
private static boolean verifiedPotionArray = false;
private static int potionArrayLimit = 0;
@@ -286,6 +291,18 @@ public final class ConfigHandler {
desc = "Enables all built-in recipes. This can be false for expert modpacks that wish to supply their own.";
enableDefaultRecipes = loadPropBool("recipes.enabled", desc, enableDefaultRecipes);
desc = "Whitelist of which dimension generates Botania flowers. Empty means any dimension can.";
flowerDimensionWhitelist = loadPropIntArray("worldgen.flower.dimensionWhitelist", desc, flowerDimensionWhitelist);
desc = "Blacklist of which dimension generates Botania flowers.";
flowerDimensionBlacklist = loadPropIntArray("worldgen.flower.dimensionBlacklist", desc, flowerDimensionBlacklist);
desc = "Whitelist of which dimension generates Botania mushrooms. Empty means any dimension can.";
mushroomDimensionWhitelist = loadPropIntArray("worldgen.mushroom.dimensionWhitelist", desc, mushroomDimensionWhitelist);
desc = "Blacklist of which dimension generates Botania mushrooms.";
mushroomDimensionBlacklist = loadPropIntArray("worldgen.mushroom.dimensionBlacklist", desc, mushroomDimensionBlacklist);
potionIDSoulCross = loadPropPotionId(LibPotionNames.SOUL_CROSS, potionIDSoulCross);
potionIDFeatherfeet = loadPropPotionId(LibPotionNames.FEATHER_FEET, potionIDFeatherfeet);
potionIDEmptiness = loadPropPotionId(LibPotionNames.EMPTINESS, potionIDEmptiness);
@@ -334,6 +351,16 @@ public final class ConfigHandler {
return prop.getBoolean(default_);
}
public static int[] loadPropIntArray(String propName, String desc, int[] intArray) {
Property prop = config.get(Configuration.CATEGORY_GENERAL, propName, intArray);
prop.comment = desc;
if(adaptor != null)
adaptor.adaptPropertyIntArray(prop, prop.getIntList());
return prop.getIntList();
}
public static int loadPropPotionId(String propName, int default_) {
if(!verifiedPotionArray)
verifyPotionArray();
@@ -455,6 +482,10 @@ public final class ConfigHandler {
this.<Boolean>adaptProperty(prop, val);
}
public void adaptPropertyIntArray(Property prop, int[] val) {
this.<int[]>adaptProperty(prop, val);
}
public static class AdaptableValue<T> {
public final int version;