From e48580f10a31e4b13780b6766a9b4afae562ab69 Mon Sep 17 00:00:00 2001 From: OrekiWoof Date: Thu, 19 Mar 2026 02:06:07 +0100 Subject: [PATCH] blockinfo --- .../BlockEntityButterflyPinBoard.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/ButterflyPins/BlockEntities/BlockEntityButterflyPinBoard.cs b/ButterflyPins/BlockEntities/BlockEntityButterflyPinBoard.cs index 3d6636f..4f7ce7a 100644 --- a/ButterflyPins/BlockEntities/BlockEntityButterflyPinBoard.cs +++ b/ButterflyPins/BlockEntities/BlockEntityButterflyPinBoard.cs @@ -1,4 +1,5 @@ using System; +using System.Text; using Vintagestory.API.Client; using Vintagestory.API.Common; using Vintagestory.API.Datastructures; @@ -110,6 +111,46 @@ public class BlockEntityButterflyPinBoard : BlockEntityDisplay } } + public override void GetBlockInfo(IPlayer forPlayer, StringBuilder dsc) + { + int highlightedSlot = -1; + BlockSelection? selection = forPlayer?.CurrentBlockSelection; + if (selection?.Position != null && selection.Position.Equals(Pos)) + highlightedSlot = GetSlotIndex(selection.HitPosition); + + AppendContentsBlockInfo(dsc, highlightedSlot); + } + + public bool AppendContentsBlockInfo(StringBuilder builder, int highlightedSlot) + { + int initialLength = builder.Length; + + for (int slotIndex = 0; slotIndex < ActiveSlotCount; slotIndex++) + { + ItemStack? stack = inventory[slotIndex].Itemstack; + if (stack == null) + continue; + + if (builder.Length > initialLength) + builder.AppendLine(); + else if (initialLength > 0) + builder.AppendLine(); + + string itemName = stack.GetName(); + if (slotIndex == highlightedSlot) + { + builder.Append(""); + builder.Append(itemName); + builder.Append(""); + continue; + } + + builder.Append(itemName); + } + + return builder.Length > initialLength; + } + public int GetSlotIndex(Vec3d hitPosition) { Vec3d local = ToBaseOrientation(hitPosition);