Fixed Biome Modification API not working for datapack provided biomes ()

* Fixed Biome Modification API not working for json biome

* upgraded test to add to all deserts and added json biome. (note the test mod won't load the json biome tho. Make it into a datapack so it works)

* switched set of rgeistrykeys to set of biome instances

* added datapack as backup to test mod

* removed unused imports

* removed the biome json file from the test mod's data folder
This commit is contained in:
TelepathicGrunt 2021-05-25 13:02:16 -04:00 committed by modmuss50
parent 75bf7f0f4a
commit f37e715554
8 changed files with 64 additions and 8 deletions
fabric-biome-api-v1/src

View file

@ -111,7 +111,7 @@ public class BiomeModificationImpl {
// which usually will not result in a reload of objects, since it reuses existing objects
// from the manager when they are being referenced.
BiomeModificationTracker modificationTracker = (BiomeModificationTracker) (Object) impl;
Set<RegistryKey<Biome>> modifiedBiomes = modificationTracker.fabric_getModifiedBiomes();
Set<Biome> modifiedBiomes = modificationTracker.fabric_getModifiedBiomes();
Registry<Biome> biomes = impl.get(Registry.BIOME_KEY);
@ -131,7 +131,7 @@ public class BiomeModificationImpl {
for (RegistryKey<Biome> key : keys) {
Biome biome = biomes.getOrThrow(key);
if (!modifiedBiomes.add(key)) {
if (!modifiedBiomes.add(biome)) {
continue; // Do not modify the same biome twice
}

View file

@ -20,7 +20,6 @@ import java.util.Set;
import org.jetbrains.annotations.ApiStatus;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.biome.Biome;
/**
@ -29,5 +28,5 @@ import net.minecraft.world.biome.Biome;
*/
@ApiStatus.Internal
public interface BiomeModificationTracker {
Set<RegistryKey<Biome>> fabric_getModifiedBiomes();
Set<Biome> fabric_getModifiedBiomes();
}

View file

@ -23,7 +23,6 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.biome.Biome;
import net.fabricmc.fabric.impl.biome.modification.BiomeModificationTracker;
@ -35,10 +34,10 @@ import net.fabricmc.fabric.impl.biome.modification.BiomeModificationTracker;
@Mixin(DynamicRegistryManager.Impl.class)
public class DynamicRegistryManagerImplMixin implements BiomeModificationTracker {
@Unique
private final Set<RegistryKey<Biome>> modifiedBiomes = new HashSet<>();
private final Set<Biome> modifiedBiomes = new HashSet<>();
@Override
public Set<RegistryKey<Biome>> fabric_getModifiedBiomes() {
public Set<Biome> fabric_getModifiedBiomes() {
return this.modifiedBiomes;
}
}

View file

@ -30,9 +30,12 @@ import net.minecraft.world.biome.DefaultBiomeCreator;
import net.minecraft.world.biome.GenerationSettings;
import net.minecraft.world.biome.SpawnSettings;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.ConfiguredFeatures;
import net.minecraft.world.gen.feature.ConfiguredStructureFeatures;
import net.minecraft.world.gen.feature.DefaultBiomeFeatures;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.surfacebuilder.ConfiguredSurfaceBuilders;
import net.minecraft.world.gen.surfacebuilder.ConfiguredSurfaceBuilder;
import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder;
@ -47,6 +50,7 @@ import net.fabricmc.fabric.api.biome.v1.NetherBiomes;
import net.fabricmc.fabric.api.biome.v1.OverworldBiomes;
import net.fabricmc.fabric.api.biome.v1.OverworldClimate;
import net.fabricmc.fabric.api.biome.v1.TheEndBiomes;
import net.fabricmc.fabric.test.biome.mixin.DecoratorsAccessor;
/**
* <b>NOTES FOR TESTING:</b>
@ -97,6 +101,9 @@ public class FabricBiomeTest implements ModInitializer {
OverworldBiomes.addContinentalBiome(BiomeKeys.END_HIGHLANDS, OverworldClimate.DRY, 0.5);
ConfiguredFeature<?, ?> COMMON_DESERT_WELL = Feature.DESERT_WELL.configure(FeatureConfig.DEFAULT).decorate(DecoratorsAccessor.getSQUARE_HEIGHTMAP());
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier(MOD_ID, "common_desert_well"), COMMON_DESERT_WELL);
BiomeModifications.create(new Identifier("fabric:test_mod"))
.add(ModificationPhase.ADDITIONS,
BiomeSelectors.foundInOverworld(),
@ -107,6 +114,13 @@ public class FabricBiomeTest implements ModInitializer {
),
context -> {
context.getGenerationSettings().setBuiltInSurfaceBuilder(ConfiguredSurfaceBuilders.CRIMSON_FOREST);
})
.add(ModificationPhase.ADDITIONS,
BiomeSelectors.categories(Biome.Category.DESERT),
context -> {
context.getGenerationSettings().addFeature(GenerationStep.Feature.TOP_LAYER_MODIFICATION,
BuiltinRegistries.CONFIGURED_FEATURE.getKey(COMMON_DESERT_WELL).get()
);
});
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.test.biome.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.world.gen.decorator.ConfiguredDecorator;
@Mixin(targets = "net.minecraft.world.gen.feature.ConfiguredFeatures$Decorators")
public interface DecoratorsAccessor {
@Accessor
static ConfiguredDecorator<?> getSQUARE_HEIGHTMAP() {
throw new UnsupportedOperationException("");
}
}

View file

@ -0,0 +1,11 @@
{
"required": true,
"package": "net.fabricmc.fabric.test.biome.mixin",
"compatibilityLevel": "JAVA_16",
"client": [
"DecoratorsAccessor"
],
"injectors": {
"defaultRequire": 1
}
}

View file

@ -12,5 +12,8 @@
"main": [
"net.fabricmc.fabric.test.biome.FabricBiomeTest"
]
}
},
"mixins": [
"fabric-biome-testmod-api-v1.mixins.json"
]
}