User Tools

Site Tools


tutorial:biomes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:biome [2020/09/04 17:40] – Use hex for color siglongtutorial:biomes [2020/10/17 02:18] – updated mappings hydos
Line 1: Line 1:
-====== Adding a Biome ======+====== Adding Biomes ======
 **NOTE:** There is [[https://github.com/FabricMC/fabric/pull/1036|a ongoing pull request on Fabric API]] that adds biome API for 1.16.2. **NOTE:** There is [[https://github.com/FabricMC/fabric/pull/1036|a ongoing pull request on Fabric API]] that adds biome API for 1.16.2.
-Read this tutorial as a workaround until it gets merged.+Please use this tutorial as a workaround until it gets merged.
  
 ==== Introduction ==== ==== Introduction ====
- 
 There are 3 steps that are required to add a biome to the world. There are 3 steps that are required to add a biome to the world.
   * Creating a biome   * Creating a biome
Line 22: Line 21:
   // We use custom surface builder for our biome to cover surface with obsidians.   // We use custom surface builder for our biome to cover surface with obsidians.
   private static final ConfiguredSurfaceBuilder<TernarySurfaceConfig> OBSIDIAN_SURFACE_BUILDER = SurfaceBuilder.DEFAULT   private static final ConfiguredSurfaceBuilder<TernarySurfaceConfig> OBSIDIAN_SURFACE_BUILDER = SurfaceBuilder.DEFAULT
-    .method_30478(new TernarySurfaceConfig(+    .withConfig(new TernarySurfaceConfig(
       Blocks.OBSIDIAN.getDefaultState(),       Blocks.OBSIDIAN.getDefaultState(),
       Blocks.DIRT.getDefaultState(),       Blocks.DIRT.getDefaultState(),
Line 108: Line 107:
  
 ==== Adding a biome to a climate zone in the world ==== ==== Adding a biome to a climate zone in the world ====
-The vanilla biomes used in the overworld is defined ''VanillaLayeredBiomeSource''+The vanilla biomes used in the overworld is defined in ''VanillaLayeredBiomeSource.BIOMES''
-We have to add our biome to ''VanillaLayeredBiomeSource'' first.+We have to add our biome to it first. 
 + 
 +<code java> 
 +public class ExampleMod implements ModInitializer { 
 +  @Override 
 +  public void onInitialize() { 
 +    [...] 
 + 
 +    // We have to copy existing List because it is immutable. 
 +    List<RegistryKey<Biome>> biomes = new ArrayList<>(VanillaLayeredBiomeSourceAccessor.getBiomes()); 
 +    biomes.add(OBSILAND_KEY); 
 +    VanillaLayeredBiomeSourceAccessor.setBiomes(biomes); 
 +  } 
 +
 +</code>
  
 <code java> <code java>
 @Mixin(VanillaLayeredBiomeSource.class) @Mixin(VanillaLayeredBiomeSource.class)
-public class VanillaLayeredBiomeSourceMixin +public interface VanillaLayeredBiomeSourceAccessor 
-  @ModifyArgs(method = "<init>(JZZLnet/minecraft/util/registry/Registry;)V", at = @At(value = "INVOKE", target = "net/minecraft/world/biome/source/BiomeSource.<init>(Ljava/util/stream/Stream;)V")+  @Accessor("BIOMES"
-  private static void addOverworldBiomes(Args args, long seed, boolean legacyBiomeInitLayer, boolean largeBiomes, +  public static List<RegistryKey<Biome>getBiomes() { 
-      Registry<Biome> biomeRegistry) { +    throw new AssertionError(); 
-    Stream<Supplier<Biome>> biomes = args.get(0); +  } 
-    biomes = Stream.concat(biomes, Stream.of(() -> biomeRegistry.get(ExampleMod.OBSILAND_KEY))); + 
-    args.set(0, biomes);+  @Accessor("BIOMES") 
 +  public static void setBiomes(List<RegistryKey<Biome>> biomes) { 
 +    throw new AssertionError();
   }   }
 } }
 </code> </code>
  
-We need to specify the climate to which the biome is added.+Secondly, we need to specify the climate to which the biome is added.
 In this tutorial, we will add the custom biome to the temperate climate as an example. In this tutorial, we will add the custom biome to the temperate climate as an example.
 We modify ''SetBaseBiomesLayer.TEMPERATE_BIOMES'' to accomplish this. We modify ''SetBaseBiomesLayer.TEMPERATE_BIOMES'' to accomplish this.
Line 136: Line 151:
     // SetBaseBiomesLayer.TEMPERATE_BIOMES is an array of raw biome IDs.     // SetBaseBiomesLayer.TEMPERATE_BIOMES is an array of raw biome IDs.
     // We have to get the raw id of our biome and append it to TEMPERATE_BIOMES.     // We have to get the raw id of our biome and append it to TEMPERATE_BIOMES.
-    SetBaseBiomesLayer.TEMPERATE_BIOMES = ArrayUtils.add(SetBaseBiomesLayer.TEMPERATE_BIOMES, BuiltinRegistries.BIOME.getRawId(OBSILAND));+    SetBaseBiomesLayerAccessor.setTemperateBiomes( 
 +      ArrayUtils.add(SetBaseBiomesLayerAccessor.getTemperateBiomes(), BuiltinRegistries.BIOME.getRawId(OBSILAND)));
   }   }
 } }
 </code> </code>
  
-We have to use [[tutorial:accesswideners|Access Wideners]] to modify ''SetBaseBiomesLayer.TEMPERATE_BIOMES'' because it is a privte static field. +<code java> 
-Your ''modid.accesswidener'' should look like:+@Mixin(SetBaseBiomesLayer.class) 
 +public interface SetBaseBiomesLayerAccessor { 
 +  @Accessor("TEMPERATE_BIOMES") 
 +  public static int[] getTemperateBiomes() { 
 +    throw new AssertionError(); 
 +  }
  
-<code> +  @Accessor("TEMPERATE_BIOMES") 
-accessWidener v1 named +  public static void setTemperateBiomes(int[] biomes) { 
- +    throw new AssertionError(); 
-accessible field net/minecraft/world/biome/layer/SetBaseBiomesLayer TEMPERATE_BIOMES [I +  } 
-mutable    field net/minecraft/world/biome/layer/SetBaseBiomesLayer TEMPERATE_BIOMES [I+}
 </code> </code>
  
tutorial/biomes.txt · Last modified: 2022/08/16 20:50 by mineblock11