diff --git a/ChestPreview/ChestPreview/PreviewTargetProvider.cs b/ChestPreview/ChestPreview/PreviewTargetProvider.cs index 65e6ae0..2c918be 100644 --- a/ChestPreview/ChestPreview/PreviewTargetProvider.cs +++ b/ChestPreview/ChestPreview/PreviewTargetProvider.cs @@ -260,7 +260,7 @@ internal partial class PreviewTargetProvider(ICoreClientAPI api, Config config) return inventory.CanPlayerAccess(player, playerEntity.GetPos()); } - if (blockEntity is BlockEntityBloomery) + if (blockEntity is BlockEntityBloomery or BlockEntityForge) return true; return HasHeldBagInGroundStorage(blockEntity); @@ -271,12 +271,7 @@ internal partial class PreviewTargetProvider(ICoreClientAPI api, Config config) if (config.GroundStorageOnlyContainers && blockEntity is BlockEntityGroundStorage) return HasHeldBagInGroundStorage(blockEntity); - return block.GetInterface(api.World, blockPos) != null || HasHeldBagInGroundStorage(blockEntity) || HasBloomeryInventory(blockEntity); - } - - private static bool HasBloomeryInventory(BlockEntity? blockEntity) - { - return blockEntity is BlockEntityBloomery; + return block.GetInterface(api.World, blockPos) != null || HasHeldBagInGroundStorage(blockEntity) || (blockEntity is BlockEntityBloomery or BlockEntityForge); } private static bool HasHeldBagInGroundStorage(BlockEntity? blockEntity) diff --git a/ChestPreview/ChestPreview/Rendering/CardRenderer.cs b/ChestPreview/ChestPreview/Rendering/CardRenderer.cs index f2af050..a7dd47a 100644 --- a/ChestPreview/ChestPreview/Rendering/CardRenderer.cs +++ b/ChestPreview/ChestPreview/Rendering/CardRenderer.cs @@ -32,6 +32,7 @@ internal class CardRenderer(ICoreClientAPI api, Config config) : IDisposable private readonly ICoreClientAPI api = api; private readonly Config config = config; private readonly TreeAttribute tempTree = new(); + private readonly InventoryGeneric sharedPreviewInventory = new(64, "inventory-preview", null, null); private readonly Dictionary cardTextureByTarget = []; private readonly Dictionary atlasTextureById = []; private readonly Dictionary renderedIconByStack = []; @@ -136,9 +137,9 @@ internal class CardRenderer(ICoreClientAPI api, Config config) : IDisposable { inventory = null; - if (TryResolveBloomeryInventory(target.BlockEntity, out InventoryBase? bloomeryInventory)) + if (TryResolveSpecialInventory(target.BlockEntity, out InventoryBase? specialInventory)) { - inventory = bloomeryInventory; + inventory = specialInventory; return true; } @@ -152,19 +153,33 @@ internal class CardRenderer(ICoreClientAPI api, Config config) : IDisposable return false; } - private bool TryResolveBloomeryInventory(BlockEntity blockEntity, [NotNullWhen(true)] out InventoryBase? inventory) + private bool TryResolveSpecialInventory(BlockEntity blockEntity, [NotNullWhen(true)] out InventoryBase? inventory) { inventory = null; - if (blockEntity is not BlockEntityBloomery) + if (blockEntity is not BlockEntityBloomery and not BlockEntityForge) return false; tempTree.Clear(); blockEntity.ToTreeAttributes(tempTree); - // bloomery inventory has 3 slots: fuel, ore, output - InventoryGeneric bloomeryInventory = new(3, "bloomery-preview", null, null); - bloomeryInventory.FromTreeAttributes(tempTree); - inventory = bloomeryInventory; + ITreeAttribute sourceTree = tempTree; + if (blockEntity is BlockEntityForge) + { + ITreeAttribute? forgeInventoryTree = tempTree.GetTreeAttribute("inventory"); + if (forgeInventoryTree != null) + sourceTree = forgeInventoryTree; + } + + sharedPreviewInventory.FromTreeAttributes(sourceTree); + + if (blockEntity is BlockEntityForge && sharedPreviewInventory[0].Itemstack == null) + { + ItemStack? legacyContents = tempTree.GetItemstack("contents"); + if (legacyContents != null) + sharedPreviewInventory[0].Itemstack = legacyContents; + } + + inventory = sharedPreviewInventory; return true; }