Skip to content

Commit

Permalink
tweak shulkerBoxItemContentHint improves use experience for nbt-dif…
Browse files Browse the repository at this point in the history
…ference-only boxes

resolved #38
  • Loading branch information
Fallen-Breath committed Jun 26, 2024
1 parent 431e2b4 commit 05da26b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 21 deletions.
Binary file modified docs/assets/shulkerBoxItemContentHint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion docs/document-en_us.md
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,8 @@ Show a hint of content of shulker box item at the lower-left corner of the shulk

If the shulker box contains only 1 item type, then that item in the box will be shown

If the shulker box contains only 1 item type with different nbt, then "*" will be appended

If the shulker box contains multiple types of item, then "..." will be shown

If the shulker box is empty, no hint will be shown
Expand All @@ -1770,7 +1772,7 @@ The scale of the hint stuffs in option shulkerBoxItemContentHint
- Type: double (Generic)
- Default value: `0.5`
- Minimum value: `0.01`
- Maximum value: `1.0`
- Maximum value: `0.75`


### shulkerBoxItemContentHintShowBarOnMixed
Expand Down
4 changes: 3 additions & 1 deletion docs/document-zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,8 @@ FOV覆盖的开关

若潜影盒仅包含1种物品类型,将显示盒中的那一种物品

若潜影盒仅包含1种物品类型但nbt有不同,将追加显示一个“*

若潜影盒包含多种物品类型,将显示“...”

若潜影盒为空,则不显示内容提示
Expand All @@ -1766,7 +1768,7 @@ FOV覆盖的开关
- 类型: 实数 (通用)
- 默认值: `0.5`
- 最小值: `0.01`
- 最大值: `1.0`
- 最大值: `0.75`


### 潜影盒物品内容提示-杂盒也有容量条 (shulkerBoxItemContentHintShowBarOnMixed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public class TweakerMoreConfigs
public static final TweakerMoreConfigBoolean SHULKER_BOX_ITEM_CONTENT_HINT = newConfigBoolean("shulkerBoxItemContentHint", false);

@Config(type = Config.Type.GENERIC, category = Config.Category.MC_TWEAKS)
public static final TweakerMoreConfigDouble SHULKER_BOX_ITEM_CONTENT_HINT_SCALE = newConfigDouble("shulkerBoxItemContentHintScale", 0.5, 0.01, 1);
public static final TweakerMoreConfigDouble SHULKER_BOX_ITEM_CONTENT_HINT_SCALE = newConfigDouble("shulkerBoxItemContentHintScale", 0.5, 0.01, 0.75);

