forked from OrekiWoof/ChestPreview
support for Forge
This commit is contained in:
@@ -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<IBlockEntityContainer>(api.World, blockPos) != null || HasHeldBagInGroundStorage(blockEntity) || HasBloomeryInventory(blockEntity);
|
||||
}
|
||||
|
||||
private static bool HasBloomeryInventory(BlockEntity? blockEntity)
|
||||
{
|
||||
return blockEntity is BlockEntityBloomery;
|
||||
return block.GetInterface<IBlockEntityContainer>(api.World, blockPos) != null || HasHeldBagInGroundStorage(blockEntity) || (blockEntity is BlockEntityBloomery or BlockEntityForge);
|
||||
}
|
||||
|
||||
private static bool HasHeldBagInGroundStorage(BlockEntity? blockEntity)
|
||||
|
||||
@@ -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<string, CachedCardTexture> cardTextureByTarget = [];
|
||||
private readonly Dictionary<int, LoadedTexture> atlasTextureById = [];
|
||||
private readonly Dictionary<string, RenderedIconEntry> 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user