From 413f3d60554d1d79a348bf5ab0e3ef60669b008a Mon Sep 17 00:00:00 2001 From: modmuss50 <modmuss50@gmail.com> Date: Thu, 5 Sep 2019 12:04:07 +0100 Subject: [PATCH] 19w36a some biome changes --- build.gradle | 2 +- fabric-biomes-v1/build.gradle | 2 +- .../fabric/impl/biomes/InternalBiomeData.java | 31 ++++++++---- .../MixinVanillaLayeredBiomeSource.java | 48 +++++-------------- fabric-rendering-v0/build.gradle | 2 +- .../render/ColorProviderRegistryImpl.java | 2 +- 6 files changed, 39 insertions(+), 48 deletions(-) diff --git a/build.gradle b/build.gradle index b88b7e359..94f9d446e 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ def ENV = System.getenv() class Globals { static def baseVersion = "0.3.2" - static def mcVersion = "19w35a" + static def mcVersion = "19w36a" static def yarnVersion = "+build.1" } diff --git a/fabric-biomes-v1/build.gradle b/fabric-biomes-v1/build.gradle index 0f49c235f..ee1a288cc 100644 --- a/fabric-biomes-v1/build.gradle +++ b/fabric-biomes-v1/build.gradle @@ -1,2 +1,2 @@ archivesBaseName = "fabric-biomes-v1" -version = getSubprojectVersion(project, "0.1.0") +version = getSubprojectVersion(project, "0.1.1") diff --git a/fabric-biomes-v1/src/main/java/net/fabricmc/fabric/impl/biomes/InternalBiomeData.java b/fabric-biomes-v1/src/main/java/net/fabricmc/fabric/impl/biomes/InternalBiomeData.java index 559c74e32..c6b557850 100644 --- a/fabric-biomes-v1/src/main/java/net/fabricmc/fabric/impl/biomes/InternalBiomeData.java +++ b/fabric-biomes-v1/src/main/java/net/fabricmc/fabric/impl/biomes/InternalBiomeData.java @@ -23,7 +23,10 @@ import net.minecraft.util.registry.Registry; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biomes; import net.minecraft.world.biome.layer.BiomeLayers; +import net.minecraft.world.biome.source.VanillaLayeredBiomeSource; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.*; /** @@ -40,17 +43,18 @@ public final class InternalBiomeData { private static final Map<Biome, WeightedBiomePicker> OVERWORLD_EDGE_MAP = new HashMap<>(); private static final Map<Biome, VariantTransformer> OVERWORLD_VARIANT_TRANSFORMERS = new HashMap<>(); private static final Map<Biome, Biome> OVERWORLD_RIVER_MAP = new HashMap<>(); - private static final List<Biome> OVERWORLD_INJECTED_BIOMES = new ArrayList<>(); private static final Set<Biome> SPAWN_BIOMES = new HashSet<>(); + private static Method injectBiomeMethod = null; + public static void addOverworldContinentalBiome(OverworldClimate climate, Biome biome, double weight) { Preconditions.checkArgument(climate != null, "Climate is null"); Preconditions.checkArgument(biome != null, "Biome is null"); Preconditions.checkArgument(!Double.isNaN(weight), "Weight is NaN"); Preconditions.checkArgument(weight > 0.0, "Weight is less than or equal to 0.0 (%s)", weight); OVERWORLD_MODDED_CONTINENTAL_BIOME_PICKERS.computeIfAbsent(climate, k -> new WeightedBiomePicker()).addBiome(biome, weight); - OVERWORLD_INJECTED_BIOMES.add(biome); + injectOverworldBiome(biome); } public static void addOverworldHillsBiome(Biome primary, Biome hills, double weight) { @@ -59,7 +63,7 @@ public final class InternalBiomeData { Preconditions.checkArgument(!Double.isNaN(weight), "Weight is NaN"); Preconditions.checkArgument(weight > 0.0, "Weight is less than or equal to 0.0 (%s)", weight); OVERWORLD_HILLS_MAP.computeIfAbsent(primary, biome -> DefaultHillsData.injectDefaultHills(primary, new WeightedBiomePicker())).addBiome(hills, weight); - OVERWORLD_INJECTED_BIOMES.add(hills); + injectOverworldBiome(hills); } public static void addOverworldShoreBiome(Biome primary, Biome shore, double weight) { @@ -68,7 +72,7 @@ public final class InternalBiomeData { Preconditions.checkArgument(!Double.isNaN(weight), "Weight is NaN"); Preconditions.checkArgument(weight > 0.0, "Weight is less than or equal to 0.0 (%s)", weight); OVERWORLD_SHORE_MAP.computeIfAbsent(primary, biome -> new WeightedBiomePicker()).addBiome(shore, weight); - OVERWORLD_INJECTED_BIOMES.add(shore); + injectOverworldBiome(shore); } public static void addOverworldEdgeBiome(Biome primary, Biome edge, double weight) { @@ -77,7 +81,7 @@ public final class InternalBiomeData { Preconditions.checkArgument(!Double.isNaN(weight), "Weight is NaN"); Preconditions.checkArgument(weight > 0.0, "Weight is less than or equal to 0.0 (%s)", weight); OVERWORLD_EDGE_MAP.computeIfAbsent(primary, biome -> new WeightedBiomePicker()).addBiome(edge, weight); - OVERWORLD_INJECTED_BIOMES.add(edge); + injectOverworldBiome(edge); } public static void addOverworldBiomeReplacement(Biome replaced, Biome variant, double chance, OverworldClimate[] climates) { @@ -85,14 +89,14 @@ public final class InternalBiomeData { Preconditions.checkArgument(variant != null, "Variant biome is null"); Preconditions.checkArgument(chance > 0 && chance <= 1, "Chance is not greater than 0 or less than or equal to 1"); OVERWORLD_VARIANT_TRANSFORMERS.computeIfAbsent(replaced, biome -> new VariantTransformer()).addBiome(variant, chance, climates); - OVERWORLD_INJECTED_BIOMES.add(variant); + injectOverworldBiome(variant); } public static void setOverworldRiverBiome(Biome primary, Biome river) { Preconditions.checkArgument(primary != null, "Primary biome is null"); OVERWORLD_RIVER_MAP.put(primary, river); if (river != null) { - OVERWORLD_INJECTED_BIOMES.add(river); + injectOverworldBiome(river); } } @@ -101,8 +105,17 @@ public final class InternalBiomeData { SPAWN_BIOMES.add(biome); } - public static List<Biome> getOverworldInjectedBiomes() { - return OVERWORLD_INJECTED_BIOMES; + private static void injectOverworldBiome(Biome biome) { + try { + if (injectBiomeMethod == null) { + injectBiomeMethod = VanillaLayeredBiomeSource.class.getDeclaredMethod("fabric_injectBiome", Biome.class); + injectBiomeMethod.setAccessible(true); + } + + injectBiomeMethod.invoke(null, biome); + } catch (NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException e){ + throw new RuntimeException(e); + } } public static Set<Biome> getSpawnBiomes() { diff --git a/fabric-biomes-v1/src/main/java/net/fabricmc/fabric/mixin/biomes/MixinVanillaLayeredBiomeSource.java b/fabric-biomes-v1/src/main/java/net/fabricmc/fabric/mixin/biomes/MixinVanillaLayeredBiomeSource.java index 94fda79ae..b9d5d3207 100644 --- a/fabric-biomes-v1/src/main/java/net/fabricmc/fabric/mixin/biomes/MixinVanillaLayeredBiomeSource.java +++ b/fabric-biomes-v1/src/main/java/net/fabricmc/fabric/mixin/biomes/MixinVanillaLayeredBiomeSource.java @@ -16,17 +16,18 @@ package net.fabricmc.fabric.mixin.biomes; -import net.fabricmc.fabric.impl.biomes.InternalBiomeData; -import net.minecraft.block.BlockState; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.source.VanillaLayeredBiomeSource; import net.minecraft.world.gen.feature.StructureFeature; -import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.List; +import java.util.HashSet; import java.util.Set; /** @@ -39,39 +40,16 @@ public class MixinVanillaLayeredBiomeSource { @Shadow @Final @Mutable - private Biome[] biomes; + private static Set<Biome> biomes; - @Unique - private int injectionCount; - - @Inject(at = @At("HEAD"), method = "hasStructureFeature") - private void hasStructureFeature(CallbackInfoReturnable<Boolean> info) { - updateInjections(); + @Inject(method = "<clinit>", at = @At("RETURN")) + private static void cinit(CallbackInfo info){ + biomes = new HashSet<>(biomes); } - @Inject(at = @At("HEAD"), method = "getTopMaterials") - private void getTopMaterials(CallbackInfoReturnable<Set<BlockState>> info) { - updateInjections(); - } - - @Unique - private void updateInjections() { - List<Biome> injectedBiomes = InternalBiomeData.getOverworldInjectedBiomes(); - int currentSize = injectedBiomes.size(); - if (this.injectionCount < currentSize) { - List<Biome> toInject = injectedBiomes.subList(injectionCount, currentSize - 1); - - Biome[] oldBiomes = this.biomes; - this.biomes = new Biome[oldBiomes.length + toInject.size()]; - System.arraycopy(oldBiomes, 0, this.biomes, 0, oldBiomes.length); - - int index = oldBiomes.length; - for (Biome injected : toInject) { - biomes[index++] = injected; - } - - injectionCount += toInject.size(); - } + //Called via reflection + private static void fabric_injectBiome(Biome biome) { + biomes.add(biome); } } diff --git a/fabric-rendering-v0/build.gradle b/fabric-rendering-v0/build.gradle index 82df2e286..ec8434714 100644 --- a/fabric-rendering-v0/build.gradle +++ b/fabric-rendering-v0/build.gradle @@ -1,5 +1,5 @@ archivesBaseName = "fabric-rendering-v0" -version = getSubprojectVersion(project, "0.1.1") +version = getSubprojectVersion(project, "0.1.2") dependencies { compile project(path: ':fabric-api-base', configuration: 'dev') diff --git a/fabric-rendering-v0/src/main/java/net/fabricmc/fabric/impl/client/render/ColorProviderRegistryImpl.java b/fabric-rendering-v0/src/main/java/net/fabricmc/fabric/impl/client/render/ColorProviderRegistryImpl.java index 5b55df270..cb8d4675e 100644 --- a/fabric-rendering-v0/src/main/java/net/fabricmc/fabric/impl/client/render/ColorProviderRegistryImpl.java +++ b/fabric-rendering-v0/src/main/java/net/fabricmc/fabric/impl/client/render/ColorProviderRegistryImpl.java @@ -31,7 +31,7 @@ public abstract class ColorProviderRegistryImpl<T, Provider, Underlying> impleme public static final ColorProviderRegistryImpl<Block, BlockColorProvider, BlockColors> BLOCK = new ColorProviderRegistryImpl<Block, BlockColorProvider, BlockColors>() { @Override void registerUnderlying(BlockColors map, BlockColorProvider mapper, Block block) { - map.register(mapper, block); + map.registerColorProvider(mapper, block); } };