@Config(type = Config.Type.GENERIC, category = Config.Category.MC_TWEAKS)
public static final TweakerMoreConfigBoolean SHULKER_BOX_ITEM_CONTENT_HINT_SHOW_BAR_ON_MIXED = newConfigBoolean("shulkerBoxItemContentHintShowBarOnMixed", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static class Info
{
public boolean enabled;
public boolean allItemSame;
public boolean allItemSameIgnoreNbt;
public double scale;
public ItemStack stack;
public double fillRatio;
Expand Down Expand Up @@ -63,23 +64,32 @@ public static Info prepareInformation(ItemStack itemStack)

ItemStack std = null;
info.allItemSame = true;
info.allItemSameIgnoreNbt = true;
for (ItemStack stack : stackList.get())
{
if (!stack.isEmpty())
{
if (std == null)
{
std = stack;
continue;
}
// to be equal: item type equals, item nbt equals
//#if MC >= 12000
//$$ else if (!ItemStack.canCombine(stack, std))
//#else
else if (!(ItemStack.areItemsEqual(stack, std) && ItemStack.areTagsEqual(stack, std)))

boolean itemEqual = ItemStack.areItemsEqual(stack, std);
boolean itemAndNbtEqual =
//#if MC >= 12000
//$$ ItemStack.canCombine(stack, std)
//#else
itemEqual && ItemStack.areTagsEqual(stack, std);
//#endif

if (!itemAndNbtEqual)
{
info.allItemSame = false;
break;
}
if (!itemEqual)
{
info.allItemSameIgnoreNbt = false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static void render(
RenderUtil.Scaler scaler = RenderUtil.createScaler(x, y + SLOT_WIDTH, info.scale);
scaler.apply(renderContext);

if (info.allItemSame)
if (info.allItemSame || info.allItemSameIgnoreNbt)
{
renderMiniItem(
renderContext,
Expand All @@ -108,9 +108,9 @@ public static void render(
info, x, y
);
}
else
if (!info.allItemSame)
{
renderQuestionMark(
renderText(
//#if MC >= 11500
textMatrixStack,
//#endif
Expand All @@ -128,8 +128,9 @@ public static void render(
//$$ RenderSystem.applyModelViewMatrix();
//#endif

boolean mixedBox = !info.allItemSameIgnoreNbt && !info.allItemSame;
if (
(info.allItemSame || TweakerMoreConfigs.SHULKER_BOX_ITEM_CONTENT_HINT_SHOW_BAR_ON_MIXED.getBooleanValue())
(!mixedBox || TweakerMoreConfigs.SHULKER_BOX_ITEM_CONTENT_HINT_SHOW_BAR_ON_MIXED.getBooleanValue())
&& (0 < info.fillRatio && info.fillRatio < 1)
)
{
Expand Down Expand Up @@ -199,21 +200,23 @@ private static void renderMiniItem(
}
}

private static void renderQuestionMark(
private static void renderText(
//#if MC >= 11500
MatrixStack textMatrixStack,
//#endif
double zOffset, ShulkerBoxItemContentHintCommon.Info info, int x, int y
)
{
String text = "...";
String text = info.allItemSameIgnoreNbt ? "*" : "...";
boolean putTextOnRight = info.allItemSameIgnoreNbt && info.scale <= 0.75;
float width = RenderUtil.getRenderWidth(text);
float height = RenderUtil.TEXT_HEIGHT;
float textX = x + (SLOT_WIDTH - width) * 0.5F;
float textY = y + SLOT_WIDTH - height - 3;
int color = 0xDDDDDD;
float textX = putTextOnRight ? x + SLOT_WIDTH + 0.5F : x + (SLOT_WIDTH - width) * 0.5F;
float textY = putTextOnRight ? y + (SLOT_WIDTH - height) * 0.5F : y + SLOT_WIDTH - height - 3;
double textScale = SLOT_WIDTH / height * 0.7 * (putTextOnRight ? 0.9 : 1);
int textColor = 0xDDDDDD;

RenderUtil.Scaler textScaler = RenderUtil.createScaler(textX + width * 0.5, textY + height * 0.5, SLOT_WIDTH / height * 0.7);
RenderUtil.Scaler textScaler = RenderUtil.createScaler(textX + width * 0.5, textY + height * 0.5, textScale);
textScaler.apply(RenderContext.of(
//#if MC >= 11600
//$$ textMatrixStack
Expand All @@ -228,7 +231,7 @@ private static void renderQuestionMark(
text,
textX,
textY,
color,
textColor,
true,
// TODO: check why this doesn't get remapped
//#if MC >= 11800
Expand All @@ -250,7 +253,7 @@ private static void renderQuestionMark(
//$$ GlStateManager.disableLighting();
//$$ GlStateManager.disableDepthTest();
//$$ GlStateManager.disableBlend();
//$$ textRenderer.drawWithShadow(text, textX, textY, color);
//$$ textRenderer.drawWithShadow(text, textX, textY, textColor);
//$$ GlStateManager.enableBlend();
//$$ GlStateManager.enableLighting();
//$$ GlStateManager.enableDepthTest();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/tweakermore/lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ tweakermore:
comment: |-
Show a hint of content of shulker box item at the lower-left corner of the shulker box
If the shulker box contains only 1 item type, then that item in the box will be shown
If the shulker box contains only 1 item type with different nbt, then "*" will be appended
If the shulker box contains multiple types of item, then "..." will be shown
If the shulker box is empty, no hint will be shown
Also, a fill-level bar will be rendered at the lower-right corner,
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/tweakermore/lang/zh_cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ tweakermore:
comment: |-
在渲染潜影盒物品时,在潜影盒的左下角显示一个盒中内容的提示
若潜影盒仅包含1种物品类型,将显示盒中的那一种物品
若潜影盒仅包含1种物品类型但nbt有不同,将追加显示一个“*”
若潜影盒包含多种物品类型,将显示“...”
若潜影盒为空,则不显示内容提示
除此之外,若潜影盒非空且非全满,
Expand Down

0 comments on commit 05da26b

Please sign in to comment.