Better Fabric biome API support
This commit is contained in:
parent
67be2ce342
commit
895b605523
6 changed files with 103 additions and 66 deletions
|
@ -1,11 +1,9 @@
|
||||||
package ru.bclib.api;
|
package ru.bclib.api;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.fabricmc.fabric.impl.biome.InternalBiomeData;
|
import net.fabricmc.fabric.impl.biome.InternalBiomeData;
|
||||||
import net.fabricmc.fabric.impl.biome.WeightedBiomePicker;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.data.BuiltinRegistries;
|
import net.minecraft.data.BuiltinRegistries;
|
||||||
|
@ -16,13 +14,11 @@ import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.biome.Biome.ClimateParameters;
|
import net.minecraft.world.level.biome.Biome.ClimateParameters;
|
||||||
import net.minecraft.world.level.biome.Biomes;
|
import net.minecraft.world.level.biome.Biomes;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.bclib.interfaces.BiomeListProvider;
|
|
||||||
import ru.bclib.util.MHelper;
|
import ru.bclib.util.MHelper;
|
||||||
import ru.bclib.world.biomes.BCLBiome;
|
import ru.bclib.world.biomes.BCLBiome;
|
||||||
|
import ru.bclib.world.biomes.FabricBiomesData;
|
||||||
import ru.bclib.world.generator.BiomePicker;
|
import ru.bclib.world.generator.BiomePicker;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
@ -155,6 +151,21 @@ public class BiomeAPI {
|
||||||
return bclBiome;
|
return bclBiome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register {@link BCLBiome} wrapper for {@link Biome}.
|
||||||
|
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands).
|
||||||
|
* @param biome {@link BCLBiome};
|
||||||
|
* @param weight float generation chance.
|
||||||
|
* @return {@link BCLBiome}
|
||||||
|
*/
|
||||||
|
public static BCLBiome registerEndLandBiome(Biome biome, float weight) {
|
||||||
|
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome).get();
|
||||||
|
BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, weight);
|
||||||
|
END_LAND_BIOME_PICKER.addBiome(bclBiome);
|
||||||
|
registerBiome(bclBiome);
|
||||||
|
return bclBiome;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register {@link BCLBiome} instance and its {@link Biome} if necessary.
|
* Register {@link BCLBiome} instance and its {@link Biome} if necessary.
|
||||||
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands).
|
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands).
|
||||||
|
@ -184,6 +195,21 @@ public class BiomeAPI {
|
||||||
return bclBiome;
|
return bclBiome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register {@link BCLBiome} instance and its {@link Biome} if necessary.
|
||||||
|
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands).
|
||||||
|
* @param biome {@link BCLBiome};
|
||||||
|
* @param weight float generation chance.
|
||||||
|
* @return {@link BCLBiome}
|
||||||
|
*/
|
||||||
|
public static BCLBiome registerEndVoidBiome(Biome biome, float weight) {
|
||||||
|
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome).get();
|
||||||
|
BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, weight);
|
||||||
|
END_VOID_BIOME_PICKER.addBiome(bclBiome);
|
||||||
|
registerBiome(bclBiome);
|
||||||
|
return bclBiome;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get {@link BCLBiome} from {@link Biome} instance on server. Used to convert world biomes to BCLBiomes.
|
* Get {@link BCLBiome} from {@link Biome} instance on server. Used to convert world biomes to BCLBiomes.
|
||||||
*
|
*
|
||||||
|
@ -250,20 +276,23 @@ public class BiomeAPI {
|
||||||
* Load biomes from Fabric API. For internal usage only.
|
* Load biomes from Fabric API. For internal usage only.
|
||||||
*/
|
*/
|
||||||
public static void loadFabricAPIBiomes() {
|
public static void loadFabricAPIBiomes() {
|
||||||
List<ResourceKey<Biome>> biomes = Lists.newArrayList();
|
FabricBiomesData.NETHER_BIOMES.forEach((key) -> {
|
||||||
biomes.addAll(getBiomes(InternalBiomeData.getEndBiomesMap().get(Biomes.SMALL_END_ISLANDS)));
|
if (!hasBiome(key.location())) {
|
||||||
biomes.addAll(getBiomes(InternalBiomeData.getEndBarrensMap().get(Biomes.END_BARRENS)));
|
registerNetherBiome(BuiltinRegistries.BIOME.get(key.location()));
|
||||||
biomes.forEach((key) -> registerEndVoidBiome(BuiltinRegistries.BIOME.get(key.location())));
|
}
|
||||||
|
});
|
||||||
|
|
||||||
biomes.clear();
|
FabricBiomesData.END_LAND_BIOMES.forEach((key, weight) -> {
|
||||||
biomes.addAll(getBiomes(InternalBiomeData.getEndBiomesMap().get(Biomes.END_MIDLANDS)));
|
if (!hasBiome(key.location())) {
|
||||||
biomes.addAll(getBiomes(InternalBiomeData.getEndBiomesMap().get(Biomes.END_HIGHLANDS)));
|
registerEndLandBiome(BuiltinRegistries.BIOME.get(key.location()), weight);
|
||||||
biomes.forEach((key) -> registerEndLandBiome(BuiltinRegistries.BIOME.get(key.location())));
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
private static List<ResourceKey<Biome>> getBiomes(WeightedBiomePicker picker) {
|
FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> {
|
||||||
BiomeListProvider biomeList = (BiomeListProvider) (Object) picker;
|
if (!hasBiome(key.location())) {
|
||||||
return biomeList == null ? Collections.emptyList() : biomeList.getBiomes();
|
registerEndVoidBiome(BuiltinRegistries.BIOME.get(key.location()), weight);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package ru.bclib.interfaces;
|
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceKey;
|
|
||||||
import net.minecraft.world.level.biome.Biome;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface BiomeListProvider {
|
|
||||||
List<ResourceKey<Biome>> getBiomes();
|
|
||||||
}
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package ru.bclib.mixin.common;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.impl.biome.InternalBiomeData;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraft.world.level.biome.Biomes;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import ru.bclib.world.biomes.FabricBiomesData;
|
||||||
|
|
||||||
|
@Mixin(value = InternalBiomeData.class, remap = false)
|
||||||
|
public class InternalBiomeDataMixin {
|
||||||
|
@Inject(method = "addEndBiomeReplacement", at = @At(value = "HEAD"))
|
||||||
|
private static void bclib_addEndBiomeReplacement(ResourceKey<Biome> replaced, ResourceKey<Biome> variant, double weight, CallbackInfo info) {
|
||||||
|
if (replaced == Biomes.END_BARRENS || replaced == Biomes.SMALL_END_ISLANDS) {
|
||||||
|
FabricBiomesData.END_VOID_BIOMES.put(variant, (float) weight);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FabricBiomesData.END_LAND_BIOMES.put(variant, (float) weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "addEndMidlandsReplacement", at = @At(value = "HEAD"))
|
||||||
|
private static void bclib_addEndMidlandsReplacement(ResourceKey<Biome> highlands, ResourceKey<Biome> midlands, double weight, CallbackInfo info) {
|
||||||
|
FabricBiomesData.END_LAND_BIOMES.put(midlands, (float) weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "addEndBarrensReplacement", at = @At(value = "HEAD"))
|
||||||
|
private static void bclib_addEndBarrensReplacement(ResourceKey<Biome> highlands, ResourceKey<Biome> barrens, double weight, CallbackInfo info) {
|
||||||
|
FabricBiomesData.END_LAND_BIOMES.put(barrens, (float) weight);
|
||||||
|
FabricBiomesData.END_VOID_BIOMES.put(barrens, (float) weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "addNetherBiome", at = @At(value = "HEAD"))
|
||||||
|
private static void bclib_addNetherBiome(ResourceKey<Biome> biome, Biome.ClimateParameters spawnNoisePoint, CallbackInfo info) {
|
||||||
|
FabricBiomesData.NETHER_BIOMES.add(biome);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,37 +0,0 @@
|
||||||
package ru.bclib.mixin.common;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import net.fabricmc.fabric.impl.biome.InternalBiomeData;
|
|
||||||
import net.fabricmc.fabric.impl.biome.WeightedBiomePicker;
|
|
||||||
import net.minecraft.resources.ResourceKey;
|
|
||||||
import net.minecraft.world.level.biome.Biome;
|
|
||||||
import net.minecraft.world.level.biome.Biomes;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
import ru.bclib.interfaces.BiomeListProvider;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mixin(value = WeightedBiomePicker.class, remap = false)
|
|
||||||
public class WeightedBiomePickerMixin implements BiomeListProvider {
|
|
||||||
private final List<ResourceKey<Biome>> biomes = Lists.newArrayList();
|
|
||||||
|
|
||||||
@Inject(method = "addBiome", at = @At("TAIL"))
|
|
||||||
private void bclib_addBiome(final ResourceKey<Biome> biome, final double weight, CallbackInfo info) {
|
|
||||||
if (be_isCorrectPicker(WeightedBiomePicker.class.cast(this))) {
|
|
||||||
biomes.add(biome);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean be_isCorrectPicker(WeightedBiomePicker picker) {
|
|
||||||
return picker == InternalBiomeData.getEndBiomesMap().get(Biomes.SMALL_END_ISLANDS) ||
|
|
||||||
picker == InternalBiomeData.getEndBarrensMap().get(Biomes.END_BARRENS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ResourceKey<Biome>> getBiomes() {
|
|
||||||
return biomes;
|
|
||||||
}
|
|
||||||
}
|
|
15
src/main/java/ru/bclib/world/biomes/FabricBiomesData.java
Normal file
15
src/main/java/ru/bclib/world/biomes/FabricBiomesData.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package ru.bclib.world.biomes;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
|
@ -5,7 +5,7 @@
|
||||||
"compatibilityLevel": "JAVA_16",
|
"compatibilityLevel": "JAVA_16",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"SimpleReloadableResourceManagerMixin",
|
"SimpleReloadableResourceManagerMixin",
|
||||||
"WeightedBiomePickerMixin",
|
"InternalBiomeDataMixin",
|
||||||
"ComposterBlockAccessor",
|
"ComposterBlockAccessor",
|
||||||
"PotionBrewingAccessor",
|
"PotionBrewingAccessor",
|
||||||
"RecipeManagerAccessor",
|
"RecipeManagerAccessor",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue