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 revisionBoth sides next revision
tutorial:structures [2019/02/16 20:56] – ↷ Page moved and renamed from features to tutorial:structures asietutorial:structures [2019/02/16 20:58] asie
Line 1: Line 1:
-**An example repo containing code that has fully completed this tutorial can be found here: [[https://github.com/Draylar/fabric-structure-example-repo|fabric-structure-example-repo]]**+====== Generating Structures ====== 
 + 
 +===== Features ===== 
 + 
 +All code used in this tutorial is available here: [[https://github.com/Draylar/fabric-structure-example-repo|fabric-structure-example-repo]] 
 + 
 +==== Introduction ====
  
 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.
Line 7: Line 13:
 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-- it answers questions such as ‘should I spawn here?’ and ‘what is my name?’ The generator handles the placement of blocks or loading in a structure file if you choose to do so. 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-- it answers questions such as ‘should I spawn here?’ and ‘what is my name?’ The generator handles the placement of blocks or loading in a structure file if you choose to do so.
  
-To create a basic feature, we recommend creating a class that extends AbstractTempleFeature<DefaultFeatureConfig>. Various vanilla structures, such as Shipwrecks, Igloos, and Temples, use AbstracTempleFeature as a base. You will have to override the following methods:+==== Creating a Feature ==== 
 + 
 +To create a basic feature, we recommend creating a class that extends AbstractTempleFeature<DefaultFeatureConfig>. Various vanilla structures, such as Shipwrecks, Igloos, and Temples, use AbstractTempleFeature as a base. You will have to override the following methods:
  
   * shouldStartAt: return true for testing purposes.   * shouldStartAt: return true for testing purposes.
Line 39: Line 47:
 This is called when the world attempts to spawn in a new structure, and is the gap between your Feature and Generator. The reference to the variable in your main class doesn't exist yet, but we'll create it at the end. You can also just set the config equal to a new DefaultFeatureConfig. You can return this in getStructureStartFactory with return MyStructureStart::new. This is called when the world attempts to spawn in a new structure, and is the gap between your Feature and Generator. The reference to the variable in your main class doesn't exist yet, but we'll create it at the end. You can also just set the config equal to a new DefaultFeatureConfig. You can return this in getStructureStartFactory with return MyStructureStart::new.
  
-This is where structure files and generating straight from a generate method part ways. If you want, you can simply override generate in your Feature class and use setBlockState to place blocks directly in the world. This is a valid option and was popular pre-1.13, but structure files are simply more powerful at this point and are highly recommended.+This is where structure files and generating straight from a generate method part ways. There are two ways to go about this: 
 + 
 +If you want, you can simply override generate in your Feature class and use setBlockState to place blocks directly in the world. This is a valid option and was popular pre-1.13
 +* Use structure files and a Generator. These are rather powerful at this point and are highly recommended. 
 + 
 +==== Creating a Generator ====
  
 As you have probably noticed, we need to create a generator. We'll name it MyGenerator, and it's referenced in the initialize method of your StructureStart class. It doesn't need to override anything, but does require the following: As you have probably noticed, we need to create a generator. We'll name it MyGenerator, and it's referenced in the initialize method of your StructureStart class. 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-- addParts is a good name:+  * Some sort of setup method - addParts is a good name:
  
   public static void addParts(StructureManager structureManager_1, BlockPos blockPos_1, Rotation rotation_1,    public static void addParts(StructureManager structureManager_1, BlockPos blockPos_1, Rotation rotation_1, 
Line 121: Line 134:
 In this case, we simply get the y position of the highest block in the middle of our chunk and generate the structure off that position.  In this case, we simply get the y position of the highest block in the middle of our chunk and generate the structure off that position. 
  
 +==== Registering Features ====
  
 The last step is to register our features. We're going to need to register: The last step is to register our features. We're going to need to register:
tutorial/structures.txt · Last modified: 2022/11/05 12:06 by jab125