tutorial:blockentityrenderers
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:blockentityrenderers [2022/07/06 18:24] – external edit 127.0.0.1 | tutorial:blockentityrenderers [2024/08/27 04:42] (current) – solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Rendering blocks and items dynamically using block entity renderers ====== | ====== Rendering blocks and items dynamically using block entity renderers ====== | ||
- | //This is the 1.15 & 1.16 version of this tutorial. For the 1.14 version, see [[tutorial: | + | //This is the 1.15+ version of this tutorial. For the 1.14 version, see [[tutorial: |
Make sure you [[tutorial: | Make sure you [[tutorial: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | Blocks by themselves aren't that interesting, | + | Blocks by themselves aren't that interesting, |
===== Example ===== | ===== Example ===== | ||
In this tutorial we'll build off the block entity we created by adding a '' | In this tutorial we'll build off the block entity we created by adding a '' | ||
Line 14: | Line 14: | ||
public class DemoBlockEntityRenderer implements BlockEntityRenderer< | public class DemoBlockEntityRenderer implements BlockEntityRenderer< | ||
// A jukebox itemstack | // A jukebox itemstack | ||
- | private static ItemStack stack = new ItemStack(Items.JUKEBOX, 1); | + | private static |
| | ||
public DemoBlockEntityRenderer(BlockEntityRendererFactory.Context ctx) {} | public DemoBlockEntityRenderer(BlockEntityRendererFactory.Context ctx) {} | ||
Line 25: | Line 25: | ||
We're going to need to register our '' | We're going to need to register our '' | ||
- | Create a new class next to your main class that implements '' | + | In the entrypoint |
<code java> | <code java> | ||
@Environment(EnvType.CLIENT) | @Environment(EnvType.CLIENT) | ||
Line 36: | Line 36: | ||
</ | </ | ||
- | Set this class as the '' | + | Set this class as the '' |
<code javascript " | <code javascript " | ||
- | " | + | { |
+ | [...] | ||
+ | | ||
[...] | [...] | ||
" | " | ||
Line 45: | Line 47: | ||
} | } | ||
] | ] | ||
+ | }, | ||
+ | [...] | ||
} | } | ||
</ | </ | ||
- | And register the '' | + | And register the '' |
<code java> | <code java> | ||
- | @Override | + | |
- | public void onInitializeClient() { | + | public void onInitializeClient() { |
- | | + | |
- | } | + | } |
</ | </ | ||
We override the '' | We override the '' | ||
Line 62: | Line 66: | ||
} | } | ||
</ | </ | ||
- | We then perform the movement of the jukebox (matrices.translate) and rotation (matrices.multiply). There are two parts to the translation: | + | We then perform the movement of the jukebox ('' |
* Getting the current world time, which changes over time. | * Getting the current world time, which changes over time. | ||
* Adding the partial ticks. (The partial ticks is a fractional value representing the amount of time that’s passed between the last full tick and now. We use this because otherwise the animation would be jittery because there are fewer ticks per second than frames per second.) | * Adding the partial ticks. (The partial ticks is a fractional value representing the amount of time that’s passed between the last full tick and now. We use this because otherwise the animation would be jittery because there are fewer ticks per second than frames per second.) | ||
Line 77: | Line 81: | ||
// Rotate the item | // Rotate the item | ||
- | matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion((blockEntity.getWorld().getTime() + tickDelta) * 4)); | + | matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees((blockEntity.getWorld().getTime() + tickDelta) * 4)); |
} | } | ||
</ | </ | ||
- | Finally, we will get the Minecraft ' | + | Finally, we will get the Minecraft ' |
<code java> | <code java> | ||
public void render(DemoBlockEntity blockEntity, | public void render(DemoBlockEntity blockEntity, | ||
[...] | [...] | ||
- | MinecraftClient.getInstance().getItemRenderer().renderItem(stack, | + | MinecraftClient.getInstance().getItemRenderer().renderItem(stack, |
// Mandatory call after GL calls | // Mandatory call after GL calls | ||
Line 93: | Line 97: | ||
You can try your newly created block entity renderer right now. However, if you didn't make your block transparent, | You can try your newly created block entity renderer right now. However, if you didn't make your block transparent, | ||
- | To get the light, we call '' | + | To get the light, we call '' |
- | and to use the light we use it in '' | + | |
<code java> | <code java> | ||
@Override | @Override | ||
Line 101: | Line 104: | ||
| | ||
int lightAbove = WorldRenderer.getLightmapCoordinates(blockEntity.getWorld(), | int lightAbove = WorldRenderer.getLightmapCoordinates(blockEntity.getWorld(), | ||
- | MinecraftClient.getInstance().getItemRenderer().renderItem(stack, | + | MinecraftClient.getInstance().getItemRenderer().renderItem(stack, |
| | ||
[...] | [...] | ||
Line 110: | Line 113: | ||
===== Rendering according to block entity data ===== | ===== Rendering according to block entity data ===== | ||
- | Sometimes you wants to render according to the block entity data (nbt), and you find they are all empty, even if you can access the data through ''/ | + | Sometimes you want to render according to the block entity data (nbt), and you find they are all empty, even if you can access the data through ''/ |
tutorial/blockentityrenderers.1657131879.txt.gz · Last modified: 2022/07/06 18:24 by 127.0.0.1