diff --git a/common/src/main/java/net/blay09/mods/refinedrelocation/SortingChestType.java b/common/src/main/java/net/blay09/mods/refinedrelocation/SortingChestType.java index 6f34152..319438c 100644 --- a/common/src/main/java/net/blay09/mods/refinedrelocation/SortingChestType.java +++ b/common/src/main/java/net/blay09/mods/refinedrelocation/SortingChestType.java @@ -11,7 +11,7 @@ import java.util.Locale; public enum SortingChestType implements StringRepresentable { - WOOD(27, 9, "sorting_chest", "normal", ResourceLocation.withDefaultNamespace("textures/gui/container/generic_54.png"), 176, 168, 256, 256), + WOOD(27, 9, "sorting_chest", "oak", ResourceLocation.withDefaultNamespace("textures/gui/container/generic_54.png"), 176, 168, 256, 256), IRON(54, 9, "sorting_iron_chest", "iron", ResourceLocation.withDefaultNamespace("textures/gui/container/generic_54.png"), 176, 222, 256, 256), GOLD(84, 12, "sorting_gold_chest", "gold", ResourceLocation.fromNamespaceAndPath(RefinedRelocation.MOD_ID, "textures/gui/gold_chest.png"), 230, 240, 230, 240), DIAMOND(112, 16, "sorting_diamond_chest", "diamond", ResourceLocation.fromNamespaceAndPath(RefinedRelocation.MOD_ID, "textures/gui/diamond_chest.png"), 302, 240, 302, 240); @@ -51,7 +51,7 @@ public BlockEntityType getBlockEntityType() { } public ResourceLocation getTextureLocation() { - return ResourceLocation.fromNamespaceAndPath(RefinedRelocation.MOD_ID, "entity/sorting_chest/" + texture); + return ResourceLocation.withDefaultNamespace("entity/sorting_chest/" + texture); } public Material getMaterial() { diff --git a/common/src/main/java/net/blay09/mods/refinedrelocation/fabric/client/ModRenderers.java b/common/src/main/java/net/blay09/mods/refinedrelocation/fabric/client/ModRenderers.java index 2945172..bc1f5c3 100644 --- a/common/src/main/java/net/blay09/mods/refinedrelocation/fabric/client/ModRenderers.java +++ b/common/src/main/java/net/blay09/mods/refinedrelocation/fabric/client/ModRenderers.java @@ -2,12 +2,12 @@ import net.blay09.mods.balm.api.client.rendering.BalmRenderers; import net.blay09.mods.refinedrelocation.block.entity.ModBlockEntities; -import net.blay09.mods.refinedrelocation.fabric.client.render.SortingChestTileEntityRenderer; +import net.blay09.mods.refinedrelocation.fabric.client.render.SortingChestBlockEntityRenderer; public class ModRenderers { public static void initialize(BalmRenderers renderers) { for (final var sortingChest : ModBlockEntities.sortingChests) { - renderers.registerBlockEntityRenderer(sortingChest::get, SortingChestTileEntityRenderer::new); + renderers.registerBlockEntityRenderer(sortingChest::get, SortingChestBlockEntityRenderer::new); } } } diff --git a/common/src/main/java/net/blay09/mods/refinedrelocation/fabric/client/render/SortingChestBlockEntityRenderer.java b/common/src/main/java/net/blay09/mods/refinedrelocation/fabric/client/render/SortingChestBlockEntityRenderer.java new file mode 100644 index 0000000..6326056 --- /dev/null +++ b/common/src/main/java/net/blay09/mods/refinedrelocation/fabric/client/render/SortingChestBlockEntityRenderer.java @@ -0,0 +1,59 @@ +package net.blay09.mods.refinedrelocation.fabric.client.render; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Axis; +import net.blay09.mods.refinedrelocation.block.SortingChestBlock; +import net.blay09.mods.refinedrelocation.block.entity.SortingChestBlockEntity; +import net.minecraft.client.model.geom.ModelLayers; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.client.renderer.blockentity.ChestRenderer; +import net.minecraft.client.resources.model.Material; + +public class SortingChestBlockEntityRenderer extends ChestRenderer { + + private static final String BOTTOM = "bottom"; + private static final String LID = "lid"; + private static final String LOCK = "lock"; + + private final ModelPart lid; + private final ModelPart bottom; + private final ModelPart lock; + + public SortingChestBlockEntityRenderer(BlockEntityRendererProvider.Context context) { + super(context); + + final var modelPart = context.bakeLayer(ModelLayers.CHEST); + bottom = modelPart.getChild(BOTTOM); + lid = modelPart.getChild(LID); + lock = modelPart.getChild(LOCK); + } + + @Override + public void render(SortingChestBlockEntity sortingChest, float partialTicks, PoseStack poseStack, MultiBufferSource multiBufferSource, int brightness, int overlay) { + final var state = sortingChest.getBlockState(); + poseStack.pushPose(); + float yRot = state.getValue(SortingChestBlock.FACING).toYRot(); + poseStack.translate(0.5f, 0.5f, 0.5f); + poseStack.mulPose(Axis.YP.rotationDegrees(-yRot)); + poseStack.translate(-0.5f, -0.5f, -0.5f); + + final var openness = sortingChest.getOpenNess(partialTicks); + final var material = getMaterial(sortingChest); + final var buffer = material.buffer(multiBufferSource, RenderType::entityCutout); + + lid.xRot = -(openness * 1.5707964F); + lock.xRot = lid.xRot; + lid.render(poseStack, buffer, brightness, overlay); + lock.render(poseStack, buffer, brightness, overlay); + bottom.render(poseStack, buffer, brightness, overlay); + + poseStack.popPose(); + } + + private Material getMaterial(SortingChestBlockEntity blockEntity) { + return blockEntity.getChestType().getMaterial(); + } +} diff --git a/common/src/main/java/net/blay09/mods/refinedrelocation/fabric/client/render/SortingChestTileEntityRenderer.java b/common/src/main/java/net/blay09/mods/refinedrelocation/fabric/client/render/SortingChestTileEntityRenderer.java deleted file mode 100644 index 4e4ec4b..0000000 --- a/common/src/main/java/net/blay09/mods/refinedrelocation/fabric/client/render/SortingChestTileEntityRenderer.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.blay09.mods.refinedrelocation.fabric.client.render; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.blay09.mods.refinedrelocation.block.entity.SortingChestBlockEntity; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; -import net.minecraft.client.renderer.blockentity.ChestRenderer; -import net.minecraft.client.resources.model.Material; -import net.minecraft.world.level.block.state.properties.ChestType; - -public class SortingChestTileEntityRenderer extends ChestRenderer { - - public SortingChestTileEntityRenderer(BlockEntityRendererProvider.Context context) { - super(context); - } - - @Override - public void render(SortingChestBlockEntity $$0, float $$1, PoseStack $$2, MultiBufferSource $$3, int $$4, int $$5) { - super.render($$0, $$1, $$2, $$3, $$4, $$5); - } - - // @Override TODO oof - protected Material getMaterial(SortingChestBlockEntity tileEntity, ChestType chestType) { - return tileEntity.getChestType().getMaterial(); - } -} diff --git a/common/src/main/resources/assets/minecraft/atlases/chests.json b/common/src/main/resources/assets/minecraft/atlases/chests.json index 603b6eb..53a7ee8 100644 --- a/common/src/main/resources/assets/minecraft/atlases/chests.json +++ b/common/src/main/resources/assets/minecraft/atlases/chests.json @@ -2,8 +2,8 @@ "sources": [ { "type": "directory", - "source": "sorting_chests", - "prefix": "sorting_chests/" + "source": "entity/sorting_chest", + "prefix": "entity/sorting_chest/" } ] } \ No newline at end of file diff --git a/common/src/main/resources/assets/minecraft/textures/sorting_chests/diamond.png b/common/src/main/resources/assets/minecraft/textures/entity/sorting_chest/diamond.png similarity index 100% rename from common/src/main/resources/assets/minecraft/textures/sorting_chests/diamond.png rename to common/src/main/resources/assets/minecraft/textures/entity/sorting_chest/diamond.png diff --git a/common/src/main/resources/assets/minecraft/textures/sorting_chests/gold.png b/common/src/main/resources/assets/minecraft/textures/entity/sorting_chest/gold.png similarity index 100% rename from common/src/main/resources/assets/minecraft/textures/sorting_chests/gold.png rename to common/src/main/resources/assets/minecraft/textures/entity/sorting_chest/gold.png diff --git a/common/src/main/resources/assets/minecraft/textures/sorting_chests/iron.png b/common/src/main/resources/assets/minecraft/textures/entity/sorting_chest/iron.png similarity index 100% rename from common/src/main/resources/assets/minecraft/textures/sorting_chests/iron.png rename to common/src/main/resources/assets/minecraft/textures/entity/sorting_chest/iron.png diff --git a/common/src/main/resources/assets/minecraft/textures/sorting_chests/normal.png b/common/src/main/resources/assets/minecraft/textures/entity/sorting_chest/oak.png similarity index 100% rename from common/src/main/resources/assets/minecraft/textures/sorting_chests/normal.png rename to common/src/main/resources/assets/minecraft/textures/entity/sorting_chest/oak.png