Skip to content

Commit

Permalink
Merge pull request ModFest#55 from sisby-folk/1.21
Browse files Browse the repository at this point in the history
Add placeholder renders for blocks, change some textures
  • Loading branch information
sisby-folk authored Nov 18, 2024
2 parents 10a19bb + 0e24fcf commit ad71496
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 150 deletions.
8 changes: 4 additions & 4 deletions src/main/java/dev/hephaestus/glowcase/Glowcase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import java.util.Set;

public abstract class BakedBlockEntityRenderer<T extends BlockEntity> implements BlockEntityRenderer<T> {
protected static final MinecraftClient mc = MinecraftClient.getInstance();

protected final BlockEntityRendererFactory.Context context;

protected BakedBlockEntityRenderer(BlockEntityRendererFactory.Context context) {
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HyperlinkBlockEntity> {
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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ItemDisplayBlockEntity> {
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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<OutlineBlockEntity> {
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();
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<ParticleDisplayBlockEntity> {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<PopupBlockEntity> {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,8 @@
import org.joml.Vector3f;

public record SpriteBlockEntityRenderer(BlockEntityRendererFactory.Context context) implements BlockEntityRenderer<SpriteBlockEntity> {
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),
Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit ad71496

Please sign in to comment.