forked from OrekiWoof/ChestPreview
support for groundstorable containers and bloomery
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"total": 66247,
|
"total": 73071,
|
||||||
"sessions": [
|
"sessions": [
|
||||||
{
|
{
|
||||||
"begin": "2026-03-11T23:50:47+01:00",
|
"begin": "2026-03-11T23:50:47+01:00",
|
||||||
@@ -65,6 +65,11 @@
|
|||||||
"begin": "2026-03-15T20:33:08+01:00",
|
"begin": "2026-03-15T20:33:08+01:00",
|
||||||
"end": "2026-03-15T20:53:09+01:00",
|
"end": "2026-03-15T20:53:09+01:00",
|
||||||
"duration": 1201
|
"duration": 1201
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"begin": "2026-03-15T21:00:39+01:00",
|
||||||
|
"end": "2026-03-15T23:04:35+01:00",
|
||||||
|
"duration": 7435
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,20 +1,22 @@
|
|||||||
namespace ChestPreview.Configs;
|
namespace ChestPreview.Configs;
|
||||||
|
|
||||||
public sealed class Config
|
public sealed class Config
|
||||||
{
|
{
|
||||||
public string Mode { get; set; } = PreviewModes.UNDER_CURSOR;
|
public string Mode { get; set; } = PreviewModes.UNDER_CURSOR;
|
||||||
|
|
||||||
public bool HoldKey { get; set; } = true;
|
public bool HoldKey { get; set; } = true;
|
||||||
|
|
||||||
public int BillboardColumnsPerBlock { get; set; } = 4;
|
public int BillboardColumnsPerBlock { get; set; } = 4;
|
||||||
|
|
||||||
public int ColumnsUnderCursor { get; set; } = 10;
|
public int ColumnsUnderCursor { get; set; } = 10;
|
||||||
|
|
||||||
public int PreviewNearbyRadius { get; set; } = 8;
|
public int PreviewNearbyRadius { get; set; } = 8;
|
||||||
|
|
||||||
public bool WhitelistedContainersOnly { get; set; } = true;
|
public bool WhitelistedContainersOnly { get; set; } = true;
|
||||||
|
|
||||||
public string WhitelistedContainers { get; set; } = "barrel, crate, chest-*, trunk-*, storagevessel-*, stationarybasket-*, labeledchest-*";
|
public string WhitelistedContainers { get; set; } = "barrel, crate, chest-*, trunk-*, storagevessel-*, stationarybasket-*, labeledchest-*, groundstorage";
|
||||||
|
|
||||||
public string BlacklistedContainers { get; set; } = "";
|
public string BlacklistedContainers { get; set; } = "";
|
||||||
|
|
||||||
|
public bool GroundStorageOnlyContainers { get; set; } = true;
|
||||||
}
|
}
|
||||||
@@ -1,284 +1,336 @@
|
|||||||
using ChestPreview.Configs;
|
using ChestPreview.Configs;
|
||||||
using ChestPreview.Core;
|
using ChestPreview.Core;
|
||||||
using ChestPreview.Models;
|
using ChestPreview.Models;
|
||||||
using ChestPreview.Utils;
|
using ChestPreview.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Vintagestory.API.Client;
|
using Vintagestory.API.Client;
|
||||||
using Vintagestory.API.Common;
|
using Vintagestory.API.Common;
|
||||||
using Vintagestory.API.MathTools;
|
using Vintagestory.API.MathTools;
|
||||||
using Vintagestory.API.Util;
|
using Vintagestory.API.Util;
|
||||||
|
using Vintagestory.GameContent;
|
||||||
namespace ChestPreview;
|
|
||||||
|
namespace ChestPreview;
|
||||||
internal partial class PreviewTargetProvider(ICoreClientAPI api, Config config) : IDisposable
|
|
||||||
{
|
internal partial class PreviewTargetProvider(ICoreClientAPI api, Config config) : IDisposable
|
||||||
private const float nearby_scan_interval_seconds = 0.1f;
|
{
|
||||||
private static readonly Regex list_separator_regex = ListSeparatorRegex();
|
private const float nearby_scan_interval_seconds = 0.1f;
|
||||||
|
private static readonly Regex list_separator_regex = ListSeparatorRegex();
|
||||||
private readonly ICoreClientAPI api = api;
|
|
||||||
private readonly Config config = config;
|
private readonly ICoreClientAPI api = api;
|
||||||
private readonly List<BlockEntity> nearbyContainerEntities = [];
|
private readonly Config config = config;
|
||||||
private float nearbyScanAccumulator;
|
private readonly List<BlockEntity> nearbyContainerEntities = [];
|
||||||
|
private float nearbyScanAccumulator;
|
||||||
public void CollectTargets(float deltaTime, List<PreviewTarget> targets)
|
|
||||||
{
|
public void CollectTargets(float deltaTime, List<PreviewTarget> targets)
|
||||||
string mode = GetActiveMode();
|
{
|
||||||
if (mode == PreviewModes.NONE)
|
string mode = GetActiveMode();
|
||||||
return;
|
if (mode == PreviewModes.NONE)
|
||||||
|
return;
|
||||||
if (mode == PreviewModes.ON_NEARBY_CONTAINERS)
|
|
||||||
{
|
if (mode == PreviewModes.ON_NEARBY_CONTAINERS)
|
||||||
CollectNearbyTargets(deltaTime, targets);
|
{
|
||||||
return;
|
CollectNearbyTargets(deltaTime, targets);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
if (!TryGetHoveredContainer(out Block hoveredBlock, out BlockEntity hoveredBlockEntity))
|
|
||||||
return;
|
if (!TryGetHoveredContainer(out Block hoveredBlock, out BlockEntity hoveredBlockEntity))
|
||||||
|
return;
|
||||||
if (!CanAccessContainer(hoveredBlockEntity))
|
|
||||||
return;
|
if (!CanAccessContainer(hoveredBlock, hoveredBlockEntity))
|
||||||
|
return;
|
||||||
if (!IsContainerAllowed(hoveredBlock))
|
|
||||||
return;
|
if (!IsContainerAllowed(hoveredBlock))
|
||||||
|
return;
|
||||||
targets.Add(new PreviewTarget(hoveredBlock, hoveredBlockEntity, mode, GetContainerAnchor(hoveredBlock, hoveredBlockEntity.Pos)));
|
|
||||||
}
|
targets.Add(new PreviewTarget(hoveredBlock, hoveredBlockEntity, mode, GetContainerAnchor(hoveredBlock, hoveredBlockEntity.Pos)));
|
||||||
|
}
|
||||||
public void Dispose()
|
|
||||||
{
|
public void Dispose()
|
||||||
nearbyContainerEntities.Clear();
|
{
|
||||||
}
|
nearbyContainerEntities.Clear();
|
||||||
|
}
|
||||||
private void CollectNearbyTargets(float deltaTime, List<PreviewTarget> targets)
|
|
||||||
{
|
private void CollectNearbyTargets(float deltaTime, List<PreviewTarget> targets)
|
||||||
nearbyScanAccumulator += deltaTime;
|
{
|
||||||
bool shouldRefresh = nearbyContainerEntities.Count == 0 || nearbyScanAccumulator >= nearby_scan_interval_seconds;
|
nearbyScanAccumulator += deltaTime;
|
||||||
|
bool shouldRefresh = nearbyContainerEntities.Count == 0 || nearbyScanAccumulator >= nearby_scan_interval_seconds;
|
||||||
if (shouldRefresh)
|
|
||||||
{
|
if (shouldRefresh)
|
||||||
RefreshNearbyContainers();
|
{
|
||||||
nearbyScanAccumulator = 0f;
|
RefreshNearbyContainers();
|
||||||
}
|
nearbyScanAccumulator = 0f;
|
||||||
|
}
|
||||||
foreach (BlockEntity blockEntity in nearbyContainerEntities)
|
|
||||||
{
|
foreach (BlockEntity blockEntity in nearbyContainerEntities)
|
||||||
Block block = api.World.BlockAccessor.GetBlock(blockEntity.Pos);
|
{
|
||||||
if (block.Id == 0)
|
Block block = api.World.BlockAccessor.GetBlock(blockEntity.Pos);
|
||||||
continue;
|
if (block.Id == 0)
|
||||||
|
continue;
|
||||||
if (!CanAccessContainer(blockEntity))
|
|
||||||
continue;
|
if (!CanAccessContainer(block, blockEntity))
|
||||||
|
continue;
|
||||||
if (!IsContainerAllowed(block))
|
|
||||||
continue;
|
if (!IsContainerAllowed(block))
|
||||||
|
continue;
|
||||||
targets.Add(new PreviewTarget(block, blockEntity, PreviewModes.ON_NEARBY_CONTAINERS, GetContainerAnchor(block, blockEntity.Pos)));
|
|
||||||
}
|
targets.Add(new PreviewTarget(block, blockEntity, PreviewModes.ON_NEARBY_CONTAINERS, GetContainerAnchor(block, blockEntity.Pos)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private string GetActiveMode()
|
|
||||||
{
|
private string GetActiveMode()
|
||||||
if (IsHotkeyHeld(ChestPreviewModSystem.PREVIEW_CONTAINERS_NEARBY_HOTKEY_CODE))
|
{
|
||||||
return PreviewModes.ON_NEARBY_CONTAINERS;
|
if (IsHotkeyHeld(ChestPreviewModSystem.PREVIEW_CONTAINERS_NEARBY_HOTKEY_CODE))
|
||||||
|
return PreviewModes.ON_NEARBY_CONTAINERS;
|
||||||
if (config.HoldKey && !IsHotkeyHeld(ChestPreviewModSystem.PREVIEW_CONTAINERS_HOTKEY_CODE))
|
|
||||||
return PreviewModes.NONE;
|
if (config.HoldKey && !IsHotkeyHeld(ChestPreviewModSystem.PREVIEW_CONTAINERS_HOTKEY_CODE))
|
||||||
|
return PreviewModes.NONE;
|
||||||
return PreviewModes.Normalize(config.Mode);
|
|
||||||
}
|
return PreviewModes.Normalize(config.Mode);
|
||||||
|
}
|
||||||
private bool IsHotkeyHeld(string hotkeyCode)
|
|
||||||
{
|
private bool IsHotkeyHeld(string hotkeyCode)
|
||||||
HotKey? hotKey = api.Input.GetHotKeyByCode(hotkeyCode);
|
{
|
||||||
if (hotKey?.CurrentMapping == null)
|
HotKey? hotKey = api.Input.GetHotKeyByCode(hotkeyCode);
|
||||||
return false;
|
if (hotKey?.CurrentMapping == null)
|
||||||
|
return false;
|
||||||
KeyCombination mapping = hotKey.CurrentMapping;
|
|
||||||
if (!IsKeyHeld(mapping.KeyCode))
|
KeyCombination mapping = hotKey.CurrentMapping;
|
||||||
return false;
|
if (!IsKeyHeld(mapping.KeyCode))
|
||||||
|
return false;
|
||||||
if (mapping.SecondKeyCode.HasValue && !IsKeyHeld(mapping.SecondKeyCode.Value))
|
|
||||||
return false;
|
if (mapping.SecondKeyCode.HasValue && !IsKeyHeld(mapping.SecondKeyCode.Value))
|
||||||
|
return false;
|
||||||
EntityControls? controls = api.World.Player?.Entity?.Controls;
|
|
||||||
if (mapping.Ctrl && controls?.CtrlKey != true)
|
EntityControls? controls = api.World.Player?.Entity?.Controls;
|
||||||
return false;
|
if (mapping.Ctrl && controls?.CtrlKey != true)
|
||||||
|
return false;
|
||||||
if (mapping.Shift && controls?.ShiftKey != true)
|
|
||||||
return false;
|
if (mapping.Shift && controls?.ShiftKey != true)
|
||||||
|
return false;
|
||||||
return !mapping.Alt || IsAltHeld();
|
|
||||||
}
|
return !mapping.Alt || IsAltHeld();
|
||||||
|
}
|
||||||
private bool IsKeyHeld(int keyCode)
|
|
||||||
{
|
private bool IsKeyHeld(int keyCode)
|
||||||
bool[] keyStates = api.Input.KeyboardKeyStateRaw;
|
{
|
||||||
return keyCode >= 0 && keyCode < keyStates.Length && keyStates[keyCode];
|
bool[] keyStates = api.Input.KeyboardKeyStateRaw;
|
||||||
}
|
return keyCode >= 0 && keyCode < keyStates.Length && keyStates[keyCode];
|
||||||
|
}
|
||||||
private bool IsAltHeld()
|
|
||||||
{
|
private bool IsAltHeld()
|
||||||
return IsKeyHeld((int)GlKeys.AltLeft) || IsKeyHeld((int)GlKeys.AltRight);
|
{
|
||||||
}
|
return IsKeyHeld((int)GlKeys.AltLeft) || IsKeyHeld((int)GlKeys.AltRight);
|
||||||
|
}
|
||||||
private bool TryGetHoveredContainer(out Block block, out BlockEntity blockEntity)
|
|
||||||
{
|
private bool TryGetHoveredContainer(out Block block, out BlockEntity blockEntity)
|
||||||
block = null!;
|
{
|
||||||
blockEntity = null!;
|
block = null!;
|
||||||
|
blockEntity = null!;
|
||||||
BlockSelection? currentBlockSelection = api.World.Player?.CurrentBlockSelection;
|
|
||||||
if (currentBlockSelection == null)
|
BlockSelection? currentBlockSelection = api.World.Player?.CurrentBlockSelection;
|
||||||
return false;
|
if (currentBlockSelection == null)
|
||||||
|
return false;
|
||||||
BlockEntity? currentBlockEntity = api.World.BlockAccessor.GetBlockEntity(currentBlockSelection.Position);
|
|
||||||
if (currentBlockEntity is IBlockEntityContainer)
|
BlockPos hoveredPos = currentBlockSelection.Position;
|
||||||
{
|
BlockEntity? currentBlockEntity = api.World.BlockAccessor.GetBlockEntity(hoveredPos);
|
||||||
block = currentBlockSelection.Block;
|
if (HasPreviewableStorage(currentBlockSelection.Block, hoveredPos, currentBlockEntity))
|
||||||
blockEntity = currentBlockEntity;
|
{
|
||||||
return true;
|
block = currentBlockSelection.Block;
|
||||||
}
|
if (currentBlockEntity == null)
|
||||||
|
return false;
|
||||||
if (!TryResolveMultiblockControllerContainer(currentBlockSelection, out Block controllerBlock, out BlockEntity controllerBlockEntity))
|
|
||||||
return false;
|
blockEntity = currentBlockEntity;
|
||||||
|
return true;
|
||||||
block = controllerBlock;
|
}
|
||||||
blockEntity = controllerBlockEntity;
|
|
||||||
return true;
|
if (!TryResolveMultiblockControllerContainer(currentBlockSelection, out Block controllerBlock, out BlockEntity controllerBlockEntity))
|
||||||
}
|
return false;
|
||||||
|
|
||||||
private bool TryResolveMultiblockControllerContainer(BlockSelection blockSelection, out Block controllerBlock, out BlockEntity controllerBlockEntity)
|
block = controllerBlock;
|
||||||
{
|
blockEntity = controllerBlockEntity;
|
||||||
controllerBlock = null!;
|
return true;
|
||||||
controllerBlockEntity = null!;
|
}
|
||||||
|
|
||||||
if (blockSelection.Block is not IMultiblockOffset multiblockOffset)
|
private bool TryResolveMultiblockControllerContainer(BlockSelection blockSelection, out Block controllerBlock, out BlockEntity controllerBlockEntity)
|
||||||
return false;
|
{
|
||||||
|
controllerBlock = null!;
|
||||||
BlockPos controllerPos = multiblockOffset.GetControlBlockPos(blockSelection.Position);
|
controllerBlockEntity = null!;
|
||||||
BlockEntity? blockEntity = api.World.BlockAccessor.GetBlockEntity(controllerPos);
|
|
||||||
if (blockEntity is not IBlockEntityContainer)
|
if (blockSelection.Block is not IMultiblockOffset multiblockOffset)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
controllerBlock = api.World.BlockAccessor.GetBlock(controllerPos);
|
BlockPos controllerPos = multiblockOffset.GetControlBlockPos(blockSelection.Position);
|
||||||
if (controllerBlock.Id == 0)
|
controllerBlock = api.World.BlockAccessor.GetBlock(controllerPos);
|
||||||
return false;
|
if (controllerBlock.Id == 0)
|
||||||
|
return false;
|
||||||
controllerBlockEntity = blockEntity;
|
|
||||||
return true;
|
BlockEntity? blockEntity = api.World.BlockAccessor.GetBlockEntity(controllerPos);
|
||||||
}
|
if (!HasPreviewableStorage(controllerBlock, controllerPos, blockEntity))
|
||||||
|
return false;
|
||||||
private void RefreshNearbyContainers()
|
|
||||||
{
|
if (blockEntity == null)
|
||||||
nearbyContainerEntities.Clear();
|
return false;
|
||||||
|
|
||||||
EntityPlayer? playerEntity = api.World.Player?.Entity;
|
controllerBlockEntity = blockEntity;
|
||||||
if (playerEntity?.CameraPos == null)
|
return true;
|
||||||
return;
|
}
|
||||||
|
|
||||||
float nearbyRadius = config.PreviewNearbyRadius;
|
private void RefreshNearbyContainers()
|
||||||
float nearbyRadiusSquared = nearbyRadius * nearbyRadius;
|
{
|
||||||
|
nearbyContainerEntities.Clear();
|
||||||
Vec3d nearbyRadiusOffset = new(nearbyRadius, nearbyRadius, nearbyRadius);
|
|
||||||
BlockPos minPos = (playerEntity.CameraPos - nearbyRadiusOffset).AsBlockPos;
|
EntityPlayer? playerEntity = api.World.Player?.Entity;
|
||||||
BlockPos maxPos = (playerEntity.CameraPos + nearbyRadiusOffset + new Vec3d(1d, 1d, 1d)).AsBlockPos;
|
if (playerEntity?.CameraPos == null)
|
||||||
|
return;
|
||||||
api.World.BlockAccessor.WalkBlocks(minPos, maxPos, (block, x, y, z) =>
|
|
||||||
{
|
float nearbyRadius = config.PreviewNearbyRadius;
|
||||||
double horizontalDx = x + 0.5d - playerEntity.CameraPos.X;
|
float nearbyRadiusSquared = nearbyRadius * nearbyRadius;
|
||||||
double horizontalDz = z + 0.5d - playerEntity.CameraPos.Z;
|
|
||||||
if (horizontalDx * horizontalDx + horizontalDz * horizontalDz > nearbyRadiusSquared)
|
Vec3d nearbyRadiusOffset = new(nearbyRadius, nearbyRadius, nearbyRadius);
|
||||||
return;
|
BlockPos minPos = (playerEntity.CameraPos - nearbyRadiusOffset).AsBlockPos;
|
||||||
|
BlockPos maxPos = (playerEntity.CameraPos + nearbyRadiusOffset + new Vec3d(1d, 1d, 1d)).AsBlockPos;
|
||||||
if (Math.Abs(y + 0.5d - playerEntity.CameraPos.Y) > nearbyRadius)
|
|
||||||
return;
|
api.World.BlockAccessor.WalkBlocks(minPos, maxPos, (block, x, y, z) =>
|
||||||
|
{
|
||||||
BlockEntity? blockEntity = api.World.BlockAccessor.GetBlockEntity(new BlockPos(x, y, z));
|
double horizontalDx = x + 0.5d - playerEntity.CameraPos.X;
|
||||||
if (blockEntity is not IBlockEntityContainer)
|
double horizontalDz = z + 0.5d - playerEntity.CameraPos.Z;
|
||||||
return;
|
if (horizontalDx * horizontalDx + horizontalDz * horizontalDz > nearbyRadiusSquared)
|
||||||
|
return;
|
||||||
if (block.Id == 0)
|
|
||||||
return;
|
if (Math.Abs(y + 0.5d - playerEntity.CameraPos.Y) > nearbyRadius)
|
||||||
|
return;
|
||||||
nearbyContainerEntities.Add(blockEntity);
|
|
||||||
});
|
if (block.Id == 0)
|
||||||
}
|
return;
|
||||||
|
|
||||||
private Vec3d GetContainerAnchor(Block block, BlockPos blockPos)
|
BlockPos blockPos = new(x, y, z);
|
||||||
{
|
BlockEntity? blockEntity = api.World.BlockAccessor.GetBlockEntity(blockPos);
|
||||||
GetContainerBounds(block, blockPos, out Vector3 min, out Vector3 max);
|
if (!HasPreviewableStorage(block, blockPos, blockEntity))
|
||||||
|
return;
|
||||||
Vector3 anchor = blockPos.ToVector3() + new Vector3((min.X + max.X) * 0.5f, max.Y + 0.1f, (min.Z + max.Z) * 0.5f);
|
|
||||||
return anchor.ToVec3d();
|
if (blockEntity == null)
|
||||||
}
|
return;
|
||||||
|
|
||||||
private void GetContainerBounds(Block block, BlockPos blockPos, out Vector3 min, out Vector3 max)
|
nearbyContainerEntities.Add(blockEntity);
|
||||||
{
|
});
|
||||||
Cuboidf[]? selectionBoxes = block.GetSelectionBoxes(api.World.BlockAccessor, blockPos);
|
}
|
||||||
|
|
||||||
min = new Vector3(0f, 0f, 0f);
|
private Vec3d GetContainerAnchor(Block block, BlockPos blockPos)
|
||||||
max = new Vector3(1f, 1f, 1f);
|
{
|
||||||
|
GetContainerBounds(block, blockPos, out Vector3 min, out Vector3 max);
|
||||||
if (selectionBoxes is not { Length: > 0 })
|
|
||||||
return;
|
Vector3 anchor = blockPos.ToVector3() + new Vector3((min.X + max.X) * 0.5f, max.Y + 0.1f, (min.Z + max.Z) * 0.5f);
|
||||||
|
return anchor.ToVec3d();
|
||||||
foreach (Cuboidf selectionBox in selectionBoxes)
|
}
|
||||||
{
|
|
||||||
min = Vector3.Min(min, selectionBox.Start.ToVector3());
|
private void GetContainerBounds(Block block, BlockPos blockPos, out Vector3 min, out Vector3 max)
|
||||||
max = Vector3.Max(max, selectionBox.End.ToVector3());
|
{
|
||||||
}
|
Cuboidf[]? selectionBoxes = block.GetSelectionBoxes(api.World.BlockAccessor, blockPos);
|
||||||
}
|
|
||||||
|
min = new Vector3(0f, 0f, 0f);
|
||||||
private bool CanAccessContainer(BlockEntity blockEntity)
|
max = new Vector3(1f, 1f, 1f);
|
||||||
{
|
|
||||||
if (blockEntity is not IBlockEntityContainer container || container.Inventory is not InventoryBase inventory)
|
if (selectionBoxes is not { Length: > 0 })
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
IPlayer? player = api.World.Player;
|
foreach (Cuboidf selectionBox in selectionBoxes)
|
||||||
EntityPlayer? playerEntity = player?.Entity;
|
{
|
||||||
if (player == null || playerEntity == null)
|
min = Vector3.Min(min, selectionBox.Start.ToVector3());
|
||||||
return false;
|
max = Vector3.Max(max, selectionBox.End.ToVector3());
|
||||||
|
}
|
||||||
return inventory.CanPlayerAccess(player, playerEntity.GetPos());
|
}
|
||||||
}
|
|
||||||
|
private bool CanAccessContainer(Block block, BlockEntity blockEntity)
|
||||||
private bool IsContainerAllowed(Block block)
|
{
|
||||||
{
|
if (config.GroundStorageOnlyContainers && blockEntity is BlockEntityGroundStorage && !HasHeldBagInGroundStorage(blockEntity))
|
||||||
string? code = block.Code?.Path;
|
return false;
|
||||||
if (string.IsNullOrWhiteSpace(code))
|
|
||||||
return true;
|
BlockPos blockPos = blockEntity.Pos;
|
||||||
|
if (block.GetInterface<IBlockEntityContainer>(api.World, blockPos) is { } container && container.Inventory is InventoryBase inventory)
|
||||||
HashSet<string> blacklist = ParseContainerCodes(config.BlacklistedContainers);
|
{
|
||||||
if (blacklist.Any(x => WildcardUtil.Match(x, code)))
|
IPlayer? player = api.World.Player;
|
||||||
return false;
|
EntityPlayer? playerEntity = player?.Entity;
|
||||||
|
if (player == null || playerEntity == null)
|
||||||
if (!config.WhitelistedContainersOnly)
|
return false;
|
||||||
return true;
|
|
||||||
|
return inventory.CanPlayerAccess(player, playerEntity.GetPos());
|
||||||
HashSet<string> whitelist = ParseContainerCodes(config.WhitelistedContainers);
|
}
|
||||||
return whitelist.Any(x => WildcardUtil.Match(x, code));
|
|
||||||
}
|
if (blockEntity is BlockEntityBloomery)
|
||||||
|
return true;
|
||||||
private static HashSet<string> ParseContainerCodes(string rawList)
|
|
||||||
{
|
return HasHeldBagInGroundStorage(blockEntity);
|
||||||
if (string.IsNullOrWhiteSpace(rawList))
|
}
|
||||||
return [];
|
|
||||||
|
private bool HasPreviewableStorage(Block block, BlockPos blockPos, BlockEntity? blockEntity)
|
||||||
string[] entries = list_separator_regex.Split(rawList.Trim());
|
{
|
||||||
HashSet<string> result = new(StringComparer.OrdinalIgnoreCase);
|
if (config.GroundStorageOnlyContainers && blockEntity is BlockEntityGroundStorage)
|
||||||
|
return HasHeldBagInGroundStorage(blockEntity);
|
||||||
foreach (string entry in entries)
|
|
||||||
{
|
return block.GetInterface<IBlockEntityContainer>(api.World, blockPos) != null || HasHeldBagInGroundStorage(blockEntity) || HasBloomeryInventory(blockEntity);
|
||||||
if (!string.IsNullOrWhiteSpace(entry))
|
}
|
||||||
result.Add(entry);
|
|
||||||
}
|
private static bool HasBloomeryInventory(BlockEntity? blockEntity)
|
||||||
|
{
|
||||||
return result;
|
return blockEntity is BlockEntityBloomery;
|
||||||
}
|
}
|
||||||
|
|
||||||
[GeneratedRegex("[,;\\s]+", RegexOptions.Compiled)]
|
private static bool HasHeldBagInGroundStorage(BlockEntity? blockEntity)
|
||||||
private static partial Regex ListSeparatorRegex();
|
{
|
||||||
|
if (blockEntity is not BlockEntityGroundStorage groundStorage)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
foreach (ItemSlot? slot in groundStorage.Inventory)
|
||||||
|
{
|
||||||
|
if (slot?.Itemstack?.Collectible is not { } collectible)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
IHeldBag? heldBag = collectible.GetCollectibleInterface<IHeldBag>();
|
||||||
|
if (heldBag != null)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsContainerAllowed(Block block)
|
||||||
|
{
|
||||||
|
string? code = block.Code?.Path;
|
||||||
|
if (string.IsNullOrWhiteSpace(code))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
HashSet<string> blacklist = ParseContainerCodes(config.BlacklistedContainers);
|
||||||
|
if (blacklist.Any(x => WildcardUtil.Match(x, code)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!config.WhitelistedContainersOnly)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
HashSet<string> whitelist = ParseContainerCodes(config.WhitelistedContainers);
|
||||||
|
return whitelist.Any(x => WildcardUtil.Match(x, code));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HashSet<string> ParseContainerCodes(string rawList)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(rawList))
|
||||||
|
return [];
|
||||||
|
|
||||||
|
string[] entries = list_separator_regex.Split(rawList.Trim());
|
||||||
|
HashSet<string> result = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
foreach (string entry in entries)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(entry))
|
||||||
|
result.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex("[,;\\s]+", RegexOptions.Compiled)]
|
||||||
|
private static partial Regex ListSeparatorRegex();
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -72,7 +72,7 @@
|
|||||||
"code": "WhitelistedContainers",
|
"code": "WhitelistedContainers",
|
||||||
"comment": "config-desc-WhitelistedContainers",
|
"comment": "config-desc-WhitelistedContainers",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "barrel, crate, chest-*, trunk-*, storagevessel-*, stationarybasket-*, labeledchest-*",
|
"default": "barrel, crate, chest-*, trunk-*, storagevessel-*, stationarybasket-*, labeledchest-*, labeledtrunk-*, groundstorage, beehive-*",
|
||||||
"clientSide": true
|
"clientSide": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -81,6 +81,13 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "",
|
"default": "",
|
||||||
"clientSide": true
|
"clientSide": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code": "GroundStorageOnlyContainers",
|
||||||
|
"comment": "config-desc-GroundStorageOnlyContainers",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true,
|
||||||
|
"clientSide": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
"config-desc-ColumnsUnderCursor": "Columns in the UnderCursor mode.",
|
"config-desc-ColumnsUnderCursor": "Columns in the UnderCursor mode.",
|
||||||
"config-desc-PreviewNearbyRadius": "Radius for \"Preview containers nearby\".",
|
"config-desc-PreviewNearbyRadius": "Radius for \"Preview containers nearby\".",
|
||||||
"config-desc-WhitelistedContainersOnly": "If true, only container codes in WhitelistedContainers are handled.",
|
"config-desc-WhitelistedContainersOnly": "If true, only container codes in WhitelistedContainers are handled.",
|
||||||
|
"config-desc-GroundStorageOnlyContainers": "If true, groundstorage previews only appear when the stored item has its own inventory (for example bags/backpacks).",
|
||||||
"config-desc-WhitelistedContainers": "Allowed container codes, separated by comma, semicolon, or spaces. No effectif WhitelistedContainersOnly==false.",
|
"config-desc-WhitelistedContainers": "Allowed container codes, separated by comma, semicolon, or spaces. No effectif WhitelistedContainersOnly==false.",
|
||||||
"config-desc-BlacklistedContainers": "Blocked container codes, separated by comma, semicolon, or spaces."
|
"config-desc-BlacklistedContainers": "Blocked container codes, separated by comma, semicolon, or spaces."
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
"OrekiWoof"
|
"OrekiWoof"
|
||||||
],
|
],
|
||||||
"description": "see containers' contents without having to open them",
|
"description": "see containers' contents without having to open them",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"game": "1.21.0"
|
"game": "1.21.0"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user