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());
|
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)
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user