Skip to content

Commit

Permalink
Fixed #55
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindnorling committed Apr 4, 2022
1 parent d09c563 commit 16a0949
Showing 1 changed file with 73 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ private static void reconstructFeatureFromJSON() {
false
);

Holder<PlacedFeature> placedFeature = reconstructPlaced(configuredFeature, Objects.requireNonNull(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(ore.getOre()))),
Objects.requireNonNull(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(replace.toLowerCase()))),
Holder<PlacedFeature> placedFeature = reconstructPlaced(configuredFeature,
Objects.requireNonNull(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(ore.getOre()))),
replace.toLowerCase(),
ore.getMinY(),
ore.getMaxY(),
ore.getSpawnRate(),
ore.getMaxVeinSize(),
ore.getDiscardChanceOnAirExposure(),
ore.getDistribution(),
false
);
Expand All @@ -87,13 +89,65 @@ private static void reconstructFeatureFromJSON() {
}
}

private static String makeRegistryNameUnique(String name) {
if (registryNames.contains(name)) {
int i = 1;
while (registryNames.contains(name + "_" + i)) {
i++;
}
return name + "_" + i;
}
return name;
}

private static final List<String> registryNames = new ArrayList<>();

private static String createUniqueRegistryName(Block block, String filler, int minY, int maxY, float spawnRate, int maxVeinSize, float discardChanceOnAirExposure, String distribution, boolean isDeepSlate, String featureType) {

String registryName;

if (isDeepSlate) {
registryName = String.format("deepslate_%s_%s_%s_%s_%s_%s_%s_%s_%s_feature",
Objects.requireNonNull(block.getRegistryName()).getPath(),
filler,
minY,
maxY,
spawnRate,
maxVeinSize,
discardChanceOnAirExposure,
distribution,
featureType
);
} else {
registryName = String.format("ore_%s_%s_%s_%s_%s_%s_%s_%s_%s_feature",
Objects.requireNonNull(block.getRegistryName()).getPath(),
filler,
minY,
maxY,
spawnRate,
maxVeinSize,
discardChanceOnAirExposure,
distribution,
featureType
);
}

registryName = makeRegistryNameUnique(registryName);
ModLogger.debug("Registry Name: " + registryName);
registryNames.add(registryName);

return registryName;
}

private static Holder<ConfiguredFeature<OreConfiguration, ?>> reconstructConfigured(OreEntry entry, Block ore, String filler, int minY, int maxY, float spawnRate, int maxVeinSize, float discardChanceOnAirExposure, boolean isDeepslate) {
ModLogger.debug("Reconstructing ore: " + ore);
ModLogger.debug("Reconstructing configured feature: " + ore);

String fillerName;
Block fillerBlock = null;
TagKey<Block> fillerTag = null;

ModLogger.info("Filler :: " + filler);

if (filler.contains(":")) {
fillerBlock = Objects.requireNonNull(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(filler)));
fillerName = Objects.requireNonNull(fillerBlock.getRegistryName()).getPath();
Expand All @@ -104,16 +158,10 @@ private static void reconstructFeatureFromJSON() {
return null;
}

String registryName = String.format("%s_%s_%s_%s_%s_%s_feature",
Objects.requireNonNull(ore.getRegistryName()).getPath(),
fillerName,
minY,
maxY,
spawnRate,
maxVeinSize
);
ModLogger.info("Filler Name :: " + fillerName);

String registryName = createUniqueRegistryName(ore, fillerName, minY, maxY, spawnRate, maxVeinSize, discardChanceOnAirExposure, entry.getDistribution().name().toLowerCase(), isDeepslate, "configured");

ModLogger.debug("Registry Name: " + registryName);
ModLogger.debug("Filler Block :: " + fillerBlock);
ModLogger.debug("Filler Tag :: " + fillerTag);

Expand Down Expand Up @@ -185,25 +233,20 @@ private static OreConfiguration configureFeature(Block ore, TagKey<Block> filler
return new OreConfiguration(new TagMatchTest(filler), ore.defaultBlockState(), maxVeinSize, discardChanceOnAirExposure);
}

private static Holder<PlacedFeature> reconstructPlaced(Holder<ConfiguredFeature<OreConfiguration, ?>> configuredFeature, Block ore, String fillerName, int minY, int maxY, float spawnRate, int maxVeinSize, float discardChanceOnAirExposure, Distribution distribution, boolean isDeepslate) {
ModLogger.debug("Reconstructing placed feature: " + ore);

private static Holder<PlacedFeature> reconstructPlaced(Holder<ConfiguredFeature<OreConfiguration, ?>> configuredFeature, Block ore, Block filler, int minY, int maxY, float spawnRate, int maxVeinSize, Distribution distribution, boolean isDeepslate) {
ModLogger.debug("Reconstructing ore: " + ore);
String registryName = String.format("%s_%s_%s_%s_%s_%s_placed",
Objects.requireNonNull(ore.getRegistryName()).getPath(),
Objects.requireNonNull(filler.getRegistryName()).getPath(),
minY,
maxY,
spawnRate,
maxVeinSize
);

ModLogger.debug("Registry Name: " + registryName);
String registryName = createUniqueRegistryName(ore, fillerName, minY, maxY, spawnRate, maxVeinSize, discardChanceOnAirExposure, distribution.name().toLowerCase(), isDeepslate, "placed");

return PlacementUtils.register(registryName, configuredFeature, buildPlacementModifiers(
spawnRate,
minY, maxY,
distribution
));
return PlacementUtils.register(
registryName,
configuredFeature,
buildPlacementModifiers(
spawnRate,
minY, maxY,
distribution
)
);
}

private static boolean hasDeepslateVariant(OreEntry entry) {
Expand All @@ -219,7 +262,7 @@ private static ResourceLocation formatDeepslate(OreEntry entry) {
String name = ore_split[1];
name = "deepslate_" + name;
String newResourceLocation = domain + ":" + name;
ModLogger.debug("Deepslate :: " + newResourceLocation);
ModLogger.debug("Format Deepslate :: " + newResourceLocation);

return new ResourceLocation(newResourceLocation);
}
Expand Down

0 comments on commit 16a0949

Please sign in to comment.