diff --git a/src/main/java/dev/hephaestus/glowcase/Glowcase.java b/src/main/java/dev/hephaestus/glowcase/Glowcase.java index 8aa7a67..fe9400d 100644 --- a/src/main/java/dev/hephaestus/glowcase/Glowcase.java +++ b/src/main/java/dev/hephaestus/glowcase/Glowcase.java @@ -78,14 +78,14 @@ public class Glowcase implements ModInitializer { .displayName(Text.translatable("itemGroup.glowcase.items")) .icon(() -> new ItemStack(Items.GLOWSTONE)) .entries((displayContext, entries) -> { - entries.add(HYPERLINK_BLOCK_ITEM.get()); - entries.add(ITEM_DISPLAY_BLOCK_ITEM.get()); entries.add(TEXT_BLOCK_ITEM.get()); - entries.add(POPUP_BLOCK_ITEM.get()); entries.add(SPRITE_BLOCK_ITEM.get()); entries.add(OUTLINE_BLOCK_ITEM.get()); - entries.add(LOCK_ITEM.get()); entries.add(PARTICLE_DISPLAY_ITEM.get()); + entries.add(ITEM_DISPLAY_BLOCK_ITEM.get()); + entries.add(HYPERLINK_BLOCK_ITEM.get()); + entries.add(POPUP_BLOCK_ITEM.get()); + entries.add(LOCK_ITEM.get()); }) .build() ); diff --git a/src/main/java/dev/hephaestus/glowcase/client/GlowcaseClient.java b/src/main/java/dev/hephaestus/glowcase/client/GlowcaseClient.java index 50462f2..6b16237 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/GlowcaseClient.java +++ b/src/main/java/dev/hephaestus/glowcase/client/GlowcaseClient.java @@ -5,6 +5,7 @@ import dev.hephaestus.glowcase.client.render.block.entity.HyperlinkBlockEntityRenderer; import dev.hephaestus.glowcase.client.render.block.entity.ItemDisplayBlockEntityRenderer; import dev.hephaestus.glowcase.client.render.block.entity.OutlineBlockEntityRenderer; +import dev.hephaestus.glowcase.client.render.block.entity.ParticleDisplayBlockEntityRenderer; import dev.hephaestus.glowcase.client.render.block.entity.PopupBlockEntityRenderer; import dev.hephaestus.glowcase.client.render.block.entity.SpriteBlockEntityRenderer; import dev.hephaestus.glowcase.client.render.block.entity.TextBlockEntityRenderer; @@ -24,6 +25,7 @@ public void onInitializeClient() { BlockEntityRendererFactories.register(Glowcase.POPUP_BLOCK_ENTITY.get(), PopupBlockEntityRenderer::new); BlockEntityRendererFactories.register(Glowcase.SPRITE_BLOCK_ENTITY.get(), SpriteBlockEntityRenderer::new); BlockEntityRendererFactories.register(Glowcase.OUTLINE_BLOCK_ENTITY.get(), OutlineBlockEntityRenderer::new); + BlockEntityRendererFactories.register(Glowcase.PARTICLE_DISPLAY_BLOCK_ENTITY.get(), ParticleDisplayBlockEntityRenderer::new); WorldRenderEvents.AFTER_TRANSLUCENT.register(BakedBlockEntityRenderer.Manager::render); InvalidateRenderStateCallback.EVENT.register(BakedBlockEntityRenderer.Manager::reset); diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/BakedBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/BakedBlockEntityRenderer.java index 56cca49..42ef343 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/BakedBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/BakedBlockEntityRenderer.java @@ -36,8 +36,6 @@ import java.util.Set; public abstract class BakedBlockEntityRenderer implements BlockEntityRenderer { - protected static final MinecraftClient mc = MinecraftClient.getInstance(); - protected final BlockEntityRendererFactory.Context context; protected BakedBlockEntityRenderer(BlockEntityRendererFactory.Context context) { @@ -118,11 +116,10 @@ private static class CachedVertexConsumerProvider implements VertexConsumerProvi @Override public VertexConsumer getBuffer(RenderLayer l) { var allocator = allocators.computeIfAbsent(l, l1 -> new BufferAllocator(l.getExpectedBufferSize())); - var builder = builders.computeIfAbsent(l, l1 -> new BufferBuilder( + return builders.computeIfAbsent(l, l1 -> new BufferBuilder( allocator, l.getDrawMode(), l.getVertexFormat())); - return builder; } /** @@ -223,7 +220,7 @@ public static void render(WorldRenderContext wrc) { boolean bakedAnything = false; for (BlockEntity be : blockEntities) { - if (mc.getBlockEntityRenderDispatcher().get(be) instanceof BakedBlockEntityRenderer renderer && renderer.shouldBake(be)) { + if (MinecraftClient.getInstance().getBlockEntityRenderDispatcher().get(be) instanceof BakedBlockEntityRenderer renderer && renderer.shouldBake(be)) { BlockPos pos = be.getPos(); bakeMatrices.push(); bakeMatrices.translate(pos.getX() & MAX_XZ_IN_REGION, pos.getY(), pos.getZ() & MAX_XZ_IN_REGION); diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java index 066e36f..ae1bada 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java @@ -2,38 +2,33 @@ import dev.hephaestus.glowcase.Glowcase; import dev.hephaestus.glowcase.block.entity.HyperlinkBlockEntity; +import dev.hephaestus.glowcase.client.util.BlockEntityRenderUtil; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer.TextLayerType; import net.minecraft.client.render.Camera; import net.minecraft.client.render.LightmapTextureManager; -import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.block.entity.BlockEntityRenderer; import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; -import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.RotationAxis; public record HyperlinkBlockEntityRenderer(BlockEntityRendererFactory.Context context) implements BlockEntityRenderer { - private static final MinecraftClient mc = MinecraftClient.getInstance(); - - public static final ItemStack STACK = new ItemStack(Glowcase.HYPERLINK_BLOCK.get()); + public static Identifier ITEM_TEXTURE = Glowcase.id("textures/item/hyperlink_block.png"); public void render(HyperlinkBlockEntity entity, float f, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { Camera camera = context.getRenderDispatcher().camera; - matrices.push(); - matrices.translate(0.5D, 0.5D, 0.5D); - matrices.scale(0.5F, 0.5F, 0.5F); - float n = -camera.getYaw(); - matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(n)); - matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch())); - context.getItemRenderer().renderItem(STACK, ModelTransformationMode.FIXED, light, OverlayTexture.DEFAULT_UV, matrices, vertexConsumers, entity.getWorld(), 0); + BlockEntityRenderUtil.renderPlaceholder(entity, ITEM_TEXTURE, 0.5F, matrices, vertexConsumers, camera); - HitResult hitResult = mc.crosshairTarget; - if (hitResult instanceof BlockHitResult && ((BlockHitResult) hitResult).getBlockPos().equals(entity.getPos())) { + matrices.push(); + if (MinecraftClient.getInstance().crosshairTarget instanceof BlockHitResult bhr && bhr.getBlockPos().equals(entity.getPos())) { + matrices.translate(0.5D, 0.5D, 0.5D); + matrices.scale(0.5F, 0.5F, 0.5F); + float n = -camera.getYaw(); + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(n)); + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch())); float scale = 0.025F; matrices.scale(scale, scale, scale); matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180)); diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ItemDisplayBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ItemDisplayBlockEntityRenderer.java index 5ca18ad..cba1384 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ItemDisplayBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ItemDisplayBlockEntityRenderer.java @@ -1,6 +1,8 @@ package dev.hephaestus.glowcase.client.render.block.entity; +import dev.hephaestus.glowcase.Glowcase; import dev.hephaestus.glowcase.block.entity.ItemDisplayBlockEntity; +import dev.hephaestus.glowcase.client.util.BlockEntityRenderUtil; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer.TextLayerType; import net.minecraft.client.render.LightmapTextureManager; @@ -17,17 +19,18 @@ import net.minecraft.item.SpawnEggItem; import net.minecraft.state.property.Properties; import net.minecraft.text.Text; +import net.minecraft.util.Identifier; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.RotationAxis; import net.minecraft.util.math.Vec2f; public record ItemDisplayBlockEntityRenderer(BlockEntityRendererFactory.Context context) implements BlockEntityRenderer { - private static final MinecraftClient mc = MinecraftClient.getInstance(); + public static Identifier ITEM_TEXTURE = Glowcase.id("textures/item/item_display_block.png"); @Override public void render(ItemDisplayBlockEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { - Entity camera = mc.getCameraEntity(); + Entity camera = MinecraftClient.getInstance().getCameraEntity(); if (camera == null) return; @@ -100,7 +103,7 @@ public void render(ItemDisplayBlockEntity entity, float tickDelta, MatrixStack m } if (entity.showName) { - HitResult hitResult = mc.crosshairTarget; + HitResult hitResult = MinecraftClient.getInstance().crosshairTarget; if (hitResult instanceof BlockHitResult && ((BlockHitResult) hitResult).getBlockPos().equals(entity.getPos())) { matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180)); matrices.translate(0, 0, -0.4); @@ -115,5 +118,7 @@ public void render(ItemDisplayBlockEntity entity, float tickDelta, MatrixStack m } matrices.pop(); + + if (!entity.hasItem() || BlockEntityRenderUtil.shouldRenderPlaceholder(entity.getPos())) BlockEntityRenderUtil.renderPlaceholder(entity, ITEM_TEXTURE, 1.0F, RotationAxis.POSITIVE_Y.rotationDegrees(180), matrices, vertexConsumers, context.getRenderDispatcher().camera); } } diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/OutlineBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/OutlineBlockEntityRenderer.java index 440017d..9e2cf81 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/OutlineBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/OutlineBlockEntityRenderer.java @@ -1,14 +1,20 @@ package dev.hephaestus.glowcase.client.render.block.entity; +import dev.hephaestus.glowcase.Glowcase; import dev.hephaestus.glowcase.block.entity.OutlineBlockEntity; +import dev.hephaestus.glowcase.client.util.BlockEntityRenderUtil; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.WorldRenderer; import net.minecraft.client.render.block.entity.BlockEntityRenderer; import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.Vec3i; public record OutlineBlockEntityRenderer(BlockEntityRendererFactory.Context context) implements BlockEntityRenderer { + public static Identifier ITEM_TEXTURE = Glowcase.id("textures/item/outline_block.png"); + public void render(OutlineBlockEntity entity, float f, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { double x = entity.offset.getX(); double y = entity.offset.getY(); @@ -21,5 +27,7 @@ public void render(OutlineBlockEntity entity, float f, MatrixStack matrices, Ver float blue = (entity.color & 0xFF) / 255f; WorldRenderer.drawBox(matrices, vertexConsumers.getBuffer(RenderLayer.getLines()), x, y, z, x + width, y + height, z + depth, red, green, blue, 1); + + if (entity.scale.equals(Vec3i.ZERO) || BlockEntityRenderUtil.shouldRenderPlaceholder(entity.getPos())) BlockEntityRenderUtil.renderPlaceholder(entity, ITEM_TEXTURE, 1.0F, matrices, vertexConsumers, context.getRenderDispatcher().camera); } } diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ParticleDisplayBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ParticleDisplayBlockEntityRenderer.java new file mode 100644 index 0000000..44eddd5 --- /dev/null +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ParticleDisplayBlockEntityRenderer.java @@ -0,0 +1,19 @@ +package dev.hephaestus.glowcase.client.render.block.entity; + +import dev.hephaestus.glowcase.Glowcase; +import dev.hephaestus.glowcase.block.entity.ParticleDisplayBlockEntity; +import dev.hephaestus.glowcase.client.util.BlockEntityRenderUtil; +import dev.hephaestus.glowcase.math.DeviatedInteger; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.block.entity.BlockEntityRenderer; +import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Identifier; + +public record ParticleDisplayBlockEntityRenderer(BlockEntityRendererFactory.Context context) implements BlockEntityRenderer { + public static Identifier ITEM_TEXTURE = Glowcase.id("textures/item/particle_display.png"); + + public void render(ParticleDisplayBlockEntity entity, float f, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { + if (entity.count.equals(DeviatedInteger.ZERO) || BlockEntityRenderUtil.shouldRenderPlaceholder(entity.getPos())) BlockEntityRenderUtil.renderPlaceholder(entity, ITEM_TEXTURE, 1.0F, matrices, vertexConsumers, context.getRenderDispatcher().camera); + } +} diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/PopupBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/PopupBlockEntityRenderer.java index 1c0ffa3..c051df9 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/PopupBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/PopupBlockEntityRenderer.java @@ -2,38 +2,33 @@ import dev.hephaestus.glowcase.Glowcase; import dev.hephaestus.glowcase.block.entity.PopupBlockEntity; +import dev.hephaestus.glowcase.client.util.BlockEntityRenderUtil; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer.TextLayerType; import net.minecraft.client.render.Camera; import net.minecraft.client.render.LightmapTextureManager; -import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.block.entity.BlockEntityRenderer; import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; -import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.RotationAxis; public record PopupBlockEntityRenderer(BlockEntityRendererFactory.Context context) implements BlockEntityRenderer { - private static final MinecraftClient mc = MinecraftClient.getInstance(); - - public static final ItemStack STACK = new ItemStack(Glowcase.POPUP_BLOCK.get()); + public static Identifier ITEM_TEXTURE = Glowcase.id("textures/item/popup_block.png"); public void render(PopupBlockEntity entity, float f, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { Camera camera = context.getRenderDispatcher().camera; - matrices.push(); - matrices.translate(0.5D, 0.5D, 0.5D); - matrices.scale(0.5F, 0.5F, 0.5F); - float n = -camera.getYaw(); - matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(n)); - matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch())); - context.getItemRenderer().renderItem(STACK, ModelTransformationMode.FIXED, light, OverlayTexture.DEFAULT_UV, matrices, vertexConsumers, entity.getWorld(), 0); + BlockEntityRenderUtil.renderPlaceholder(entity, ITEM_TEXTURE, 0.5F, matrices, vertexConsumers, camera); - HitResult hitResult = mc.crosshairTarget; - if (hitResult instanceof BlockHitResult && ((BlockHitResult) hitResult).getBlockPos().equals(entity.getPos())) { + matrices.push(); + if (MinecraftClient.getInstance().crosshairTarget instanceof BlockHitResult bhr && bhr.getBlockPos().equals(entity.getPos())) { + matrices.translate(0.5D, 0.5D, 0.5D); + matrices.scale(0.5F, 0.5F, 0.5F); + float n = -camera.getYaw(); + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(n)); + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch())); float scale = 0.025F; matrices.scale(scale, scale, scale); matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180)); diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SpriteBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SpriteBlockEntityRenderer.java index d0b4032..b986716 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SpriteBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SpriteBlockEntityRenderer.java @@ -2,6 +2,7 @@ import dev.hephaestus.glowcase.Glowcase; import dev.hephaestus.glowcase.block.entity.SpriteBlockEntity; +import dev.hephaestus.glowcase.client.util.BlockEntityRenderUtil; import dev.hephaestus.glowcase.mixin.client.TextureManagerAccessor; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.LightmapTextureManager; @@ -20,6 +21,8 @@ import org.joml.Vector3f; public record SpriteBlockEntityRenderer(BlockEntityRendererFactory.Context context) implements BlockEntityRenderer { + public static Identifier ITEM_TEXTURE = Glowcase.id("textures/item/sprite_block.png"); + private static final Vector3f[] vertices = new Vector3f[] { new Vector3f(-0.5F, -0.5F, 0.0F), new Vector3f(0.5F, -0.5F, 0.0F), @@ -64,6 +67,8 @@ If the texture (file) does not exist, just replace it. vertex(entry, vertexConsumer, vertices[3], 0, 0, entity.color); matrices.pop(); + + if (entity.sprite.isEmpty() || BlockEntityRenderUtil.shouldRenderPlaceholder(entity.getPos())) BlockEntityRenderUtil.renderPlaceholder(entity, ITEM_TEXTURE, 1.0F, matrices, vertexConsumers, context.getRenderDispatcher().camera); } private void vertex( diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java index ff73195..8b7b197 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java @@ -1,7 +1,9 @@ package dev.hephaestus.glowcase.client.render.block.entity; +import dev.hephaestus.glowcase.Glowcase; import dev.hephaestus.glowcase.block.entity.TextBlockEntity; import dev.hephaestus.glowcase.client.GlowcaseRenderLayers; +import dev.hephaestus.glowcase.client.util.BlockEntityRenderUtil; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.font.TextRenderer.TextLayerType; import net.minecraft.client.render.LightmapTextureManager; @@ -10,10 +12,13 @@ import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.state.property.Properties; +import net.minecraft.util.Identifier; import net.minecraft.util.math.RotationAxis; import org.joml.Matrix4f; public class TextBlockEntityRenderer extends BakedBlockEntityRenderer { + public static Identifier ITEM_TEXTURE = Glowcase.id("textures/item/text_block.png"); + public TextBlockEntityRenderer(BlockEntityRendererFactory.Context context) { super(context); } @@ -29,36 +34,37 @@ public void renderUnbaked(TextBlockEntity entity, float tickDelta, MatrixStack m entity.renderDirty = false; Manager.markForRebuild(entity.getPos()); } + if (entity.lines.stream().allMatch(t -> t.getString().isBlank()) || BlockEntityRenderUtil.shouldRenderPlaceholder(entity.getPos())) BlockEntityRenderUtil.renderPlaceholder(entity, ITEM_TEXTURE, 1.0F, matrices, vertexConsumers, context.getRenderDispatcher().camera); } @Override - public void renderBaked(TextBlockEntity blockEntity, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { + public void renderBaked(TextBlockEntity entity, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { matrices.push(); matrices.translate(0.5D, 0.5D, 0.5D); - float rotation = -(blockEntity.getCachedState().get(Properties.ROTATION) * 360) / 16.0F; + float rotation = -(entity.getCachedState().get(Properties.ROTATION) * 360) / 16.0F; matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(rotation)); - switch (blockEntity.zOffset) { + switch (entity.zOffset) { case FRONT -> matrices.translate(0D, 0D, 0.4D); case BACK -> matrices.translate(0D, 0D, -0.4D); } - float scale = 0.010416667F * blockEntity.scale; + float scale = 0.010416667F * entity.scale; matrices.scale(scale, -scale, scale); TextRenderer textRenderer = this.context.getTextRenderer(); double maxLength = 0; double minLength = Double.MAX_VALUE; - for (int i = 0; i < blockEntity.lines.size(); ++i) { - maxLength = Math.max(maxLength, textRenderer.getWidth(blockEntity.lines.get(i))); - minLength = Math.min(minLength, textRenderer.getWidth(blockEntity.lines.get(i))); + for (int i = 0; i < entity.lines.size(); ++i) { + maxLength = Math.max(maxLength, textRenderer.getWidth(entity.lines.get(i))); + minLength = Math.min(minLength, textRenderer.getWidth(entity.lines.get(i))); } - matrices.translate(0, -((blockEntity.lines.size() - 0.25) * 12) / 2D, 0D); - for (int i = 0; i < blockEntity.lines.size(); ++i) { - double width = textRenderer.getWidth(blockEntity.lines.get(i)); - double dX = switch (blockEntity.textAlignment) { + matrices.translate(0, -((entity.lines.size() - 0.25) * 12) / 2D, 0D); + for (int i = 0; i < entity.lines.size(); ++i) { + double width = textRenderer.getWidth(entity.lines.get(i)); + double dX = switch (entity.textAlignment) { case LEFT -> -maxLength / 2D; case CENTER -> (maxLength - width) / 2D - maxLength / 2D; case RIGHT -> maxLength - width - maxLength / 2D; @@ -67,13 +73,13 @@ public void renderBaked(TextBlockEntity blockEntity, MatrixStack matrices, Verte matrices.push(); matrices.translate(dX, 0, 0); - if (blockEntity.shadowType == TextBlockEntity.ShadowType.PLATE && width > 0) { + if (entity.shadowType == TextBlockEntity.ShadowType.PLATE && width > 0) { matrices.translate(0, 0, -0.025D); drawFillRect(matrices, vertexConsumers, (int) width + 5, (i + 1) * 12 - 2, -5, i * 12 - 2, 0x44000000); matrices.translate(0, 0, 0.025D); } - textRenderer.draw(blockEntity.lines.get(i), 0, i * 12, blockEntity.color, blockEntity.shadowType == TextBlockEntity.ShadowType.DROP, matrices.peek().getPositionMatrix(), vertexConsumers, TextLayerType.NORMAL, 0, LightmapTextureManager.MAX_LIGHT_COORDINATE); + textRenderer.draw(entity.lines.get(i), 0, i * 12, entity.color, entity.shadowType == TextBlockEntity.ShadowType.DROP, matrices.peek().getPositionMatrix(), vertexConsumers, TextLayerType.NORMAL, 0, LightmapTextureManager.MAX_LIGHT_COORDINATE); matrices.pop(); } diff --git a/src/main/java/dev/hephaestus/glowcase/client/util/BlockEntityRenderUtil.java b/src/main/java/dev/hephaestus/glowcase/client/util/BlockEntityRenderUtil.java new file mode 100644 index 0000000..1aba8ac --- /dev/null +++ b/src/main/java/dev/hephaestus/glowcase/client/util/BlockEntityRenderUtil.java @@ -0,0 +1,77 @@ +package dev.hephaestus.glowcase.client.util; + +import dev.hephaestus.glowcase.Glowcase; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.Camera; +import net.minecraft.client.render.LightmapTextureManager; +import net.minecraft.client.render.OverlayTexture; +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.state.property.Properties; +import net.minecraft.util.Identifier; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RotationAxis; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +public class BlockEntityRenderUtil { + private static final Vector3f[] placeholderVertices = new Vector3f[]{ + new Vector3f(-0.5F, -0.5F, 0.0F), + new Vector3f(0.5F, -0.5F, 0.0F), + new Vector3f(0.5F, 0.5F, 0.0F), + new Vector3f(-0.5F, 0.5F, 0.0F) + }; + + public static void renderPlaceholder(BlockEntity entity, Identifier texture, float scale, Quaternionf rotation, MatrixStack matrices, VertexConsumerProvider vertexConsumers, Camera camera) { + matrices.push(); + matrices.translate(0.5, 0.5, 0.5); + boolean doBillboard = !entity.getCachedState().contains(Properties.ROTATION); + if (doBillboard) { + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180.0F - camera.getYaw())); + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-camera.getPitch())); + } else { + float blockRotation = -(entity.getCachedState().get(Properties.ROTATION) * 360) / 16.0F; + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(blockRotation)); + } + matrices.multiply(rotation); + matrices.scale(scale, scale, scale); + var entry = matrices.peek(); + var vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getEntityCutout(texture)); + boolean hovered = MinecraftClient.getInstance().crosshairTarget instanceof BlockHitResult bhr && bhr.getBlockPos().equals(entity.getPos()); + int color = hovered ? 0x808080 : 0xFFFFFF; + placeholderVertex(entry, vertexConsumer, placeholderVertices[0], 0, 1, color); + placeholderVertex(entry, vertexConsumer, placeholderVertices[1], 1, 1, color); + placeholderVertex(entry, vertexConsumer, placeholderVertices[2], 1, 0, color); + placeholderVertex(entry, vertexConsumer, placeholderVertices[3], 0, 0, color); + if (!doBillboard) { // Draw Reverse Face + int reverseColor = hovered ? 0x404040 : 0x808080; + placeholderVertex(entry, vertexConsumer, placeholderVertices[3], 0, 0, reverseColor); + placeholderVertex(entry, vertexConsumer, placeholderVertices[2], 1, 0, reverseColor); + placeholderVertex(entry, vertexConsumer, placeholderVertices[1], 1, 1, reverseColor); + placeholderVertex(entry, vertexConsumer, placeholderVertices[0], 0, 1, reverseColor); + } + matrices.pop(); + } + + public static void renderPlaceholder(BlockEntity entity, Identifier texture, float scale, MatrixStack matrices, VertexConsumerProvider vertexConsumers, Camera camera) { + renderPlaceholder(entity, texture, scale, RotationAxis.POSITIVE_Y.rotationDegrees(0), matrices, vertexConsumers, camera); + } + + public static boolean shouldRenderPlaceholder(BlockPos pos) { + return MinecraftClient.getInstance().player != null && MinecraftClient.getInstance().player.isHolding(stack -> stack.isIn(Glowcase.ITEM_TAG)) && !(MinecraftClient.getInstance().crosshairTarget instanceof BlockHitResult bhr && bhr.getBlockPos().equals(pos)); + } + + private static void placeholderVertex( + MatrixStack.Entry matrix, VertexConsumer vertexConsumer, Vector3f vertex, float u, float v, int color) { + vertexConsumer.vertex(matrix, vertex.x(), vertex.y(), vertex.z()) + .color(color) + .texture(u, v) + .overlay(OverlayTexture.DEFAULT_UV) + .light(LightmapTextureManager.MAX_LIGHT_COORDINATE) + .normal(0, 1, 0); + } +} diff --git a/src/main/resources/assets/glowcase/models/item/hyperlink_block.json b/src/main/resources/assets/glowcase/models/item/hyperlink_block.json index 59c43c8..342e5a9 100644 --- a/src/main/resources/assets/glowcase/models/item/hyperlink_block.json +++ b/src/main/resources/assets/glowcase/models/item/hyperlink_block.json @@ -1,49 +1,6 @@ { + "parent": "item/generated", "textures": { - "0": "glowcase:item/hyperlink_block", - "particle": "glowcase:item/hyperlink_block" - }, - "elements": [ - { - "from": [ - 2, - 2, - 8 - ], - "to": [ - 14, - 14, - 8 - ], - "rotation": { - "angle": 0, - "axis": "y", - "origin": [ - 8, - 8, - 16 - ] - }, - "faces": { - "north": { - "uv": [ - 0, - 0, - 16, - 16 - ], - "texture": "#0" - }, - "south": { - "uv": [ - 0, - 0, - 16, - 16 - ], - "texture": "#0" - } - } - } - ] -} \ No newline at end of file + "layer0": "glowcase:item/hyperlink_block" + } +} diff --git a/src/main/resources/assets/glowcase/models/item/popup_block.json b/src/main/resources/assets/glowcase/models/item/popup_block.json index 898e040..5759b0a 100644 --- a/src/main/resources/assets/glowcase/models/item/popup_block.json +++ b/src/main/resources/assets/glowcase/models/item/popup_block.json @@ -1,49 +1,6 @@ { + "parent": "item/generated", "textures": { - "0": "glowcase:item/popup_block", - "particle": "glowcase:item/popup_block" - }, - "elements": [ - { - "from": [ - 2, - 2, - 8 - ], - "to": [ - 14, - 14, - 8 - ], - "rotation": { - "angle": 0, - "axis": "y", - "origin": [ - 8, - 8, - 16 - ] - }, - "faces": { - "north": { - "uv": [ - 0, - 0, - 16, - 16 - ], - "texture": "#0" - }, - "south": { - "uv": [ - 0, - 0, - 16, - 16 - ], - "texture": "#0" - } - } - } - ] + "layer0": "glowcase:item/popup_block" + } } diff --git a/src/main/resources/assets/glowcase/textures/item/hyperlink_block.png b/src/main/resources/assets/glowcase/textures/item/hyperlink_block.png index efc93a8..a95f020 100644 Binary files a/src/main/resources/assets/glowcase/textures/item/hyperlink_block.png and b/src/main/resources/assets/glowcase/textures/item/hyperlink_block.png differ diff --git a/src/main/resources/assets/glowcase/textures/item/popup_block.png b/src/main/resources/assets/glowcase/textures/item/popup_block.png index 9a17e05..8f716f1 100644 Binary files a/src/main/resources/assets/glowcase/textures/item/popup_block.png and b/src/main/resources/assets/glowcase/textures/item/popup_block.png differ diff --git a/src/main/resources/assets/glowcase/textures/item/sprite_block.png b/src/main/resources/assets/glowcase/textures/item/sprite_block.png index 00b7df6..230a315 100644 Binary files a/src/main/resources/assets/glowcase/textures/item/sprite_block.png and b/src/main/resources/assets/glowcase/textures/item/sprite_block.png differ