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 b23ce31..09b8051 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,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 { private static final Vector3f[] vertices = new Vector3f[] { new Vector3f(-0.5F, -0.5F, 0.0F), @@ -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); diff --git a/src/main/java/dev/hephaestus/glowcase/item/LockItem.java b/src/main/java/dev/hephaestus/glowcase/item/LockItem.java index f30487f..8a445ac 100644 --- a/src/main/java/dev/hephaestus/glowcase/item/LockItem.java +++ b/src/main/java/dev/hephaestus/glowcase/item/LockItem.java @@ -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; } diff --git a/src/main/java/dev/hephaestus/glowcase/mixin/LockableContainerBlockEntityAccessor.java b/src/main/java/dev/hephaestus/glowcase/mixin/LockableContainerBlockEntityAccessor.java index 8b95c09..3ddfb28 100644 --- a/src/main/java/dev/hephaestus/glowcase/mixin/LockableContainerBlockEntityAccessor.java +++ b/src/main/java/dev/hephaestus/glowcase/mixin/LockableContainerBlockEntityAccessor.java @@ -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); } diff --git a/src/main/java/dev/hephaestus/glowcase/mixin/KeyboardMixin.java b/src/main/java/dev/hephaestus/glowcase/mixin/client/KeyboardMixin.java similarity index 94% rename from src/main/java/dev/hephaestus/glowcase/mixin/KeyboardMixin.java rename to src/main/java/dev/hephaestus/glowcase/mixin/client/KeyboardMixin.java index 02281c1..7952545 100644 --- a/src/main/java/dev/hephaestus/glowcase/mixin/KeyboardMixin.java +++ b/src/main/java/dev/hephaestus/glowcase/mixin/client/KeyboardMixin.java @@ -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; diff --git a/src/main/java/dev/hephaestus/glowcase/mixin/client/TextureManagerAccessor.java b/src/main/java/dev/hephaestus/glowcase/mixin/client/TextureManagerAccessor.java new file mode 100644 index 0000000..5dc4301 --- /dev/null +++ b/src/main/java/dev/hephaestus/glowcase/mixin/client/TextureManagerAccessor.java @@ -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(); +} diff --git a/src/main/resources/assets/glowcase/textures/sprite/invalid.png b/src/main/resources/assets/glowcase/textures/sprite/invalid.png new file mode 100644 index 0000000..6d69d8e Binary files /dev/null and b/src/main/resources/assets/glowcase/textures/sprite/invalid.png differ diff --git a/src/main/resources/glowcase.mixins.json b/src/main/resources/glowcase.mixins.json index 2dd784e..6644548 100644 --- a/src/main/resources/glowcase.mixins.json +++ b/src/main/resources/glowcase.mixins.json @@ -8,7 +8,8 @@ "PlayerEntityMixin" ], "client": [ - "KeyboardMixin" + "client.KeyboardMixin", + "client.TextureManagerAccessor" ], "server": [], "injectors": {