diff --git a/src/main/java/meteordevelopment/meteorclient/commands/Command.java b/src/main/java/meteordevelopment/meteorclient/commands/Command.java index 22914ec298..d1b73e811f 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/Command.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/Command.java @@ -9,32 +9,34 @@ import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.systems.config.Config; import meteordevelopment.meteorclient.utils.Utils; import meteordevelopment.meteorclient.utils.player.ChatUtils; +import net.minecraft.client.MinecraftClient; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.CommandSource; import net.minecraft.registry.BuiltinRegistries; import net.minecraft.server.command.CommandManager; import net.minecraft.text.Text; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; public abstract class Command { protected static final CommandRegistryAccess REGISTRY_ACCESS = CommandManager.createRegistryAccess(BuiltinRegistries.createWrapperLookup()); + protected static final int SINGLE_SUCCESS = com.mojang.brigadier.Command.SINGLE_SUCCESS; + protected static final MinecraftClient mc = MeteorClient.mc; private final String name; private final String title; private final String description; - private final List aliases = new ArrayList<>(); + private final List aliases; public Command(String name, String description, String... aliases) { this.name = name; this.title = Utils.nameToTitle(name); this.description = description; - Collections.addAll(this.aliases, aliases); + this.aliases = List.of(aliases); } // Helper methods to painlessly infer the CommandSource generic type argument diff --git a/src/main/java/meteordevelopment/meteorclient/events/game/SectionVisibleEvent.java b/src/main/java/meteordevelopment/meteorclient/events/game/SectionVisibleEvent.java deleted file mode 100644 index 726faf7966..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/events/game/SectionVisibleEvent.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.events.game; - -import net.minecraft.component.DataComponentType; - - -public class SectionVisibleEvent { - private static final SectionVisibleEvent INSTANCE = new SectionVisibleEvent(); - - public DataComponentType section; - public boolean visible; - - public static SectionVisibleEvent get(DataComponentType section, boolean visible) { - INSTANCE.section = section; - INSTANCE.visible = visible; - return INSTANCE; - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ArmorTrimMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ArmorTrimMixin.java new file mode 100644 index 0000000000..582a918398 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ArmorTrimMixin.java @@ -0,0 +1,22 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixin; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.render.BetterTooltips; +import net.minecraft.item.trim.ArmorTrim; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(ArmorTrim.class) +public class ArmorTrimMixin { + @ModifyExpressionValue(method = "appendTooltip", at = @At(value = "FIELD", target = "Lnet/minecraft/item/trim/ArmorTrim;showInTooltip:Z")) + private boolean modifyShowInTooltip(boolean original) { + BetterTooltips bt = Modules.get().get(BetterTooltips.class); + return (bt.isActive() && bt.upgrades.get()) || original; + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BundleItemMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BundleItemMixin.java new file mode 100644 index 0000000000..52978a3062 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BundleItemMixin.java @@ -0,0 +1,28 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixin; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.render.BetterTooltips; +import net.minecraft.item.BundleItem; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(BundleItem.class) +public class BundleItemMixin { + @ModifyExpressionValue(method = "getTooltipData", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;contains(Lnet/minecraft/component/DataComponentType;)Z", ordinal = 0)) + private boolean modifyContains1(boolean original) { + BetterTooltips bt = Modules.get().get(BetterTooltips.class); + return !(bt.isActive() && bt.tooltip.get()) && original; + } + + @ModifyExpressionValue(method = "getTooltipData", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;contains(Lnet/minecraft/component/DataComponentType;)Z", ordinal = 1)) + private boolean modifyContains2(boolean original) { + BetterTooltips bt = Modules.get().get(BetterTooltips.class); + return !(bt.isActive() && bt.additional.get()) && original; + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java index f19a141076..d64dbce1cc 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java @@ -140,7 +140,7 @@ private void onItemPickupAnimation(ItemPickupAnimationS2CPacket packet, Callback private void onSendChatMessage(String message, CallbackInfo ci) { if (ignoreChatMessage) return; - if (BaritoneUtils.IS_AVAILABLE || !message.startsWith(BaritoneUtils.getPrefix())) { + if (!(BaritoneUtils.IS_AVAILABLE && message.startsWith(BaritoneUtils.getPrefix()))) { SendMessageEvent event = MeteorClient.EVENT_BUS.post(SendMessageEvent.get(message)); if (!event.isCancelled()) { diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ContainerComponentAccessor.java b/src/main/java/meteordevelopment/meteorclient/mixin/ContainerComponentAccessor.java new file mode 100644 index 0000000000..87a763cbd9 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ContainerComponentAccessor.java @@ -0,0 +1,18 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixin; + +import net.minecraft.component.type.ContainerComponent; +import net.minecraft.item.ItemStack; +import net.minecraft.util.collection.DefaultedList; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(ContainerComponent.class) +public interface ContainerComponentAccessor { + @Accessor + DefaultedList getStacks(); +} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/DyedColorComponentMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/DyedColorComponentMixin.java new file mode 100644 index 0000000000..7d7a80da8d --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixin/DyedColorComponentMixin.java @@ -0,0 +1,22 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixin; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.render.BetterTooltips; +import net.minecraft.component.type.DyedColorComponent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(DyedColorComponent.class) +public class DyedColorComponentMixin { + @ModifyExpressionValue(method = "appendTooltip", at = @At(value = "FIELD", target = "Lnet/minecraft/component/type/DyedColorComponent;showInTooltip:Z")) + private boolean modifyShowInTooltip(boolean original) { + BetterTooltips bt = Modules.get().get(BetterTooltips.class); + return (bt.isActive() && bt.dye.get()) || original; + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/HandledScreenMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/HandledScreenMixin.java index 66072bc939..7813d648b0 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/HandledScreenMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/HandledScreenMixin.java @@ -12,9 +12,11 @@ import meteordevelopment.meteorclient.utils.Utils; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.BookScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.component.DataComponentTypes; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.screen.ScreenHandler; @@ -57,6 +59,9 @@ public abstract class HandledScreenMixin extends Screen @Shadow protected abstract void onMouseClick(Slot slot, int invSlot, int clickData, SlotActionType actionType); + @Shadow + public abstract void close(); + @Unique private static final ItemStack[] ITEMS = new ItemStack[27]; @@ -104,6 +109,11 @@ private void mouseClicked(double mouseX, double mouseY, int button, CallbackInfo if (Utils.hasItems(itemStack) || itemStack.getItem() == Items.ENDER_CHEST) { cir.setReturnValue(Utils.openContainer(focusedSlot.getStack(), ITEMS, false)); } + else if (itemStack.get(DataComponentTypes.WRITTEN_BOOK_CONTENT) != null || itemStack.get(DataComponentTypes.WRITABLE_BOOK_CONTENT) != null) { + close(); + mc.setScreen(new BookScreen(BookScreen.Contents.create(itemStack))); + cir.setReturnValue(true); + } } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ItemEnchantmentsComponentMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ItemEnchantmentsComponentMixin.java new file mode 100644 index 0000000000..1744328465 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ItemEnchantmentsComponentMixin.java @@ -0,0 +1,22 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixin; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.render.BetterTooltips; +import net.minecraft.component.type.ItemEnchantmentsComponent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(ItemEnchantmentsComponent.class) +public class ItemEnchantmentsComponentMixin { + @ModifyExpressionValue(method = "appendTooltip", at = @At(value = "FIELD", target = "Lnet/minecraft/component/type/ItemEnchantmentsComponent;showInTooltip:Z")) + private boolean modifyShowInTooltip(boolean original) { + BetterTooltips bt = Modules.get().get(BetterTooltips.class); + return (bt.isActive() && bt.enchantments.get()) || original; + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ItemStackMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ItemStackMixin.java index 370aca9ebf..63fd0863ed 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ItemStackMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ItemStackMixin.java @@ -5,11 +5,14 @@ package meteordevelopment.meteorclient.mixin; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.ModifyReturnValue; import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.events.entity.player.FinishUsingItemEvent; import meteordevelopment.meteorclient.events.entity.player.StoppedUsingItemEvent; import meteordevelopment.meteorclient.events.game.ItemStackTooltipEvent; +import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.render.BetterTooltips; import meteordevelopment.meteorclient.utils.Utils; import net.minecraft.entity.LivingEntity; import net.minecraft.item.ItemStack; @@ -37,6 +40,30 @@ private List onGetTooltip(List original) { return original; } + @ModifyExpressionValue(method = "getTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BlockPredicatesChecker;showInTooltip()Z", ordinal = 0)) + private boolean modifyCanBreakText(boolean original) { + BetterTooltips bt = Modules.get().get(BetterTooltips.class); + return (bt.isActive() && bt.canDestroy.get()) || original; + } + + @ModifyExpressionValue(method = "getTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BlockPredicatesChecker;showInTooltip()Z", ordinal = 1)) + private boolean modifyCanPlaceText(boolean original) { + BetterTooltips bt = Modules.get().get(BetterTooltips.class); + return (bt.isActive() && bt.canPlaceOn.get()) || original; + } + + @ModifyExpressionValue(method = "getTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;contains(Lnet/minecraft/component/DataComponentType;)Z", ordinal = 0)) + private boolean modifyContainsTooltip(boolean original) { + BetterTooltips bt = Modules.get().get(BetterTooltips.class); + return !(bt.isActive() && bt.tooltip.get()) && original; + } + + @ModifyExpressionValue(method = "getTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;contains(Lnet/minecraft/component/DataComponentType;)Z", ordinal = 3)) + private boolean modifyContainsAdditional(boolean original) { + BetterTooltips bt = Modules.get().get(BetterTooltips.class); + return !(bt.isActive() && bt.additional.get()) && original; + } + @Inject(method = "finishUsing", at = @At("HEAD")) private void onFinishUsing(World world, LivingEntity user, CallbackInfoReturnable info) { if (user == mc.player) { @@ -50,4 +77,10 @@ private void onStoppedUsing(World world, LivingEntity user, int remainingUseTick MeteorClient.EVENT_BUS.post(StoppedUsingItemEvent.get((ItemStack) (Object) this)); } } + + @ModifyExpressionValue(method = "appendAttributeModifiersTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/component/type/AttributeModifiersComponent;showInTooltip()Z")) + private boolean modifyShowInTooltip(boolean original) { + BetterTooltips bt = Modules.get().get(BetterTooltips.class); + return (bt.isActive() && bt.modifiers.get()) || original; + } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/UnbreakableComponentMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/UnbreakableComponentMixin.java new file mode 100644 index 0000000000..307f2e6216 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixin/UnbreakableComponentMixin.java @@ -0,0 +1,22 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixin; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.render.BetterTooltips; +import net.minecraft.component.type.UnbreakableComponent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(UnbreakableComponent.class) +public class UnbreakableComponentMixin { + @ModifyExpressionValue(method = "appendTooltip", at = @At(value = "FIELD", target = "Lnet/minecraft/component/type/UnbreakableComponent;showInTooltip:Z")) + private boolean modifyShowInTooltip(boolean original) { + BetterTooltips bt = Modules.get().get(BetterTooltips.class); + return (bt.isActive() && bt.unbreakable.get()) || original; + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java index 48fca09f5e..4487d23b09 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java @@ -5,11 +5,9 @@ package meteordevelopment.meteorclient.systems.modules.render; -import com.google.gson.JsonParseException; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import meteordevelopment.meteorclient.events.game.ItemStackTooltipEvent; -import meteordevelopment.meteorclient.events.game.SectionVisibleEvent; import meteordevelopment.meteorclient.events.render.TooltipDataEvent; import meteordevelopment.meteorclient.mixin.EntityAccessor; import meteordevelopment.meteorclient.mixin.EntityBucketItemAccessor; @@ -43,7 +41,6 @@ import net.minecraft.util.Formatting; import net.minecraft.util.collection.DefaultedList; -import java.io.IOException; import java.util.Comparator; import java.util.List; @@ -75,7 +72,7 @@ public class BetterTooltips extends Module { private final Setting middleClickOpen = sgGeneral.add(new BoolSetting.Builder() .name("middle-click-open") - .description("Opens a GUI window with the inventory of the storage block when you middle click the item.") + .description("Opens a GUI window with the inventory of the storage block or book when you middle click the item.") .defaultValue(true) .build() ); @@ -167,56 +164,63 @@ public class BetterTooltips extends Module { //Hide flags - private final Setting enchantments = sgHideFlags.add(new BoolSetting.Builder() + public final Setting tooltip = sgHideFlags.add(new BoolSetting.Builder() + .name("tooltip") + .description("Show the tooltip when it's hidden.") + .defaultValue(false) + .build() + ); + + public final Setting enchantments = sgHideFlags.add(new BoolSetting.Builder() .name("enchantments") .description("Show enchantments when it's hidden.") .defaultValue(false) .build() ); - private final Setting modifiers = sgHideFlags.add(new BoolSetting.Builder() + public final Setting modifiers = sgHideFlags.add(new BoolSetting.Builder() .name("modifiers") .description("Show item modifiers when it's hidden.") .defaultValue(false) .build() ); - private final Setting unbreakable = sgHideFlags.add(new BoolSetting.Builder() + public final Setting unbreakable = sgHideFlags.add(new BoolSetting.Builder() .name("unbreakable") .description("Show \"Unbreakable\" tag when it's hidden.") .defaultValue(false) .build() ); - private final Setting canDestroy = sgHideFlags.add(new BoolSetting.Builder() + public final Setting canDestroy = sgHideFlags.add(new BoolSetting.Builder() .name("can-destroy") .description("Show \"CanDestroy\" tag when it's hidden.") .defaultValue(false) .build() ); - private final Setting canPlaceOn = sgHideFlags.add(new BoolSetting.Builder() + public final Setting canPlaceOn = sgHideFlags.add(new BoolSetting.Builder() .name("can-place-on") .description("Show \"CanPlaceOn\" tag when it's hidden.") .defaultValue(false) .build() ); - private final Setting additional = sgHideFlags.add(new BoolSetting.Builder() + public final Setting additional = sgHideFlags.add(new BoolSetting.Builder() .name("additional") .description("Show potion effects, firework status, book author, etc when it's hidden.") .defaultValue(false) .build() ); - private final Setting dye = sgHideFlags.add(new BoolSetting.Builder() + public final Setting dye = sgHideFlags.add(new BoolSetting.Builder() .name("dye") .description("Show dyed item tags when it's hidden.") .defaultValue(false) .build() ); - private final Setting upgrades = sgHideFlags.add(new BoolSetting.Builder() + public final Setting upgrades = sgHideFlags.add(new BoolSetting.Builder() .name("armor-trim") .description("Show armor trims when it's hidden.") .defaultValue(false) @@ -279,8 +283,8 @@ private void appendTooltip(ItemStackTooltipEvent event) { else count = String.format("%d bytes", byteCount); event.list.add(Text.literal(count).formatted(Formatting.GRAY)); - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + event.list.add(Text.literal("Error getting bytes.").formatted(Formatting.RED)); } } @@ -303,18 +307,15 @@ private void appendTooltip(ItemStackTooltipEvent event) { private void getTooltipData(TooltipDataEvent event) { // Container preview if (previewShulkers() && Utils.hasItems(event.itemStack)) { - NbtComponent nbtComponent = event.itemStack.get(DataComponentTypes.BLOCK_ENTITY_DATA); - if (nbtComponent != null) { - DefaultedList itemStacks = DefaultedList.ofSize(27, ItemStack.EMPTY); - Inventories.readNbt(nbtComponent.copyNbt(), itemStacks, DynamicRegistryManager.EMPTY); - event.tooltipData = new ContainerTooltipComponent(itemStacks, Utils.getShulkerColor(event.itemStack)); - } + ItemStack[] itemStacks = new ItemStack[27]; + Utils.getItemsInContainerItem(event.itemStack, itemStacks); + event.tooltipData = new ContainerTooltipComponent(itemStacks, Utils.getShulkerColor(event.itemStack)); } // EChest preview else if (event.itemStack.getItem() == Items.ENDER_CHEST && previewEChest()) { event.tooltipData = EChestMemory.isKnown() - ? new ContainerTooltipComponent(EChestMemory.ITEMS, ECHEST_COLOR) + ? new ContainerTooltipComponent(EChestMemory.ITEMS.toArray(new ItemStack[27]), ECHEST_COLOR) : new TextTooltipComponent(Text.literal("Unknown ender chest inventory.").formatted(Formatting.DARK_RED)); } @@ -333,7 +334,7 @@ else if ((event.itemStack.getItem() == Items.WRITABLE_BOOK || event.itemStack.ge // Banner preview else if (event.itemStack.getItem() instanceof BannerItem && previewBanners()) { event.tooltipData = new BannerTooltipComponent(event.itemStack); - } else if (event.itemStack.getItem() instanceof BannerPatternItem patternItem && previewBanners()) { + } else if (event.itemStack.getItem() instanceof BannerPatternItem && previewBanners()) { BannerPatternsComponent bannerPatternsComponent = event.itemStack.get(DataComponentTypes.BANNER_PATTERNS); if (bannerPatternsComponent != null) { event.tooltipData = new BannerTooltipComponent(createBannerFromLayers(bannerPatternsComponent.layers())); @@ -355,20 +356,6 @@ else if (event.itemStack.getItem() instanceof EntityBucketItem bucketItem && pre } } - @EventHandler - private void onSectionVisible(SectionVisibleEvent event) { - // todo investigate how section visibility works now - if (enchantments.get() && event.section == DataComponentTypes.STORED_ENCHANTMENTS || - modifiers.get() && event.section == DataComponentTypes.ATTRIBUTE_MODIFIERS || - unbreakable.get() && event.section == DataComponentTypes.UNBREAKABLE || - canDestroy.get() && event.section == DataComponentTypes.CAN_BREAK || - canPlaceOn.get() && event.section == DataComponentTypes.CAN_PLACE_ON || - //additional.get() && event.section == ItemStack.TooltipSection.ADDITIONAL || - dye.get() && event.section == DataComponentTypes.DYED_COLOR || - upgrades.get() && event.section == DataComponentTypes.TRIM) - event.visible = true; - } - public void applyCompactShulkerTooltip(ItemStack shulkerItem, List tooltip) { NbtComponent nbtComponent = shulkerItem.get(DataComponentTypes.BLOCK_ENTITY_DATA); @@ -416,18 +403,20 @@ private MutableText getStatusText(StatusEffectInstance effect) { } private Text getFirstPage(ItemStack bookItem) { - ComponentMap components = bookItem.getComponents(); - if (components == ComponentMap.EMPTY) return null; + if (bookItem.get(DataComponentTypes.WRITABLE_BOOK_CONTENT) != null) { + List> pages = bookItem.get(DataComponentTypes.WRITABLE_BOOK_CONTENT).pages(); - List> pages = components.get(DataComponentTypes.WRITABLE_BOOK_CONTENT).pages(); - if (pages.isEmpty()) return null; - if (bookItem.getItem() == Items.WRITABLE_BOOK) return Text.literal(pages.getFirst().get(false)); + if (pages.isEmpty()) return null; + return Text.literal(pages.getFirst().get(false)); + } + else if (bookItem.get(DataComponentTypes.WRITTEN_BOOK_CONTENT) != null) { + List> pages = bookItem.get(DataComponentTypes.WRITTEN_BOOK_CONTENT).pages(); + if (pages.isEmpty()) return null; - try { - return Text.Serialization.fromLenientJson(pages.getFirst().get(false), DynamicRegistryManager.EMPTY); - } catch (JsonParseException e) { - return Text.literal("Invalid book data"); + return pages.getFirst().get(false); } + + return null; } private ItemStack createBannerFromLayers(List pattern) { diff --git a/src/main/java/meteordevelopment/meteorclient/utils/Utils.java b/src/main/java/meteordevelopment/meteorclient/utils/Utils.java index 2cb5525606..7a32b27a27 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/Utils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/Utils.java @@ -49,6 +49,7 @@ import net.minecraft.nbt.NbtList; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.DyeColor; +import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; @@ -63,7 +64,10 @@ import java.io.IOException; import java.io.InputStream; import java.net.InetSocketAddress; -import java.util.*; +import java.util.Arrays; +import java.util.Locale; +import java.util.Random; +import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -215,7 +219,15 @@ public static void getItemsInContainerItem(ItemStack itemStack, ItemStack[] item Arrays.fill(items, ItemStack.EMPTY); ComponentMap components = itemStack.getComponents(); - if (components != null && components.contains(DataComponentTypes.BLOCK_ENTITY_DATA)) { + if (components.contains(DataComponentTypes.CONTAINER)) { + ContainerComponentAccessor container = ((ContainerComponentAccessor) (Object) components.get(DataComponentTypes.CONTAINER)); + DefaultedList stacks = container.getStacks(); + + for (int i = 0; i < stacks.size(); i++) { + if (i >= 0 && i < items.length) items[i] = stacks.get(i); + } + } + else if (components.contains(DataComponentTypes.BLOCK_ENTITY_DATA)) { NbtComponent nbt2 = components.get(DataComponentTypes.BLOCK_ENTITY_DATA); if (nbt2.contains("Items")) { @@ -245,8 +257,10 @@ public static Color getShulkerColor(ItemStack shulkerItem) { } public static boolean hasItems(ItemStack itemStack) { - NbtCompound compoundTag = itemStack.getComponents().getOrDefault(DataComponentTypes.BLOCK_ENTITY_DATA, NbtComponent.DEFAULT).getNbt(); -// itemStack.getComponents().get(DataComponentTypes.CONTAINER).??? + ContainerComponentAccessor container = ((ContainerComponentAccessor) (Object) itemStack.get(DataComponentTypes.CONTAINER)); + if (container != null && !container.getStacks().isEmpty()) return true; + + NbtCompound compoundTag = itemStack.getOrDefault(DataComponentTypes.BLOCK_ENTITY_DATA, NbtComponent.DEFAULT).getNbt(); return compoundTag != null && compoundTag.contains("Items", 9); } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/PeekScreen.java b/src/main/java/meteordevelopment/meteorclient/utils/render/PeekScreen.java index 60a439bf66..59de0030a1 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/PeekScreen.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/PeekScreen.java @@ -11,10 +11,13 @@ import meteordevelopment.meteorclient.utils.Utils; import meteordevelopment.meteorclient.utils.render.color.Color; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.ingame.BookScreen; import net.minecraft.client.gui.screen.ingame.ShulkerBoxScreen; import net.minecraft.client.render.GameRenderer; +import net.minecraft.component.DataComponentTypes; import net.minecraft.inventory.SimpleInventory; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.screen.ShulkerBoxScreenHandler; import net.minecraft.util.Identifier; import org.lwjgl.glfw.GLFW; @@ -37,8 +40,17 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { BetterTooltips tooltips = Modules.get().get(BetterTooltips.class); if (button == GLFW.GLFW_MOUSE_BUTTON_MIDDLE && focusedSlot != null && !focusedSlot.getStack().isEmpty() && mc.player.currentScreenHandler.getCursorStack().isEmpty() && tooltips.middleClickOpen()) { - return Utils.openContainer(focusedSlot.getStack(), contents, false); + ItemStack itemStack = focusedSlot.getStack(); + if (Utils.hasItems(itemStack) || itemStack.getItem() == Items.ENDER_CHEST) { + return Utils.openContainer(focusedSlot.getStack(), contents, false); + } + else if (itemStack.get(DataComponentTypes.WRITTEN_BOOK_CONTENT) != null || itemStack.get(DataComponentTypes.WRITABLE_BOOK_CONTENT) != null) { + close(); + mc.setScreen(new BookScreen(BookScreen.Contents.create(itemStack))); + return true; + } } + return false; } @@ -49,7 +61,7 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (keyCode == GLFW.GLFW_KEY_ESCAPE) { + if (keyCode == GLFW.GLFW_KEY_ESCAPE || mc.options.inventoryKey.matchesKey(keyCode, scanCode)) { close(); return true; } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/tooltip/ContainerTooltipComponent.java b/src/main/java/meteordevelopment/meteorclient/utils/tooltip/ContainerTooltipComponent.java index 50f2ed65f3..21dd00aafc 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/tooltip/ContainerTooltipComponent.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/tooltip/ContainerTooltipComponent.java @@ -15,15 +15,14 @@ import net.minecraft.client.render.GameRenderer; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; -import net.minecraft.util.collection.DefaultedList; public class ContainerTooltipComponent implements TooltipComponent, MeteorTooltipData { private static final Identifier TEXTURE_CONTAINER_BACKGROUND = new MeteorIdentifier("textures/container.png"); - private final DefaultedList items; + private final ItemStack[] items; private final Color color; - public ContainerTooltipComponent(DefaultedList items, Color color) { + public ContainerTooltipComponent(ItemStack[] items, Color color) { this.items = items; this.color = color; } diff --git a/src/main/resources/meteor-client.mixins.json b/src/main/resources/meteor-client.mixins.json index fdc5299987..1fbc3fd788 100644 --- a/src/main/resources/meteor-client.mixins.json +++ b/src/main/resources/meteor-client.mixins.json @@ -13,6 +13,7 @@ "AbstractSignEditScreenAccessor", "AbstractSignEditScreenMixin", "ArmorFeatureRendererMixin", + "ArmorTrimMixin", "BackgroundRendererMixin", "BakedQuadMixin", "BannerBlockEntityRendererMixin", @@ -36,6 +37,7 @@ "BrewingStandScreenMixin", "BufferBuilderAccessor", "BufferRendererAccessor", + "BundleItemMixin", "CameraMixin", "CapabilityTrackerMixin", "ChatHudAccessor", @@ -62,6 +64,7 @@ "CobwebBlockMixin", "CompassAnglePredicateProviderMixin", "ConnectScreenMixin", + "ContainerComponentAccessor", "CrashReportMixin", "CreativeInventoryScreenAccessor", "CreativeSlotMixin", @@ -69,6 +72,7 @@ "DefaultSkinHelperMixin", "DisconnectedScreenMixin", "DrawContextMixin", + "DyedColorComponentMixin", "EnchantingTableBlockEntityRendererMixin", "EndCrystalEntityRendererMixin", "EntityAccessor", @@ -98,6 +102,7 @@ "IdentifierAccessor", "InGameHudMixin", "InGameOverlayRendererMixin", + "ItemEnchantmentsComponentMixin", "ItemEntityMixin", "ItemEntityRendererMixin", "ItemMixin", @@ -164,6 +169,7 @@ "TextVisitFactoryMixin", "TransformationMixin", "TridentItemMixin", + "UnbreakableComponentMixin", "Vec3dMixin", "VertexBufferMixin", "WorldAccessor",