tutorial:custom_model
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:custom_model [2020/08/13 23:17] – technici4n | tutorial:custom_model [2020/12/14 06:06] – [Creating the model] recommended by IJ otherwise error solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
It is possible to add models to the game using block model JSON files, but it is also possible to render them through Java code. In this tutorial, we will add a four-sided furnace model to the game. | It is possible to add models to the game using block model JSON files, but it is also possible to render them through Java code. In this tutorial, we will add a four-sided furnace model to the game. | ||
Line 10: | Line 10: | ||
<code java> | <code java> | ||
- | public class FourSidedFurnaceModel implements UnbakedModel, | + | public |
</ | </ | ||
Line 73: | Line 73: | ||
==== BakedModel methods ==== | ==== BakedModel methods ==== | ||
- | The methods here are not used by the Fabric Renderer, so we don't really care about the implementation. | + | Not all the methods here are used by the Fabric Renderer, so we don't really care about the implementation. |
<code java> | <code java> | ||
@Override | @Override | ||
Line 82: | Line 82: | ||
@Override | @Override | ||
public boolean useAmbientOcclusion() { | public boolean useAmbientOcclusion() { | ||
- | return | + | return |
} | } | ||
@Override | @Override | ||
- | public boolean | + | public boolean |
return false; | return false; | ||
} | } | ||
@Override | @Override | ||
- | public boolean | + | public boolean |
return false; | return false; | ||
} | } | ||
@Override | @Override | ||
- | public boolean | + | public boolean |
return false; | return false; | ||
} | } | ||
Line 197: | Line 197: | ||
==== Updating the model ==== | ==== Updating the model ==== | ||
- | We will re-use the same model class, with a few changes: | + | We will re-use the same model class, with just a small change: |
- | * We will register the same model instance under a different name, so we'll make sure the model is only baked once. | + | * We will need a ''ModelTransformation'' |
- | * We will need a `ModelTransformation` that rotates/ | + | |
We will update our '' | We will update our '' | ||
Line 206: | Line 205: | ||
private static final Identifier DEFAULT_BLOCK_MODEL = new Identifier(" | private static final Identifier DEFAULT_BLOCK_MODEL = new Identifier(" | ||
- | private boolean isBaked = false; | ||
private ModelTransformation transformation; | private ModelTransformation transformation; | ||
| | ||
Line 217: | Line 215: | ||
@Override | @Override | ||
public BakedModel bake(ModelLoader loader, Function< | public BakedModel bake(ModelLoader loader, Function< | ||
- | // Don't bake twice | ||
- | if(isBaked) return this; | ||
- | isBaked = true; | ||
- | | ||
// Load the default block model | // Load the default block model | ||
JsonUnbakedModel defaultBlockModel = (JsonUnbakedModel) loader.getOrLoadModel(DEFAULT_BLOCK_MODEL); | JsonUnbakedModel defaultBlockModel = (JsonUnbakedModel) loader.getOrLoadModel(DEFAULT_BLOCK_MODEL); | ||
Line 270: | Line 264: | ||
} | } | ||
} | } | ||
- | </ | + | </ |
===== Final result ===== | ===== Final result ===== | ||
{{: | {{: | ||
+ | |||
Et voilà! Enjoy! | Et voilà! Enjoy! | ||
+ | |||
+ | ===== More dynamic rendering ===== | ||
+ | The '' | ||
+ | <code java> | ||
+ | @Override | ||
+ | public void emitBlockQuads(BlockRenderView blockRenderView, | ||
+ | QuadEmitter emitter = renderContext.getEmitter(); | ||
+ | /* With this emitter, you can directly append the quads to the chunk model. */ | ||
+ | } | ||
+ | </ |
tutorial/custom_model.txt · Last modified: 2024/04/27 08:58 by florens