Better Abstraction from internal FAPI (#2, FabricMC/fabric#2369)
This commit is contained in:
parent
185453b0c4
commit
59756e6dca
4 changed files with 45 additions and 74 deletions
|
@ -1,16 +0,0 @@
|
|||
package org.betterx.bclib.api.v2.levelgen.biomes;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class FabricBiomesData {
|
||||
public static final Map<ResourceKey<Biome>, Float> END_LAND_BIOMES = Maps.newHashMap();
|
||||
public static final Map<ResourceKey<Biome>, Float> END_VOID_BIOMES = Maps.newHashMap();
|
||||
public static final Set<ResourceKey<Biome>> NETHER_BIOMES = Sets.newHashSet();
|
||||
}
|
|
@ -109,32 +109,32 @@ public class InternalBiomeAPI {
|
|||
* Load biomes from Fabric API. For internal usage only.
|
||||
*/
|
||||
public static void loadFabricAPIBiomes() {
|
||||
FabricBiomesData.NETHER_BIOMES.forEach((key) -> {
|
||||
if (!BiomeAPI.hasBiome(key.location())) {
|
||||
Optional<Holder<Biome>> optional = BuiltinRegistries.BIOME.getHolder(key);
|
||||
if (optional.isPresent()) {
|
||||
BiomeAPI.registerNetherBiome(optional.get().value());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FabricBiomesData.END_LAND_BIOMES.forEach((key, weight) -> {
|
||||
if (!BiomeAPI.hasBiome(key.location())) {
|
||||
Optional<Holder<Biome>> optional = BuiltinRegistries.BIOME.getHolder(key);
|
||||
if (optional.isPresent()) {
|
||||
BiomeAPI.registerEndLandBiome(optional.get(), weight);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> {
|
||||
if (!BiomeAPI.hasBiome(key.location())) {
|
||||
Optional<Holder<Biome>> optional = BuiltinRegistries.BIOME.getHolder(key);
|
||||
if (optional.isPresent()) {
|
||||
BiomeAPI.registerEndVoidBiome(optional.get(), weight);
|
||||
}
|
||||
}
|
||||
});
|
||||
// FabricBiomesData.NETHER_BIOMES.forEach((key) -> {
|
||||
// if (!BiomeAPI.hasBiome(key.location())) {
|
||||
// Optional<Holder<Biome>> optional = BuiltinRegistries.BIOME.getHolder(key);
|
||||
// if (optional.isPresent()) {
|
||||
// BiomeAPI.registerNetherBiome(optional.get().value());
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// FabricBiomesData.END_LAND_BIOMES.forEach((key, weight) -> {
|
||||
// if (!BiomeAPI.hasBiome(key.location())) {
|
||||
// Optional<Holder<Biome>> optional = BuiltinRegistries.BIOME.getHolder(key);
|
||||
// if (optional.isPresent()) {
|
||||
// BiomeAPI.registerEndLandBiome(optional.get(), weight);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> {
|
||||
// if (!BiomeAPI.hasBiome(key.location())) {
|
||||
// Optional<Holder<Biome>> optional = BuiltinRegistries.BIOME.getHolder(key);
|
||||
// if (optional.isPresent()) {
|
||||
// BiomeAPI.registerEndVoidBiome(optional.get(), weight);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.betterx.bclib.mixin.common;
|
|||
|
||||
import org.betterx.bclib.interfaces.TheEndBiomeDataAccessor;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
|
@ -13,45 +12,29 @@ import org.spongepowered.asm.mixin.Final;
|
|||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(value = TheEndBiomeData.Overrides.class, remap = false)
|
||||
@Mixin(value = TheEndBiomeData.class, remap = false)
|
||||
public class TheEndBiomeDataMixin implements TheEndBiomeDataAccessor {
|
||||
@Shadow
|
||||
@Final
|
||||
@Nullable
|
||||
private Map<Holder<Biome>, WeightedPicker<Holder<Biome>>> endBiomesMap;
|
||||
private static Map<ResourceKey<Biome>, WeightedPicker<ResourceKey<Biome>>> END_BIOMES_MAP;
|
||||
@Shadow
|
||||
@Final
|
||||
@Nullable
|
||||
private Map<Holder<Biome>, WeightedPicker<Holder<Biome>>> endMidlandsMap;
|
||||
private static Map<ResourceKey<Biome>, WeightedPicker<ResourceKey<Biome>>> END_MIDLANDS_MAP;
|
||||
@Shadow
|
||||
@Final
|
||||
@Nullable
|
||||
private Map<Holder<Biome>, WeightedPicker<Holder<Biome>>> endBarrensMap;
|
||||
private static Map<ResourceKey<Biome>, WeightedPicker<ResourceKey<Biome>>> END_BARRENS_MAP;
|
||||
|
||||
public boolean bcl_canGenerateAsEndBiome(ResourceKey<Biome> key) {
|
||||
return endBiomesMap != null && endBiomesMap
|
||||
.keySet()
|
||||
.stream()
|
||||
.map(h->h.unwrapKey().orElse(null))
|
||||
.anyMatch(k->k!=null && k.equals(key));
|
||||
return END_BIOMES_MAP != null && END_BIOMES_MAP.containsKey(key);
|
||||
}
|
||||
|
||||
public boolean bcl_canGenerateAsEndMidlandBiome(ResourceKey<Biome> key) {
|
||||
return endMidlandsMap != null && endMidlandsMap
|
||||
.keySet()
|
||||
.stream()
|
||||
.map(h->h.unwrapKey().orElse(null))
|
||||
.anyMatch(k->k!=null && k.equals(key));
|
||||
return END_MIDLANDS_MAP != null && END_MIDLANDS_MAP.containsKey(key);
|
||||
}
|
||||
|
||||
public boolean bcl_canGenerateAsEndBarrensBiome(ResourceKey<Biome> key) {
|
||||
return endBarrensMap != null && endBarrensMap
|
||||
.keySet()
|
||||
.stream()
|
||||
.map(h->h.unwrapKey().orElse(null))
|
||||
.anyMatch(k->k!=null && k.equals(key));
|
||||
return END_BARRENS_MAP != null && END_BARRENS_MAP.containsKey(key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -231,6 +231,7 @@ public class WorldBootstrap {
|
|||
) {
|
||||
try {
|
||||
var levelStorageAccess = levelSource.createAccess(levelID);
|
||||
try {
|
||||
Helpers.initializeWorldConfig(levelStorageAccess, false);
|
||||
|
||||
//Helpers.setupWorld();
|
||||
|
@ -239,10 +240,13 @@ public class WorldBootstrap {
|
|||
TogetherWorldPreset.loadWorldDimensions(),
|
||||
false
|
||||
));
|
||||
levelStorageAccess.close();
|
||||
} catch (Exception e) {
|
||||
BCLib.LOGGER.error("Failed to initialize data in world", e);
|
||||
}
|
||||
levelStorageAccess.close();
|
||||
} catch (Exception e) {
|
||||
BCLib.LOGGER.error("Failed to acquire storage access", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean applyWorldPatches(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue