Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/net/mision_thi/nbttooltips/NBTtooltipsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class NBTtooltipsMod implements ModInitializer {
public static final MinecraftClient client = MinecraftClient.getInstance();
public static final String MOD_ID = "NBTtooltips";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static final KeyBinding KEYBIND = KeyBindingHelper.registerKeyBinding(new KeyBinding("nbttooltips.keybind", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_LEFT_ALT, KeyBinding.INVENTORY_CATEGORY));
public static final KeyBinding SHOW_NBT_KEYBIND = KeyBindingHelper.registerKeyBinding(new KeyBinding("nbttooltips.keybind.show", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_LEFT_ALT, KeyBinding.INVENTORY_CATEGORY));
public static final KeyBinding COPY_NBT_KEYBIND = KeyBindingHelper.registerKeyBinding(new KeyBinding("nbttooltips.keybind.copy", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_RIGHT_ALT, KeyBinding.INVENTORY_CATEGORY));

@Override
public void onInitialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,30 @@ public abstract class mision_thi_TooltipChanger {

@Redirect(method = "getTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/tooltip/TooltipType;isCreative()Z"))
protected boolean forceVisible(TooltipType instance) {
int code = InputUtil.fromTranslationKey(NBTtooltipsMod.KEYBIND.getBoundKeyTranslationKey()).getCode();
int code = InputUtil.fromTranslationKey(NBTtooltipsMod.SHOW_NBT_KEYBIND.getBoundKeyTranslationKey()).getCode();
shouldShow = instance.isAdvanced() && InputUtil.isKeyPressed(client.getWindow().getHandle(), code);
return shouldShow || instance.isCreative();
}

@Inject(method = "getTooltip", at = @At("RETURN"))
protected void injectEditTooltipmethod(Item.TooltipContext context, PlayerEntity player, TooltipType type, CallbackInfoReturnable<List<Text>> info) {

ItemStack itemStack = (ItemStack) (Object) this;

// If the advanced tooltips are on and the shift key is pressed the method is run.
if (shouldShow && !isEmpty()) {
ItemStack itemStack = (ItemStack) (Object) this;

/*
Before calling the main method from the `tooltip changer` class.
We check if the item even has custom NBT.
*/
if (!itemStack.getComponentChanges().isEmpty()) {
TooltipChanger.Main(itemStack, info.getReturnValue());
}
}

int code = InputUtil.fromTranslationKey(NBTtooltipsMod.COPY_NBT_KEYBIND.getBoundKeyTranslationKey()).getCode();
if (InputUtil.isKeyPressed(client.getWindow().getHandle(), code)) {
client.keyboard.setClipboard(TooltipChanger.getNbtElement(itemStack).asString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ public static void Main(ItemStack itemStack, List<Text> list) {
// build the nbt text
NbtTextBuilder builder = new NbtTextBuilder();
builder.append(Text.translatable("item.nbt_tags.nbttooltips").formatted(Formatting.DARK_GRAY));
builder.buildElement(ComponentChanges.CODEC.encodeStart(NBT_OPS_UNLIMITED, itemStack.getComponentChanges()).getOrThrow());
builder.buildElement(getNbtElement(itemStack));
list.addAll(index, builder.build());
}

public static NbtElement getNbtElement(ItemStack itemStack) {
return ComponentChanges.CODEC.encodeStart(NBT_OPS_UNLIMITED, itemStack.getComponentChanges()).getOrThrow();
}

/**
* @author aMelonRind
*/
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/nbttooltips/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"nbttooltips.keybind": "Show NBT",
"nbttooltips.keybind.show": "Show NBT",
"nbttooltips.keybind.copy": "Copy NBT",
"item.nbt_tags.nbttooltips": "NBT: "
}