Skip to content

Commit

Permalink
consistent style for hyperlink and popup blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Nov 17, 2024
1 parent 40671e8 commit d77d15c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,31 @@

import dev.hephaestus.glowcase.Glowcase;
import dev.hephaestus.glowcase.block.entity.HyperlinkBlockEntity;
import dev.hephaestus.glowcase.client.util.BlockEntityUtil;
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;
import org.joml.Quaternionf;

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);
Quaternionf rotation = RotationAxis.POSITIVE_Y.rotationDegrees(-camera.getYaw()).mul(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch()));
BlockEntityUtil.renderPlaceholder(entity.getCachedState(), ITEM_TEXTURE, rotation, matrices, vertexConsumers);

HitResult hitResult = mc.crosshairTarget;
matrices.push();
HitResult hitResult = MinecraftClient.getInstance().crosshairTarget;
if (hitResult instanceof BlockHitResult && ((BlockHitResult) hitResult).getBlockPos().equals(entity.getPos())) {
float scale = 0.025F;
matrices.scale(scale, scale, scale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,30 @@

import dev.hephaestus.glowcase.Glowcase;
import dev.hephaestus.glowcase.block.entity.PopupBlockEntity;
import dev.hephaestus.glowcase.client.util.BlockEntityUtil;
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;
import org.joml.Quaternionf;

public record PopupBlockEntityRenderer(BlockEntityRendererFactory.Context context) implements BlockEntityRenderer<PopupBlockEntity> {

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);
Quaternionf rotation = RotationAxis.POSITIVE_Y.rotationDegrees(-camera.getYaw()).mul(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch()));
BlockEntityUtil.renderPlaceholder(entity.getCachedState(), ITEM_TEXTURE, rotation, matrices, vertexConsumers);

matrices.push();
HitResult hitResult = MinecraftClient.getInstance().crosshairTarget;
if (hitResult instanceof BlockHitResult && ((BlockHitResult) hitResult).getBlockPos().equals(entity.getPos())) {
float scale = 0.025F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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 BlockEntityUtil {
Expand All @@ -24,13 +25,14 @@ public class BlockEntityUtil {
new Vector3f(-0.5F, 0.5F, 0.0F)
};

public static void renderPlaceholder(BlockState state, Identifier texture, MatrixStack matrices, VertexConsumerProvider vertexConsumers) {
public static void renderPlaceholder(BlockState state, Identifier texture, Quaternionf rotation, MatrixStack matrices, VertexConsumerProvider vertexConsumers) {
matrices.push();
matrices.translate(0.5, 0.5, 0.5);
if (state.contains(Properties.ROTATION)) {
float rotation = -(state.get(Properties.ROTATION) * 360) / 16.0F;
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(rotation));
float blockRotation = -(state.get(Properties.ROTATION) * 360) / 16.0F;
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(blockRotation));
}
matrices.multiply(rotation);
var entry = matrices.peek();
var vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getEntityCutout(texture));
placeholderVertex(entry, vertexConsumer, placeholderVertices[0], 0, 1);
Expand All @@ -44,6 +46,10 @@ public static void renderPlaceholder(BlockState state, Identifier texture, Matri
matrices.pop();
}

public static void renderPlaceholder(BlockState state, Identifier texture, MatrixStack matrices, VertexConsumerProvider vertexConsumers) {
renderPlaceholder(state, texture, RotationAxis.POSITIVE_Y.rotationDegrees(0), matrices, vertexConsumers);
}

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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
]
}
"layer0": "glowcase:item/hyperlink_block"
}
}
49 changes: 3 additions & 46 deletions src/main/resources/assets/glowcase/models/item/popup_block.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/assets/glowcase/textures/item/popup_block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d77d15c

Please sign in to comment.