|
51 | 51 | import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; |
52 | 52 | import net.minecraft.client.renderer.GameRenderer; |
53 | 53 | import net.minecraft.client.renderer.LevelRenderer; |
| 54 | +import net.minecraft.client.renderer.LightTexture; |
54 | 55 | import net.minecraft.client.renderer.MultiBufferSource; |
55 | 56 | import net.minecraft.client.renderer.Sheets; |
56 | 57 | import net.minecraft.client.renderer.block.model.BakedQuad; |
|
76 | 77 | import org.joml.Matrix4f; |
77 | 78 |
|
78 | 79 | public class RenderHelper { |
79 | | - private static final Supplier<BakedQuad[]> OVERLAY_QUADS; |
80 | | - private static final float W = 0.05f; |
81 | | - private static final ResourceLocation LOCKED_TEXTURE_LOCATION = MI.id("block/locked"); |
| 80 | + private static final ResourceLocation HATCH_PLACEMENT_OVERLAY_LOCATION = MI.id("block/hatch_placement_overlay"); |
| 81 | + @Nullable |
| 82 | + private static OverlayQuads overlayQuads; |
| 83 | + |
| 84 | + private record OverlayQuads(BakedQuad[] quads, TextureAtlasSprite sprite) { |
| 85 | + } |
82 | 86 |
|
83 | | - public static void drawOverlay(PoseStack ms, MultiBufferSource vcp, float r, float g, float b, int light, int overlay) { |
84 | | - VertexConsumer vc = vcp.getBuffer(MIRenderTypes.solidHighlight()); |
85 | | - for (BakedQuad overlayQuad : OVERLAY_QUADS.get()) { |
86 | | - vc.putBulkData(ms.last(), overlayQuad, r, g, b, 1.0f, light, overlay); |
| 87 | + public static void drawOverlay(PoseStack ms, MultiBufferSource vcp, int overlay) { |
| 88 | + var sprite = Minecraft.getInstance().getTextureAtlas(InventoryMenu.BLOCK_ATLAS).apply(HATCH_PLACEMENT_OVERLAY_LOCATION); |
| 89 | + if (overlayQuads == null || overlayQuads.sprite() != sprite) { |
| 90 | + overlayQuads = new OverlayQuads(buildOverlayQuads(sprite), sprite); |
| 91 | + } |
| 92 | + VertexConsumer vc = vcp.getBuffer(MIRenderTypes.cutoutHighlight()); |
| 93 | + for (BakedQuad overlayQuad : overlayQuads.quads) { |
| 94 | + vc.putBulkData(ms.last(), overlayQuad, 1.0f, 1.0f, 1.0f, 1.0f, LightTexture.FULL_BRIGHT, /* not used by shader */ overlay); |
87 | 95 | } |
88 | 96 | } |
89 | 97 |
|
90 | | - static { |
91 | | - OVERLAY_QUADS = Suppliers.memoize(() -> { |
92 | | - var overlayQuads = new BakedQuad[24]; |
93 | | - QuadEmitter emitter = new QuadBuffer(); |
94 | | - for (Direction direction : Direction.values()) { |
95 | | - emitter.emit(); |
96 | | - emitter.square(direction, 0, 0, 1, W, 0); |
97 | | - overlayQuads[direction.get3DDataValue() * 4] = emitter.toBakedQuad(null); |
98 | | - emitter.square(direction, 0, 1 - W, 1, 1, 0); |
99 | | - overlayQuads[direction.get3DDataValue() * 4 + 1] = emitter.toBakedQuad(null); |
100 | | - emitter.square(direction, 0, W, W, 1 - W, 0); |
101 | | - overlayQuads[direction.get3DDataValue() * 4 + 2] = emitter.toBakedQuad(null); |
102 | | - emitter.square(direction, 1 - W, W, 1, 1 - W, 0); |
103 | | - overlayQuads[direction.get3DDataValue() * 4 + 3] = emitter.toBakedQuad(null); |
104 | | - } |
105 | | - return overlayQuads; |
106 | | - }); |
| 98 | + private static BakedQuad[] buildOverlayQuads(TextureAtlasSprite sprite) { |
| 99 | + var overlayQuads = new BakedQuad[6]; |
| 100 | + QuadEmitter emitter = new QuadBuffer(); |
| 101 | + for (Direction direction : Direction.values()) { |
| 102 | + emitter.emit(); |
| 103 | + emitter.square(direction, 0, 0, 1, 1, 0); |
| 104 | + emitter.spriteBake(sprite, MutableQuadView.BAKE_LOCK_UV); |
| 105 | + overlayQuads[direction.get3DDataValue()] = emitter.toBakedQuad(sprite); |
| 106 | + } |
| 107 | + return overlayQuads; |
107 | 108 | } |
108 | 109 |
|
109 | 110 | private static final Supplier<BakedQuad[]> CUBE_QUADS; |
110 | 111 |
|
111 | 112 | public static void drawCube(PoseStack ms, MultiBufferSource vcp, float r, float g, float b, int light, int overlay) { |
112 | | - VertexConsumer vc = vcp.getBuffer(MIRenderTypes.solidHighlight()); |
| 113 | + VertexConsumer vc = vcp.getBuffer(MIRenderTypes.cutoutHighlight()); |
113 | 114 | for (BakedQuad cubeQuad : CUBE_QUADS.get()) { |
114 | 115 | vc.putBulkData(ms.last(), cubeQuad, r, g, b, 1.0f, light, overlay); |
115 | 116 | } |
@@ -226,6 +227,8 @@ public static void quadWithAlpha(VertexConsumer consumer, PoseStack.Pose matrixE |
226 | 227 | consumer.putBulkData(matrixEntry, quad, red, green, blue, alpha, light, overlay); |
227 | 228 | } |
228 | 229 |
|
| 230 | + private static final ResourceLocation LOCKED_TEXTURE_LOCATION = MI.id("block/locked"); |
| 231 | + |
229 | 232 | public static void drawLockedTexture(BlockEntity entity, PoseStack matrices, MultiBufferSource vertexConsumers, int colorRgb) { |
230 | 233 | VertexConsumer vc = vertexConsumers.getBuffer(Sheets.cutoutBlockSheet()); |
231 | 234 | var sprite = Minecraft.getInstance().getTextureAtlas(InventoryMenu.BLOCK_ATLAS).apply(LOCKED_TEXTURE_LOCATION); |
|
0 commit comments