diff --git a/docs/Mod Development/Blocks.md b/docs/Mod Development/Blocks.md index 7fe310e..1b84372 100644 --- a/docs/Mod Development/Blocks.md +++ b/docs/Mod Development/Blocks.md @@ -46,9 +46,6 @@ This component determines a few properties of your block, namely if it is a cube ### `Category` This is the category (equivalent to a creative tab in Minecraft) that this block belongs to. -### `ItemRenderer` -This handles the rendering of the block in your inventory and hand. - ### `Renderer` This is responsible for rendering the block in the world. In the example above, `StaticRenderer` is used but there are a few others you can use as well. @@ -78,6 +75,8 @@ To render your block you have several options: - Use any of the other built-in NOVA renderers - Create your own block renderer +More information can be found on the [Rendering](Rendering.md) page. + ### `BlockRenderPipeline` This is used for rendering simple cubes. diff --git a/docs/Mod Development/Items.md b/docs/Mod Development/Items.md index 4af811b..bfb9eb1 100644 --- a/docs/Mod Development/Items.md +++ b/docs/Mod Development/Items.md @@ -11,7 +11,7 @@ public class ItemScrewdriver extends Item { public ItemScrewdriver() { components.add(Category.TOOLS); - components.add(new ItemRenderer()).setTexture(NovaItem.screwTexture); // TODO: Deprecated + components.add(new StaticRenderer().onRender(new ItemRenderPipeline(this).withTexture(NovaItem.screwTexture).build())); events.on(UseEvent.class).bind(event -> event.action = true); } @@ -26,8 +26,8 @@ There are some components you will probably always want to implement in your ite ### `Category` This is the category (equivalent to a creative tab in Minecraft) that this item belongs to. -### `ItemRenderer` -This handles the rendering of the item in your inventory and hand. +### `Renderer` +This handles the rendering of the item in your inventory and hand. In the example above, `StaticRenderer` is used but there are a few others you can use as well. ## Special Interfaces ### `Syncable` @@ -40,9 +40,11 @@ Examples include: Electric charge of batteries, amount of fuel in a canister, et ## Rendering To render your item you have several options: -- Use the `ItemRenderer` (Deprecated) +- Use the `StaticRenderer` and the `ItemRenderPipeline`. - Use any of the other built-in NOVA renderers - Create your own item renderer -### `ItemRenderer` +More information can be found on the [Rendering](Rendering.md) page. + +### `ItemRenderPipeline` This is used for rendering simple items with a single texture. diff --git a/docs/Mod Development/Rendering.md b/docs/Mod Development/Rendering.md new file mode 100644 index 0000000..764c859 --- /dev/null +++ b/docs/Mod Development/Rendering.md @@ -0,0 +1,82 @@ +Rendering in NOVA is handled using `Renderer`s and pipelines. + +```java +components.add(new StaticRenderer().onRender(new BlockRenderPipeline(this).withTexture(YourMod.blockTexture).build()); +``` + +The code above adds a `StaticRenderer` to this object, then creates a `BlockRenderPipeline` for this object with the texture `blockTexture` provided by `YourMod`. After this is done, the `build()` method is called to finish the creation of the rendering pipeline and return a function for rendering the block. + +## Renderers +The following are all the renderers you can use in nova. + +### `StaticRenderer` +This is used for rendering providers that only redraw the renderer when either the provider notifies the renderer to do so, or in case of blocks, the world notifies the renderer. To notify the block's `StaticRenderer` to redraw the model, you would call the following code: + +```java +world().markStaticRender(position()); +``` + +### `DynamicRenderer` +This is used for rendering providers that redraw the renderer every frame. This renderer should only be reserved for providers which truly need it. + +## Render pipelines +Actual rendering is done using pipelines. You can either provide your own, or use any of these pre-built ones. To finish rendering with a pre-built pipeline, you have to call the `build()` method on the instance. + +```java +components.add(new StaticRenderer().onRender(new RenderPipeline(this).build()); +``` + +Where `RenderPipeline` is an implementation of the `RenderPipeline` abstract class. The following are implementations of the `RenderPipeline` class that come with NOVA which can be used on any provider type. + +### `BlockRenderPipeline` +This is used for rendering simple cubes. + +### `ItemRenderPipeline` +This is used for rendering flat one voxel thick squares. + +## Models +NOVA also allows using of models to render renderable component providers. To load a model, you do the following: + +```java +providedModel = renderManager.registerModel(new ModelProvider(MOD_ID, "grinder")); +``` + +Where `ModelProvieder` is an implementation of the `ModelProvider` abstract class. The following are implementations of the `ModelProvider` class that come with NOVA. + +To render the model, you have to provide your own rendering pipeline. The following is a simple way to render the model shown above. + +```java +components.add(new StaticRenderer().onRender(model -> { + Model providedModel = YourMod.providedModel.getModel(); + + if (providedModel instanceof MeshModel) + ((MeshModel)providedModel).bindAll(YourMod.providedModelTexture); + + model.children.add(grinderModel); +} +``` + +### `WavefrontObjectModelProvider` +Loads wavefront `.obj` models for use by your mod. Wavefront models are some of the most common model formats in use on the Internet. + +### `TechneModelProvider` +Loads Techne `.tcn` models for use by your mod. Techne was created to easily make entity models for Minecraft, but it has seen application of it's model format in other places as well, such as rendering blocks and items. + +### Advanced model usage + +It is also possible to do some more advanced things when rendering models. The following is the code of `BlockStateful`'s rendering pipeline from NOVA Blocks Example. + +```java +components.add(new StaticRenderer().onRender(model -> { + Model grinderModel = NovaBlock.grinderModel.getModel(); + + grinderModel + .combineChildren("crank", "crank1", "crank2", "crank3") + .matrix.rotate(new Rotation(RotationUtil.DEFAULT_ORDER, 0, 0, angle)); + + if (grinderModel instanceof MeshModel) + ((MeshModel)grinderModel).bindAll(NovaBlock.grinderTexture); + + model.children.add(grinderModel); +})); +``` diff --git a/mkdocs.yml b/mkdocs.yml index ed19201..54ce637 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -17,6 +17,7 @@ pages: - Blocks: Mod Development/Blocks.md - Items: Mod Development/Items.md - Events: Mod Development/Events.md + - Rendering: Mod Development/Rendering.md - NOVA Development: - Development Workspace Setup: NOVA Development/Development Workspace Setup.md - Formatting: NOVA Development/Formatting.md