tutorial:custom_model
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:custom_model [2023/12/31 21:40] – [Sprites] Missed `int`s gudenau | tutorial:custom_model [2024/08/27 04:33] (current) – solidblock | ||
|---|---|---|---|
| Line 15: | Line 15: | ||
| ==== Sprites ==== | ==== Sprites ==== | ||
| - | A '' | + | A '' |
| - | Here, we will use two furnace textures. They are block textures, so they must be loaded from the block atlas '' | + | |
| <code java> | <code java> | ||
| + | // for versions before 1.21, replace `Identifier.ofVanilla` with `new Identifier`. | ||
| private static final SpriteIdentifier[] SPRITE_IDS = new SpriteIdentifier[]{ | private static final SpriteIdentifier[] SPRITE_IDS = new SpriteIdentifier[]{ | ||
| - | new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | + | new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, |
| - | new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | + | new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, |
| }; | }; | ||
| private final Sprite[] sprites = new Sprite[SPRITE_IDS.length]; | private final Sprite[] sprites = new Sprite[SPRITE_IDS.length]; | ||
| Line 50: | Line 50: | ||
| @Override | @Override | ||
| - | public BakedModel bake(ModelLoader loader, Function< | + | public BakedModel bake(Baker baker, Function< |
| // Get the sprites | // Get the sprites | ||
| for(int i = 0; i < SPRITE_IDS.length; | for(int i = 0; i < SPRITE_IDS.length; | ||
| Line 152: | Line 152: | ||
| <code java> | <code java> | ||
| @Environment(EnvType.CLIENT) | @Environment(EnvType.CLIENT) | ||
| - | public class TutorialModelLoadingPlugin | + | public class TutorialModelLoadingPlugin |
| - | public static final ModelIdentifier FOUR_SIDED_FURNACE_MODEL = new ModelIdentifier(" | + | public static final ModelIdentifier FOUR_SIDED_FURNACE_MODEL = new ModelIdentifier(Identifier.of(" |
| @Override | @Override | ||
| Line 160: | Line 160: | ||
| pluginContext.modifyModelOnLoad().register((original, | pluginContext.modifyModelOnLoad().register((original, | ||
| // This is called for every model that is loaded, so make sure we only target ours | // This is called for every model that is loaded, so make sure we only target ours | ||
| - | | + | |
| + | if(id != null && id.equals(FOUR_SIDED_FURNACE_MODEL)) { | ||
| return new FourSidedFurnaceModel(); | return new FourSidedFurnaceModel(); | ||
| } else { | } else { | ||
| Line 185: | Line 186: | ||
| Don't forget to register this entrypoint in '' | Don't forget to register this entrypoint in '' | ||
| - | < | + | < |
| - | /* ... */ | + | { |
| + | [...] | ||
| " | " | ||
| - | | + | |
| " | " | ||
| " | " | ||
| ] | ] | ||
| }, | }, | ||
| + | [...] | ||
| + | } | ||
| </ | </ | ||
| ===== Using the model ===== | ===== Using the model ===== | ||
| - | You can now register your block to use your new model. | + | You can now [[blocks|register your block]] to use your new model. |
| - | <code json> | + | |
| + | < | ||
| + | public final class TutorialBlocks { | ||
| + | [...] | ||
| + | public static final Block FOUR_SIDED_FURNACE = register(" | ||
| + | [...] | ||
| + | } | ||
| + | </ | ||
| + | <code javascript src/ | ||
| { | { | ||
| " | " | ||
| Line 243: | Line 255: | ||
| ==== Loading the model ==== | ==== Loading the model ==== | ||
| - | Let's update the '' | + | Let's update the '' |
| <code java> | <code java> | ||
| + | |||
| @Environment(EnvType.CLIENT) | @Environment(EnvType.CLIENT) | ||
| - | public class TutorialModelProvider | + | public class TutorialModelLoadingPlugin |
| - | public static final FourSidedFurnaceModel | + | public static final ModelIdentifier |
| - | public static final ModelIdentifier FOUR_SIDED_FURNACE_MODEL_BLOCK | + | public static final ModelIdentifier FOUR_SIDED_FURNACE_MODEL_ITEM = new ModelIdentifier(Identifier.of(" |
| - | public static final ModelIdentifier FOUR_SIDED_FURNACE_MODEL_ITEM = new ModelIdentifier(" | + | |
| - | | + | |
| - | public | + | public |
| - | if(identifier.equals(FOUR_SIDED_FURNACE_MODEL_BLOCK) || identifier.equals(FOUR_SIDED_FURNACE_MODEL_ITEM)) { | + | // We want to add our model when the models are loaded |
| - | return | + | pluginContext.modifyModelOnLoad().register((original, context) -> { |
| - | } else { | + | // This is called for every model that is loaded, so make sure we only target ours |
| - | return | + | final ModelIdentifier id = context.topLevelId(); |
| - | } | + | |
| - | } | + | return |
| + | } else { | ||
| + | // If we don't modify the model we just return | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| } | } | ||
| </ | </ | ||
tutorial/custom_model.1704058851.txt.gz · Last modified: 2023/12/31 21:40 by gudenau