Skip to content

Commit

Permalink
Feature array length fix
Browse files Browse the repository at this point in the history
  • Loading branch information
paulevsGitch committed Nov 22, 2021
1 parent 42aedf2 commit fc3dc71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ loader_version= 0.12.4
fabric_version = 0.41.3+1.17

# Mod Properties
mod_version = 0.5.2
mod_version = 0.5.3
maven_group = ru.bclib
archives_base_name = bclib

Expand Down
34 changes: 20 additions & 14 deletions src/main/java/ru/bclib/api/BiomeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,7 @@ public static void applyModifications(ServerLevel level) {
public static void addBiomeFeature(Biome biome, ConfiguredFeature feature, Decoration step) {
GenerationSettingsAccessor accessor = (GenerationSettingsAccessor) biome.getGenerationSettings();
List<List<Supplier<ConfiguredFeature<?, ?>>>> biomeFeatures = getMutableList(accessor.fabric_getFeatures());
int index = step.ordinal();
if (biomeFeatures.size() < index) {
for (int i = biomeFeatures.size(); i <= index; i++) {
biomeFeatures.add(Lists.newArrayList());
}
}
List<Supplier<ConfiguredFeature<?, ?>>> list = getMutableList(biomeFeatures.get(index));
List<Supplier<ConfiguredFeature<?, ?>>> list = getList(step, biomeFeatures);
list.add(() -> feature);
accessor.fabric_setFeatures(biomeFeatures);
}
Expand All @@ -434,18 +428,30 @@ public static void addBiomeFeatures(Biome biome, BCLFeature... features) {
GenerationSettingsAccessor accessor = (GenerationSettingsAccessor) biome.getGenerationSettings();
List<List<Supplier<ConfiguredFeature<?, ?>>>> biomeFeatures = getMutableList(accessor.fabric_getFeatures());
for (BCLFeature feature: features) {
int index = feature.getFeatureStep().ordinal();
if (biomeFeatures.size() < index) {
for (int i = biomeFeatures.size(); i <= index; i++) {
biomeFeatures.add(Lists.newArrayList());
}
}
List<Supplier<ConfiguredFeature<?, ?>>> list = getMutableList(biomeFeatures.get(index));
List<Supplier<ConfiguredFeature<?, ?>>> list = getList(feature.getFeatureStep(), biomeFeatures);
list.add(feature::getFeatureConfigured);
}
accessor.fabric_setFeatures(biomeFeatures);
}

/**
* Getter for correct feature list from all biome feature list of lists.
* @param step feature {@link Decoration} step.
* @param lists biome accessor lists.
* @return mutable {@link ConfiguredFeature} list.
*/
private static List<Supplier<ConfiguredFeature<?, ?>>> getList(Decoration step, List<List<Supplier<ConfiguredFeature<?, ?>>>> lists) {
int index = step.ordinal();
if (lists.size() <= index) {
for (int i = lists.size(); i <= index; i++) {
lists.add(Lists.newArrayList());
}
}
List<Supplier<ConfiguredFeature<?, ?>>> list = getMutableList(lists.get(index));
lists.set(index, list);
return list;
}

/**
* Adds new structure feature to existing biome.
* @param biome {@link Biome} to add structure feature in.
Expand Down

0 comments on commit fc3dc71

Please sign in to comment.