User Tools

Site Tools


tutorial:structures

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
tutorial:structures [2020/09/11 06:47] – 1.16.2 siglongtutorial:structures [2022/11/05 12:06] (current) jab125
Line 1: Line 1:
-====== Generating Structures ======+:!: //**For versions 1.18 and beyond, the Fabric Structure API no longer exists and structures can be done entirely in datapacks. [[https://misode.github.io/guides/adding-custom-structures/|Please read this gist for more information.]] ** // 
 + 
 +====== Adding Structure Features [1.16.3] ======
 We’re going to look at registering and placing structures in your world. We’re going to look at registering and placing structures in your world.
  
-To view examples of vanilla structures in action, ''IglooFeature'' and ''IglooGenerator'' are a good place to start. +To view examples of vanilla structures in action, ''IglooFeature'' and ''IglooGenerator'' are a good place to start. However, the growing standard for making new structures is using Jigsaw Structures which can be easier to work with and lets you deal with less structure code. [[https://fabricmc.net/wiki/tutorial:jigsaw|Read more on Jigsaw Structures here and how to make them.]]
  
 You are going to need a feature and generator for the most basic structure. You are going to need a feature and generator for the most basic structure.
 The feature handles the process of registering the structure and loading it in when the world is generating. The feature handles the process of registering the structure and loading it in when the world is generating.
 The generator handles the placement of blocks or loading in a structure file if you choose to do so. The generator handles the placement of blocks or loading in a structure file if you choose to do so.
 +
 +Note that this tutorial depends on [[https://github.com/FabricMC/fabric/pull/1097|Biome Modification API in Fabric API]] which is marked as experimental.
 +If the API doesn't work, consider using [[?rev=1599808070|the mixin version]].
  
 ===== Creating a Feature ===== ===== Creating a Feature =====
Line 57: Line 62:
 In this tutorial, we'll use a structure file. In this tutorial, we'll use a structure file.
 It doesn't need to override anything, but does require the following: It doesn't need to override anything, but does require the following:
-  * An Identifier that points to your structure file; use "igloo/top" if you need an example.+  * An identifier that points to your structure file; use ''"igloo/top"'' if you need an example.
   * Some sort of setup method - ''addPieces'' is a good name.   * Some sort of setup method - ''addPieces'' is a good name.
  
Line 103: Line 108:
   private void initializeStructureData(StructureManager structureManager) {   private void initializeStructureData(StructureManager structureManager) {
     Structure structure = structureManager.getStructureOrBlank(this.template);     Structure structure = structureManager.getStructureOrBlank(this.template);
-    StructurePlacementData placementData = (new StructurePlacementData()).setRotation(this.rotation).setMirror(BlockMirror.NONE) +    StructurePlacementData placementData = (new StructurePlacementData()) 
-        .addProcessor(BlockIgnoreStructureProcessor.IGNORE_STRUCTURE_BLOCKS);+      .setRotation(this.rotation) 
 +      .setMirror(BlockMirror.NONE) 
 +      .addProcessor(BlockIgnoreStructureProcessor.IGNORE_STRUCTURE_BLOCKS);
     this.setStructureData(structure, this.pos, placementData);     this.setStructureData(structure, this.pos, placementData);
   }   }
Line 121: Line 128:
 </code> </code>
          
-''handleMetadata'' is where you look at data blocks within your structure and do tasks based on what you find. +''handleMetadata'' is where you look at data blocks within your structure and can do tasks based on what you find. 
-In vanilla structures, data blocks are placed above chests so they can be filled with loot in this method.+This can be good for dynamic stuff such as placing certain mobs based on what mod is on and so on. 
 + 
 +In vanilla structures, data blocks are placed above chests so they can be filled with loot in this method.  
 +HOWEVER, you do not need to use datablocks to place chests with loot. Instead, use this command to set a north facing chest with a loottable.  
 +Save this chest into your structure's nbt file and it will generate loot when opened for the first time. (Don't open the chest before saving to the nbt file!) 
 +<code>/setblock ~ ~ ~ minecraft:chest[facing=north]{LootTable:"modid:loottable"}</code>
  
 We set the ''StructurePieceType'' to ''ExampleMod.MY_PIECE''; this is the variable that holds your registered structure piece.  We set the ''StructurePieceType'' to ''ExampleMod.MY_PIECE''; this is the variable that holds your registered structure piece. 
Line 130: Line 142:
  
   * structure   * structure
-  * pieces+  * piece
   * configured structure   * configured structure
  
Line 137: Line 149:
   public static final StructurePieceType MY_PIECE = MyGenerator.MyPiece::new;   public static final StructurePieceType MY_PIECE = MyGenerator.MyPiece::new;
   private static final StructureFeature<DefaultFeatureConfig> MY_STRUCTURE = new MyFeature(DefaultFeatureConfig.CODEC);   private static final StructureFeature<DefaultFeatureConfig> MY_STRUCTURE = new MyFeature(DefaultFeatureConfig.CODEC);
-  public static final ConfiguredStructureFeature<?, ?> MY_CONFIGURED = MY_STRUCTURE.configure(DefaultFeatureConfig.DEFAULT);+  private static final ConfiguredStructureFeature<?, ?> MY_CONFIGURED = MY_STRUCTURE.configure(DefaultFeatureConfig.DEFAULT);
  
   @Override   @Override
Line 148: Line 160:
       .register();       .register();
  
-    BuiltinRegistries.add(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, new Identifier("tutorial", "my_structure"), +    RegistryKey<ConfiguredStructureFeature<?, ?>> myConfigured = RegistryKey.of(Registry.CONFIGURED_STRUCTURE_FEATURE_WORLDGEN, 
-        MY_CONFIGURED);+        new Identifier("tutorial", "my_structure")); 
 +    BuiltinRegistries.add(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, myConfigured.getValue(), MY_CONFIGURED);
   }   }
 } }
 </code> </code>
  
-===== Adding a configured feature to a biome ===== +===== Adding a configured feature to biomes ===== 
-Vanilla features generated in the plain biomes are listed in ''DefaultBiomeFeatures.addPlainsFeatures''+In this tutorial, we add our structure to all biomes.
-We modify this method to add our structure to the plain biomes.+
  
 <code java> <code java>
-@Mixin(DefaultBiomeFeatures.class) +public class ExampleMod implements ModInitializer { 
-public class DefaultBiomeFeaturesMixin +  [...] 
-  @Inject(method = "addPlainsFeatures(Lnet/minecraft/world/biome/GenerationSettings$Builder;)V", at = @At("TAIL")) +  
-  private static void addPlainsFeatures(GenerationSettings.Builder builder, CallbackInfo ci) { +  @Override 
-    builder.structureFeature(ExampleMod.MY_CONFIGURED);+  public void onInitialize() { 
 +    [...] 
 + 
 +    BiomeModifications.addStructure(BiomeSelectors.all(), myConfigured);
   }   }
 } }
- 
 </code> </code>
  
 ===== Result ===== ===== Result =====
-You should be met with igloos in the plain biomes.+You should be met with igloos.
 You can use below command to find your structure in the world. You can use below command to find your structure in the world.
  
tutorial/structures.1599806879.txt.gz · Last modified: 2020/09/11 06:47 by siglong