support for Forge

This commit is contained in:
2026-03-15 23:53:23 +01:00
parent 27cfbcaa10
commit 5389901c82
2 changed files with 25 additions and 15 deletions

View File

@@ -260,7 +260,7 @@ internal partial class PreviewTargetProvider(ICoreClientAPI api, Config config)
return inventory.CanPlayerAccess(player, playerEntity.GetPos()); return inventory.CanPlayerAccess(player, playerEntity.GetPos());
} }
if (blockEntity is BlockEntityBloomery) if (blockEntity is BlockEntityBloomery or BlockEntityForge)
return true; return true;
return HasHeldBagInGroundStorage(blockEntity); return HasHeldBagInGroundStorage(blockEntity);
@@ -271,12 +271,7 @@ internal partial class PreviewTargetProvider(ICoreClientAPI api, Config config)
if (config.GroundStorageOnlyContainers && blockEntity is BlockEntityGroundStorage) if (config.GroundStorageOnlyContainers && blockEntity is BlockEntityGroundStorage)
return HasHeldBagInGroundStorage(blockEntity); return HasHeldBagInGroundStorage(blockEntity);
return block.GetInterface<IBlockEntityContainer>(api.World, blockPos) != null || HasHeldBagInGroundStorage(blockEntity) || HasBloomeryInventory(blockEntity); return block.GetInterface<IBlockEntityContainer>(api.World, blockPos) != null || HasHeldBagInGroundStorage(blockEntity) || (blockEntity is BlockEntityBloomery or BlockEntityForge);
}
private static bool HasBloomeryInventory(BlockEntity? blockEntity)
{
return blockEntity is BlockEntityBloomery;
} }
private static bool HasHeldBagInGroundStorage(BlockEntity? blockEntity) private static bool HasHeldBagInGroundStorage(BlockEntity? blockEntity)

View File

@@ -32,6 +32,7 @@ internal class CardRenderer(ICoreClientAPI api, Config config) : IDisposable
private readonly ICoreClientAPI api = api; private readonly ICoreClientAPI api = api;
private readonly Config config = config; private readonly Config config = config;
private readonly TreeAttribute tempTree = new(); private readonly TreeAttribute tempTree = new();
private readonly InventoryGeneric sharedPreviewInventory = new(64, "inventory-preview", null, null);
private readonly Dictionary<string, CachedCardTexture> cardTextureByTarget = []; private readonly Dictionary<string, CachedCardTexture> cardTextureByTarget = [];
private readonly Dictionary<int, LoadedTexture> atlasTextureById = []; private readonly Dictionary<int, LoadedTexture> atlasTextureById = [];
private readonly Dictionary<string, RenderedIconEntry> renderedIconByStack = []; private readonly Dictionary<string, RenderedIconEntry> renderedIconByStack = [];
@@ -136,9 +137,9 @@ internal class CardRenderer(ICoreClientAPI api, Config config) : IDisposable
{ {
inventory = null; inventory = null;
if (TryResolveBloomeryInventory(target.BlockEntity, out InventoryBase? bloomeryInventory)) if (TryResolveSpecialInventory(target.BlockEntity, out InventoryBase? specialInventory))
{ {
inventory = bloomeryInventory; inventory = specialInventory;
return true; return true;
} }
@@ -152,19 +153,33 @@ internal class CardRenderer(ICoreClientAPI api, Config config) : IDisposable
return false; return false;
} }
private bool TryResolveBloomeryInventory(BlockEntity blockEntity, [NotNullWhen(true)] out InventoryBase? inventory) private bool TryResolveSpecialInventory(BlockEntity blockEntity, [NotNullWhen(true)] out InventoryBase? inventory)
{ {
inventory = null; inventory = null;
if (blockEntity is not BlockEntityBloomery) if (blockEntity is not BlockEntityBloomery and not BlockEntityForge)
return false; return false;
tempTree.Clear(); tempTree.Clear();
blockEntity.ToTreeAttributes(tempTree); blockEntity.ToTreeAttributes(tempTree);
// bloomery inventory has 3 slots: fuel, ore, output ITreeAttribute sourceTree = tempTree;
InventoryGeneric bloomeryInventory = new(3, "bloomery-preview", null, null); if (blockEntity is BlockEntityForge)
bloomeryInventory.FromTreeAttributes(tempTree); {
inventory = bloomeryInventory; 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; return true;
} }