Skip to content

Commit

Permalink
Update to 1.20.1 (closes #20)
Browse files Browse the repository at this point in the history
Add support for paintings (closes #15) and  suspicious sand/gravel
Fix signs
  • Loading branch information
A5b84 committed Jun 17, 2023
1 parent 2e46114 commit d9e2954
Show file tree
Hide file tree
Showing 21 changed files with 252 additions and 150 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Changelog

### [1.4.3] (1.20+)
### [1.5.0] (1.20+)
- Updated to 1.20.1
- Added support for paintings ([#15](https://github.com/A5b84/held-item-info/issues/15)) and suspicious sand/gravel
- Added `pt_br` translation ([#16](https://github.com/A5b84/held-item-info/pull/16))
- Fabric API is no longer required

### [1.4.2] (1.19.3-1.19.4)
- Added `ru_ru` and `zh_cn` translations ([#10](https://github.com/A5b84/held-item-info/pull/10), [#11](https://github.com/A5b84/held-item-info/pull/11))
Expand Down Expand Up @@ -54,4 +57,4 @@
[1.4.0]: https://github.com/A5b84/dark-loading-screen/releases/tag/v1.4.0
[1.4.1]: https://github.com/A5b84/dark-loading-screen/releases/tag/v1.4.1
[1.4.2]: https://github.com/A5b84/dark-loading-screen/releases/tag/v1.4.2
[1.4.3]: https://github.com/A5b84/dark-loading-screen/releases/tag/v1.4.3
[1.5.0]: https://github.com/A5b84/dark-loading-screen/releases/tag/v1.5.0
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Held Item Info

A client-side [Fabric](https://fabricmc.net) / [Quilt](https://quiltmc.org/) mod that shows information (like enchantments) about the held item under its name. Requires Fabric API ([CurseForge](https://www.curseforge.com/minecraft/mc-mods/fabric-api) / [Modrinth](https://modrinth.com/mod/fabric-api)).
A client-side [Fabric](https://fabricmc.net) / [Quilt](https://quiltmc.org/) mod that shows information (like enchantments) about the held item under its name.

The following can be displayed when holding an item:
- Enchantments
Expand All @@ -14,6 +14,7 @@ The following can be displayed when holding an item:
- `Unbreakable` tag
- Sign text
- Title of Music Discs and Disc Fragments
- Painting information (title, author, dimensions)
- Instrument of Goat Horns
- Author and generation of Written Books
- Filled map identifier
Expand Down
26 changes: 11 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

base {
archivesName = project.archives_base_name
}

repositories {
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.terraformersmc.com/" }
Expand All @@ -20,15 +20,9 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Mod Menu
modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}"
// Cloth Config
modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") {
exclude(group: "net.fabricmc.fabric-api")
}
modApi "com.terraformersmc:modmenu:${project.mod_menu_version}"
modApi "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}"
}

processResources {
Expand All @@ -40,7 +34,6 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
}

Expand All @@ -49,11 +42,14 @@ java {
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

jar {
from(["COPYING", "COPYING.LESSER"]) {
rename { "${it}_${project.archivesBaseName}"}
rename { "${it}_${base.archivesName.get()}"}
}
}

Expand Down
26 changes: 13 additions & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Fabric Properties
# https://fabricmc.net/develop
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.5
loader_version=0.14.12
# https://fabricmc.net/develop
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.1
loader_version=0.14.21

# Mod Properties
mod_version = 1.4.2
maven_group = io.github.a5b84
archives_base_name = held-item-info
mod_version=1.5.0
maven_group=io.github.a5b84
archives_base_name=held-item-info

# Dependencies
# Fabric API (https://fabricmc.net/develop)
fabric_version=0.72.0+1.19.3
# Mod Menu (https://modrinth.com/mod/modmenu/versions)
mod_menu_version=5.0.2
# Cloth Config (https://linkie.shedaniel.me/dependencies)
cloth_config_version=9.0.94
# https://fabricmc.net/develop
fabric_version=0.83.1+1.20.1
# https://modrinth.com/mod/modmenu/versions
mod_menu_version=7.0.1
# https://linkie.shedaniel.dev/dependencies
cloth_config_version=11.0.99
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
11 changes: 6 additions & 5 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -144,15 +141,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
52 changes: 28 additions & 24 deletions src/main/java/io/github/a5b84/helditeminfo/Appenders.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.a5b84.helditeminfo;

import com.google.gson.JsonParseException;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.item.EnchantedBookItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
Expand Down Expand Up @@ -78,9 +77,9 @@ public static void appendContainerContent(TooltipBuilder builder) {
private static boolean appendContainerContent(TooltipBuilder builder, NbtCompound tag) {
if (tag == null) return false;

NbtList items = tag.getList("Items", NbtType.COMPOUND);
NbtList items = tag.getList("Items", NbtElement.COMPOUND_TYPE);

if (tag.contains("LootTable", NbtType.STRING)) {
if (tag.contains("LootTable", NbtElement.STRING_TYPE)) {
// Loot table (same as vanilla shulker boxes)
builder.append(Text.literal("???????"));
return true;
Expand All @@ -89,27 +88,10 @@ private static boolean appendContainerContent(TooltipBuilder builder, NbtCompoun
boolean added = false;

for (NbtElement itemElement : items) {
if (!(itemElement instanceof NbtCompound itemTag)
|| itemTag.isEmpty()) {
continue;
if (itemElement instanceof NbtCompound itemNbt
&& appendItem(builder, itemNbt)) {
added = true;
}
ItemStack iStack = ItemStack.fromNbt(itemTag);
if (iStack.isEmpty()) continue;

Text text;
if (builder.canAdd()) {
text = iStack.getName()
.copy() // shallowCopy to get a MutableText
.append(" x" + iStack.getCount())
.formatted(TooltipBuilder.DEFAULT_COLOR);
} else {
// If it's full and there are still items left, add `null`
// instead so the "and x more" shows the right number
text = null;
}

builder.append(text);
added = true;
}

return added;
Expand All @@ -118,6 +100,28 @@ private static boolean appendContainerContent(TooltipBuilder builder, NbtCompoun
}
}

public static boolean appendItem(TooltipBuilder builder, NbtCompound itemNbt) {
if (itemNbt.isEmpty()) return false;

ItemStack iStack = ItemStack.fromNbt(itemNbt);
if (iStack.isEmpty()) return false;

Text text;
if (builder.canAdd()) {
text = iStack.getName()
.copy() // shallowCopy to get a MutableText
.append(" x" + iStack.getCount())
.formatted(TooltipBuilder.DEFAULT_COLOR);
} else {
// If it's full and there are still items left, add `null`
// instead so the "and x more" shows the right number
text = null;
}

builder.append(text);
return true;
}


/**
* Adds the item's lore to the tooltip.
Expand All @@ -127,7 +131,7 @@ public static void appendLore(TooltipBuilder builder) {
NbtCompound displayTag = builder.stack.getSubNbt("display");
if (displayTag == null) return;

NbtList loreTag = displayTag.getList("Lore", NbtType.STRING);
NbtList loreTag = displayTag.getList("Lore", NbtElement.STRING_TYPE);
if (loreTag.isEmpty()) return;

// Convert it to a list of text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ default void heldItemInfo_appendTooltip(TooltipBuilder builder) {
Item item = builder.stack.getItem();
List<Text> tooltip = new ArrayList<>();
item.appendTooltip(builder.stack, null, tooltip, TooltipContext.Default.BASIC);
tooltip = postProcess(builder, tooltip);
tooltip = heldItemInfo_postProcess(builder, tooltip);
builder.appendAll(tooltip);
}

default List<Text> postProcess(TooltipBuilder builder, List<Text> tooltip) {
default List<Text> heldItemInfo_postProcess(TooltipBuilder builder, List<Text> tooltip) {
return tooltip;
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/github/a5b84/helditeminfo/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public static boolean hasHideFlag(NbtCompound tag, int flag) {
return config.respectHideFlags() && (tag.getInt("HideFlags") & flag) != 0;
}

public static void setAllToDefaultColor(List<Text> lines) {
for (Text line : lines) {
if (line instanceof MutableText mutableLine) {
mutableLine.formatted(TooltipBuilder.DEFAULT_COLOR);
}
}
}

public static boolean isBlank(StringVisitable visitable) {
Optional<Boolean> result = visitable.visit(asString -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class HeldItemInfoConfig {
public boolean showUnbreakable() { return true; }
public boolean showSignText() { return true; }
public boolean showMusicDiscDescription() { return true; }
public boolean showPaintingDescription() { return true; }
public boolean showGoatHornInstrument() { return true; }
public boolean showBookMeta() { return true; }
public boolean showFilledMapId() { return false; }
Expand Down Expand Up @@ -93,6 +94,7 @@ public static class HeldItemInfoAutoConfig extends HeldItemInfoConfig implements
private boolean showUnbreakable = super.showUnbreakable();
private boolean showSignText = super.showSignText();
private boolean showMusicDiscDescription = super.showMusicDiscDescription();
private boolean showPaintingDescription = super.showPaintingDescription();
private boolean showGoatHornInstrument = super.showGoatHornInstrument();
private boolean showBookMeta = super.showBookMeta();
private boolean showFilledMapId = super.showFilledMapId();
Expand Down Expand Up @@ -132,6 +134,7 @@ public static class HeldItemInfoAutoConfig extends HeldItemInfoConfig implements
@Override public boolean showUnbreakable() { return showUnbreakable; }
@Override public boolean showSignText() { return showSignText; }
@Override public boolean showMusicDiscDescription() { return showMusicDiscDescription; }
@Override public boolean showPaintingDescription() { return showPaintingDescription; }
@Override public boolean showGoatHornInstrument() { return showGoatHornInstrument; }
@Override public boolean showBookMeta() { return showBookMeta; }
@Override public boolean showFilledMapId() { return showFilledMapId; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import net.minecraft.SharedConstants;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -35,7 +34,7 @@
import static io.github.a5b84.helditeminfo.Util.FONT_HEIGHT;

@Mixin(InGameHud.class)
public abstract class HeldItemTooltipMixin extends DrawableHelper {
public abstract class HeldItemTooltipMixin {

@Shadow private @Final MinecraftClient client;
@Shadow private int heldItemTooltipFade;
Expand Down Expand Up @@ -66,8 +65,8 @@ public void onBeforeRenderHeldItemTooltip(CallbackInfo ci) {

/** Renders the background if enabled in the vanilla settings */
@Redirect(method = "renderHeldItemTooltip",
at = @At(value = "INVOKE", target = "net/minecraft/client/gui/hud/InGameHud.fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V"))
private void fillBackgroundProxy(MatrixStack stack, int x1, int y1, int x2, int y2, int color) {
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;fill(IIIII)V"))
private void fillBackgroundProxy(DrawContext context, int x1, int y1, int x2, int y2, int color) {
// Only do the math part when actually rendering
if ((color & 0xff000000) == 0) return;

Expand All @@ -81,8 +80,7 @@ private void fillBackgroundProxy(MatrixStack stack, int x1, int y1, int x2, int
}

// Fill the background
fill(
stack,
context.fill(
(scaledWidth - maxWidth) / 2 - 2, y - 2,
(scaledWidth + maxWidth) / 2 + 2, y + (config.lineHeight() * tooltip.size()) + 2,
color
Expand All @@ -92,12 +90,12 @@ private void fillBackgroundProxy(MatrixStack stack, int x1, int y1, int x2, int

/** Replaces vanilla rendering with the mod's */
@Redirect(method = "renderHeldItemTooltip",
at = @At(value = "INVOKE", target = "net/minecraft/client/font/TextRenderer.drawWithShadow(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/text/Text;FFI)I"))
private int drawTextProxy(TextRenderer fontRenderer, MatrixStack stack, Text name, float _x, float _y, int color) {
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;III)I"))
private int drawTextProxy(DrawContext context, TextRenderer textRenderer, Text name, int _x, int _y, int color) {
int lineHeight = config.lineHeight();
for (TooltipLine line : tooltip) {
int x = (scaledWidth - line.width) / 2;
fontRenderer.drawWithShadow(stack, line.text, x, y, color);
context.drawTextWithShadow(textRenderer, line.text, x, y, color);
y += lineHeight;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import io.github.a5b84.helditeminfo.TooltipAppender;
import io.github.a5b84.helditeminfo.TooltipBuilder;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.block.BeehiveBlock;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;

Expand All @@ -22,7 +22,7 @@ public boolean heldItemInfo_shouldAppendTooltip() {
public void heldItemInfo_appendTooltip(TooltipBuilder builder) {
NbtCompound blockEntityTag = builder.stack.getSubNbt("BlockEntityTag");
if (blockEntityTag != null) {
int beeCount = blockEntityTag.getList("Bees", NbtType.COMPOUND).size();
int beeCount = blockEntityTag.getList("Bees", NbtElement.COMPOUND_TYPE).size();
if (beeCount > 0) {
Text text = Text.translatable("entity.minecraft.bee")
.append(" x" + beeCount)
Expand Down

0 comments on commit d9e2954

Please sign in to comment.