Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SpriteBlockEntity rendering issues #52

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

import dev.hephaestus.glowcase.Glowcase;
import dev.hephaestus.glowcase.block.entity.SpriteBlockEntity;
import dev.hephaestus.glowcase.mixin.client.TextureManagerAccessor;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.*;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.resource.ResourceManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.RotationAxis;
import org.joml.Vector3f;

import java.io.FileNotFoundException;

public record SpriteBlockEntityRenderer(BlockEntityRendererFactory.Context context) implements BlockEntityRenderer<SpriteBlockEntity> {
private static final Vector3f[] vertices = new Vector3f[] {
new Vector3f(-0.5F, -0.5F, 0.0F),
Expand All @@ -32,7 +39,23 @@ public void render(SpriteBlockEntity entity, float f, MatrixStack matrices, Vert
}

var entry = matrices.peek();
var vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getEntityCutout(Glowcase.id("textures/sprite/" + entity.sprite + ".png")));
Identifier identifier = Identifier.tryParse(Glowcase.MODID, "textures/sprite/" + entity.sprite + ".png");
if (identifier == null) {
identifier = Glowcase.id("textures/sprite/invalid.png");
} else {
TextureManager textureManager = MinecraftClient.getInstance().getTextureManager();
ResourceManager resourceManager = ((TextureManagerAccessor) textureManager).glowcase$getResourceManager();
try {
resourceManager.getResourceOrThrow(identifier);
} catch (FileNotFoundException ignored) {
/* if the texture (file) does not exist, just replace it.
this happens a lot when edit a sprite block, so I'm adding it to avoid log spam
- SkyNotTheLimit
*/
identifier = Glowcase.id("textures/sprite/invalid.png");
}
}
var vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getEntityCutout(identifier));

vertex(entry, vertexConsumer, vertices[0], 0, 1, entity.color);
vertex(entry, vertexConsumer, vertices[1], 1, 1, entity.color);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/hephaestus/glowcase/item/LockItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public ActionResult useOnBlock(ItemUsageContext context) {
Text message;
SoundEvent soundEvent;

if (bea.getLock().equals(ContainerLock.EMPTY)) {
bea.setLock(new ContainerLock("glowcase"));
if (bea.glowcase$getLock().equals(ContainerLock.EMPTY)) {
bea.glowcase$setLock(new ContainerLock("glowcase"));
message = Text.translatable("gui.glowcase.locked_block", be.getDisplayName());
soundEvent = SoundEvents.BLOCK_WOODEN_TRAPDOOR_CLOSE;
} else {
bea.setLock(ContainerLock.EMPTY);
bea.glowcase$setLock(ContainerLock.EMPTY);
message = Text.translatable("gui.glowcase.unlocked_block", be.getDisplayName());
soundEvent = SoundEvents.BLOCK_WOODEN_TRAPDOOR_OPEN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

@Mixin(LockableContainerBlockEntity.class)
public interface LockableContainerBlockEntityAccessor {
@Accessor
ContainerLock getLock();
@Accessor("lock")
ContainerLock glowcase$getLock();

@Accessor
void setLock(ContainerLock lock);
@Accessor("lock")
void glowcase$setLock(ContainerLock lock);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.hephaestus.glowcase.mixin;
package dev.hephaestus.glowcase.mixin.client;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import dev.hephaestus.glowcase.client.gui.screen.ingame.TextBlockEditScreen;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.hephaestus.glowcase.mixin.client;

import net.minecraft.client.texture.TextureManager;
import net.minecraft.resource.ResourceManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(TextureManager.class)
public interface TextureManagerAccessor {

@Accessor("resourceContainer")
ResourceManager glowcase$getResourceManager();
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/main/resources/glowcase.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"PlayerEntityMixin"
],
"client": [
"KeyboardMixin"
"client.KeyboardMixin",
"client.TextureManagerAccessor"
],
"server": [],
"injectors": {
Expand Down