User Tools

Site Tools


tutorial:custom_model

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:custom_model [2022/03/21 04:14] solidblocktutorial:custom_model [2023/06/25 21:41] – fix typo (EntType -> EnvType) andrew6rant
Line 163: Line 163:
 Now we have to register this class in the client initializer, the entry point for client-specific code. Now we have to register this class in the client initializer, the entry point for client-specific code.
 <code java> <code java>
-@Environment(EntType.CLIENT)+@Environment(EnvType.CLIENT)
 public class ExampleModClient implements ClientModInitializer { public class ExampleModClient implements ClientModInitializer {
     @Override     @Override
Line 204: Line 204:
 ==== Updating the model ==== ==== Updating the model ====
 We will re-use the same model class, with just a small change: We will re-use the same model class, with just a small change:
-  * We will need a ''ModelTransformation'' that rotates/translates/scales the model depending on its position (in right hand, in left hand, in gui, in item frame, etc...). As we are creating a model for a regular block, we will use the one from "minecraft:block/block" which we will load during model baking.+  * We will need a ''ModelTransformation'' that rotates/translates/scales the model depending on its position (in right hand, in left hand, in gui, in item frame, etc...). As we are creating a model for a regular block, we can use the transform provided by fabric in ''ModelHelper.MODEL_TRANSFORM_BLOCK''.
  
 We will update our ''FourSidedFurnaceModel'' class as follows: We will update our ''FourSidedFurnaceModel'' class as follows:
 <code java> <code java>
-    // The minecraft default block model 
-    private static final Identifier DEFAULT_BLOCK_MODEL = new Identifier("minecraft:block/block"); 
- 
-    private ModelTransformation transformation; 
-     
-    // We need to add the default model to the dependencies 
-    public Collection<Identifier> getModelDependencies() { 
-        return Arrays.asList(DEFAULT_BLOCK_MODEL); 
-    } 
-     
-    // We need to add a bit of logic to the bake function 
-    @Override 
-    public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) { 
-        // Load the default block model 
-        JsonUnbakedModel defaultBlockModel = (JsonUnbakedModel) loader.getOrLoadModel(DEFAULT_BLOCK_MODEL); 
-        // Get its ModelTransformation 
-        transformation = defaultBlockModel.getTransformations(); 
-         
-        /* Previous code */ 
-    } 
-     
     // We need to implement getTransformation() and getOverrides()     // We need to implement getTransformation() and getOverrides()
     @Override     @Override
     public ModelTransformation getTransformation() {     public ModelTransformation getTransformation() {
-        return transformation;+        return ModelHelper.MODEL_TRANSFORM_BLOCK;
     }     }
  
tutorial/custom_model.txt · Last modified: 2024/04/27 08:58 by florens