Skip to content

Commit 0a95181

Browse files
committed
massive fixes and improvements
1 parent 8a15026 commit 0a95181

File tree

12 files changed

+158
-71
lines changed

12 files changed

+158
-71
lines changed

src/main/java/meteordevelopment/meteorclient/gui/screens/ContainerInventoryScreen.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
package meteordevelopment.meteorclient.gui.screens;
77

88
import meteordevelopment.meteorclient.utils.Utils;
9+
import net.minecraft.client.gl.RenderPipelines;
910
import net.minecraft.client.gui.DrawContext;
1011
import net.minecraft.client.gui.screen.Screen;
11-
import net.minecraft.client.gl.RenderPipelines;
1212
import net.minecraft.component.DataComponentTypes;
1313
import net.minecraft.component.type.BundleContentsComponent;
1414
import net.minecraft.entity.player.PlayerInventory;
@@ -19,19 +19,19 @@
1919
import net.minecraft.text.Text;
2020
import net.minecraft.util.Identifier;
2121

22-
import static meteordevelopment.meteorclient.MeteorClient.mc;
23-
2422
import java.util.ArrayList;
2523
import java.util.List;
2624

25+
import static meteordevelopment.meteorclient.MeteorClient.mc;
26+
2727
/*
2828
* i couldn't figure out how to add proper outer borders for the GUI without adding custom textures. @TODO
2929
*/
3030
public class ContainerInventoryScreen extends Screen {
3131
private static final Identifier SLOT_TEXTURE = Identifier.ofVanilla("container/slot");
3232
private static final int SLOT_SIZE = 18;
3333
private static final int SCREEN_WIDTH = 176;
34-
34+
3535
private final List<ItemStack> containerItems;
3636
private final PlayerInventory playerInventory;
3737
private final int containerRows;
@@ -42,7 +42,7 @@ public ContainerInventoryScreen(ItemStack containerItem) {
4242
super(containerItem.getName());
4343
this.playerInventory = mc.player.getInventory();
4444
this.tooltipContext = Item.TooltipContext.create(mc.world);
45-
45+
4646
this.containerItems = new ArrayList<>();
4747
if (containerItem.getItem() instanceof BundleItem) {
4848
BundleContentsComponent bundleContents = containerItem.get(DataComponentTypes.BUNDLE_CONTENTS);
@@ -58,7 +58,7 @@ public ContainerInventoryScreen(ItemStack containerItem) {
5858
}
5959
}
6060
}
61-
61+
6262
this.containerRows = Math.max(1, (containerItems.size() + 8) / 9);
6363
}
6464

@@ -72,18 +72,18 @@ protected void init() {
7272
@Override
7373
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
7474
super.render(context, mouseX, mouseY, delta);
75-
75+
7676
int baseX = x + 8;
7777
int baseY = y + 18;
7878
int playerY = baseY + containerRows * SLOT_SIZE + 20;
79-
79+
8080
for (int row = 0; row < containerRows + 4; row++) {
8181
for (int col = 0; col < 9; col++) {
8282
int slotY = row < containerRows ? baseY + row * SLOT_SIZE : playerY + (row - containerRows) * SLOT_SIZE;
8383
context.drawGuiTexture(RenderPipelines.GUI_TEXTURED, SLOT_TEXTURE, baseX + col * SLOT_SIZE, slotY, SLOT_SIZE, SLOT_SIZE);
8484
}
8585
}
86-
86+
8787
for (int i = 0; i < containerItems.size(); i++) {
8888
ItemStack item = containerItems.get(i);
8989
if (!item.isEmpty()) {
@@ -93,7 +93,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
9393
context.drawStackOverlay(textRenderer, item, itemX, itemY);
9494
}
9595
}
96-
96+
9797
for (int row = 0; row < 4; row++) {
9898
for (int col = 0; col < 9; col++) {
9999
int slotIndex = row < 3 ? 9 + row * 9 + col : col;
@@ -106,18 +106,18 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
106106
}
107107
}
108108
}
109-
109+
110110
context.getMatrices().pushMatrix();
111111
context.getMatrices().translate((float)x, (float)y);
112112
if (textRenderer != null) {
113113
context.drawText(textRenderer, title != null && !title.getString().isEmpty() ? title : Text.literal("Container"), 8, 6, -12566464, false);
114114
context.drawText(textRenderer, playerInventory.getDisplayName(), 8, 18 + containerRows * SLOT_SIZE + 10, -12566464, false);
115115
}
116116
context.getMatrices().popMatrix();
117-
117+
118118
if (mouseX >= baseX && mouseX < baseX + 9 * SLOT_SIZE) {
119119
int col = (mouseX - baseX) / SLOT_SIZE;
120-
120+
121121
if (mouseY >= baseY && mouseY < baseY + containerRows * SLOT_SIZE) {
122122
int index = ((mouseY - baseY) / SLOT_SIZE) * 9 + col;
123123
if (index < containerItems.size()) {
@@ -138,5 +138,4 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
138138
}
139139
}
140140
}
141-
142-
}
141+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
3+
* Copyright (c) Meteor Development.
4+
*/
5+
6+
package meteordevelopment.meteorclient.mixin;
7+
8+
import meteordevelopment.meteorclient.MeteorClient;
9+
import meteordevelopment.meteorclient.events.render.TooltipDataEvent;
10+
import net.minecraft.item.BundleItem;
11+
import net.minecraft.item.ItemStack;
12+
import net.minecraft.item.tooltip.TooltipData;
13+
import org.spongepowered.asm.mixin.Mixin;
14+
import org.spongepowered.asm.mixin.injection.At;
15+
import org.spongepowered.asm.mixin.injection.Inject;
16+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
17+
18+
import java.util.Optional;
19+
20+
@Mixin(BundleItem.class)
21+
public class BundleItemMixin {
22+
@Inject(method = "getTooltipData", at = @At("HEAD"), cancellable = true)
23+
private void onTooltipData(ItemStack stack, CallbackInfoReturnable<Optional<TooltipData>> cir) {
24+
TooltipDataEvent event = MeteorClient.EVENT_BUS.post(TooltipDataEvent.get(stack));
25+
if (event.tooltipData != null) {
26+
cir.setReturnValue(Optional.of(event.tooltipData));
27+
}
28+
}
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
3+
* Copyright (c) Meteor Development.
4+
*/
5+
6+
package meteordevelopment.meteorclient.mixin;
7+
8+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
9+
import meteordevelopment.meteorclient.systems.modules.Modules;
10+
import meteordevelopment.meteorclient.systems.modules.misc.InventoryTweaks;
11+
import net.minecraft.client.gui.tooltip.BundleTooltipSubmenuHandler;
12+
import net.minecraft.component.DataComponentTypes;
13+
import net.minecraft.component.type.BundleContentsComponent;
14+
import net.minecraft.item.ItemStack;
15+
import org.spongepowered.asm.mixin.Mixin;
16+
import org.spongepowered.asm.mixin.injection.At;
17+
18+
@Mixin(BundleTooltipSubmenuHandler.class)
19+
public class BundleTooltipSubmenuHandlerMixin {
20+
@ModifyExpressionValue(method = "sendPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BundleItem;getNumberOfStacksShown(Lnet/minecraft/item/ItemStack;)I"))
21+
private int uncapBundleScrolling1(int original, ItemStack item, int slotId, int selectedItemIndex) {
22+
if (Modules.get().get(InventoryTweaks.class).uncapBundleScrolling()) return item.getOrDefault(DataComponentTypes.BUNDLE_CONTENTS, BundleContentsComponent.DEFAULT).size();
23+
return original;
24+
}
25+
26+
@ModifyExpressionValue(method = "onScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BundleItem;getNumberOfStacksShown(Lnet/minecraft/item/ItemStack;)I"))
27+
private int uncapBundleScrolling2(int original, double horizontal, double vertical, int slotId, ItemStack item) {
28+
if (Modules.get().get(InventoryTweaks.class).uncapBundleScrolling()) return item.getOrDefault(DataComponentTypes.BUNDLE_CONTENTS, BundleContentsComponent.DEFAULT).size();
29+
return original;
30+
}
31+
}

src/main/java/meteordevelopment/meteorclient/mixin/HandledScreenMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private void mouseClicked(double mouseX, double mouseY, int button, CallbackInfo
9999
BetterTooltips tooltips = Modules.get().get(BetterTooltips.class);
100100

101101
if (tooltips.middleClickOpen() && tooltips.middleClickKey().matches(false, button, 0) && focusedSlot != null && !focusedSlot.getStack().isEmpty() && getScreenHandler().getCursorStack().isEmpty()) {
102-
if (tooltips.openContent(focusedSlot.getStack())) {
102+
if (tooltips.openContent(focusedSlot.getStack(), ITEMS)) {
103103
cir.setReturnValue(true);
104104
}
105105
}
@@ -111,7 +111,7 @@ private void keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoRe
111111
BetterTooltips tooltips = Modules.get().get(BetterTooltips.class);
112112

113113
if (tooltips.middleClickOpen() && tooltips.middleClickKey().matches(true, keyCode, modifiers) && focusedSlot != null && !focusedSlot.getStack().isEmpty() && getScreenHandler().getCursorStack().isEmpty()) {
114-
if (tooltips.openContent(focusedSlot.getStack())) {
114+
if (tooltips.openContent(focusedSlot.getStack(), ITEMS)) {
115115
cir.setReturnValue(true);
116116
}
117117
}

src/main/java/meteordevelopment/meteorclient/mixin/ItemMixin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import meteordevelopment.meteorclient.MeteorClient;
99
import meteordevelopment.meteorclient.events.render.TooltipDataEvent;
10-
1110
import net.minecraft.item.Item;
1211
import net.minecraft.item.ItemStack;
1312
import net.minecraft.item.tooltip.TooltipData;
@@ -20,7 +19,7 @@
2019

2120
@Mixin(Item.class)
2221
public abstract class ItemMixin {
23-
@Inject(method = "getTooltipData", at=@At("HEAD"), cancellable = true)
22+
@Inject(method = "getTooltipData", at = @At("HEAD"), cancellable = true)
2423
private void onTooltipData(ItemStack stack, CallbackInfoReturnable<Optional<TooltipData>> cir) {
2524
TooltipDataEvent event = MeteorClient.EVENT_BUS.post(TooltipDataEvent.get(stack));
2625
if (event.tooltipData != null) {

src/main/java/meteordevelopment/meteorclient/mixin/ItemStackMixin.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
import meteordevelopment.meteorclient.events.entity.player.FinishUsingItemEvent;
1111
import meteordevelopment.meteorclient.events.entity.player.StoppedUsingItemEvent;
1212
import meteordevelopment.meteorclient.events.game.ItemStackTooltipEvent;
13-
import meteordevelopment.meteorclient.events.render.TooltipDataEvent;
1413
import meteordevelopment.meteorclient.utils.Utils;
1514
import net.minecraft.entity.LivingEntity;
1615
import net.minecraft.item.ItemStack;
17-
import net.minecraft.item.Items;
18-
import net.minecraft.item.tooltip.TooltipData;
1916
import net.minecraft.text.Text;
2017
import net.minecraft.world.World;
2118
import org.spongepowered.asm.mixin.Mixin;
@@ -25,7 +22,6 @@
2522
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
2623

2724
import java.util.List;
28-
import java.util.Optional;
2925

3026
import static meteordevelopment.meteorclient.MeteorClient.mc;
3127

@@ -41,20 +37,6 @@ private List<Text> onGetTooltip(List<Text> original) {
4137
return original;
4238
}
4339

44-
@ModifyReturnValue(method = "getTooltipData", at = @At("RETURN"))
45-
private Optional<TooltipData> onGetTooltipData(Optional<TooltipData> original) {
46-
ItemStack stack = (ItemStack) (Object) this;
47-
48-
if (stack.getItem() instanceof net.minecraft.item.BundleItem) {
49-
TooltipDataEvent event = MeteorClient.EVENT_BUS.post(TooltipDataEvent.get(stack));
50-
if (event.tooltipData != null) {
51-
return Optional.of(event.tooltipData);
52-
}
53-
}
54-
55-
return original;
56-
}
57-
5840
@Inject(method = "finishUsing", at = @At("HEAD"))
5941
private void onFinishUsing(World world, LivingEntity user, CallbackInfoReturnable<ItemStack> info) {
6042
if (user == mc.player) {

src/main/java/meteordevelopment/meteorclient/systems/modules/misc/InventoryTweaks.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ public class InventoryTweaks extends Module {
104104
.build()
105105
);
106106

107+
private final Setting<Boolean> uncapBundleScrolling = sgGeneral.add(new BoolSetting.Builder()
108+
.name("uncap-bundle-scrolling")
109+
.description("Whether to uncap the bundle scrolling feature to let you select any item.")
110+
.defaultValue(true)
111+
.build()
112+
);
113+
107114
// Anti drop
108115

109116
private final Setting<List<Item>> antiDropItems = sgAntiDrop.add(new ItemListSetting.Builder()
@@ -452,6 +459,10 @@ public boolean mouseDragItemMove() {
452459
return isActive() && mouseDragItemMove.get();
453460
}
454461

462+
public boolean uncapBundleScrolling() {
463+
return isActive() && uncapBundleScrolling.get();
464+
}
465+
455466
public boolean canSteal(ScreenHandler handler) {
456467
try {
457468
return (stealScreens.get().contains(handler.getType()));

src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import meteordevelopment.meteorclient.utils.render.color.Color;
2424
import meteordevelopment.meteorclient.utils.tooltip.*;
2525
import meteordevelopment.orbit.EventHandler;
26-
2726
import net.minecraft.client.gui.screen.ingame.BookScreen;
2827
import net.minecraft.client.gui.screen.ingame.HandledScreen;
2928
import net.minecraft.component.DataComponentTypes;
@@ -90,7 +89,7 @@ public class BetterTooltips extends Module {
9089
.name("middle-click-key")
9190
.description("Key to open contents (containers, books, etc.) when pressed on items.")
9291
.defaultValue(Keybind.fromButton(GLFW_MOUSE_BUTTON_MIDDLE))
93-
.visible(() -> middleClickOpen.get())
92+
.visible(middleClickOpen::get)
9493
.build()
9594
);
9695

@@ -269,7 +268,7 @@ private void appendTooltip(ItemStackTooltipEvent event) {
269268
if (foodInfo.get() && event.itemStack().contains(DataComponentTypes.FOOD)) {
270269
FoodComponent food = event.itemStack().get(DataComponentTypes.FOOD);
271270
// Those emojis really look like in-game hunger bar
272-
event.appendStart(Text.literal(String.format("🍖 %d hunger (💛 %.1f saturation)", food.nutrition(), food.saturation())).formatted(Formatting.GRAY));
271+
event.appendStart(Text.literal(String.format("🍖 %d (💛 %.1f)", food.nutrition(), food.saturation())).formatted(Formatting.GRAY));
273272
}
274273

275274
// Item size tooltip
@@ -305,7 +304,6 @@ private void appendTooltip(ItemStackTooltipEvent event) {
305304
}
306305
}
307306

308-
309307
// Hold to preview tooltip
310308
appendPreviewTooltipText(event, true);
311309
}
@@ -380,7 +378,7 @@ else if (event.itemStack.getItem() instanceof BundleItem && previewBundles()) {
380378
for (ItemStack stack : bundleContents.iterate()) {
381379
bundleItems[index++] = stack;
382380
}
383-
event.tooltipData = new BundleTooltipComponent(bundleItems, bundleContents, new Color(139, 69, 19, 255));
381+
event.tooltipData = new BundleTooltipComponent(bundleItems, bundleContents);
384382
}
385383
}
386384
}
@@ -487,20 +485,18 @@ public Keybind middleClickKey() {
487485
return middleClickKey.get();
488486
}
489487

490-
public boolean openContent(ItemStack itemStack) {
488+
public boolean openContent(ItemStack itemStack, ItemStack[] contents) {
491489
if (!middleClickOpen() || itemStack.isEmpty()) return false;
492490

493491
if (itemStack.getItem() instanceof BundleItem) {
494-
if (mc.currentScreen instanceof HandledScreen)
495-
mc.currentScreen.close();
492+
if (mc.currentScreen instanceof HandledScreen) mc.currentScreen.close();
496493
mc.setScreen(new ContainerInventoryScreen(itemStack));
497494
return true;
498495
} else if (Utils.hasItems(itemStack) || itemStack.getItem() == Items.ENDER_CHEST) {
499-
Utils.openContainer(itemStack, ITEMS, false);
496+
Utils.openContainer(itemStack, contents, false);
500497
return true;
501498
} else if (itemStack.getItem() == Items.WRITABLE_BOOK || itemStack.getItem() == Items.WRITTEN_BOOK) {
502-
if (mc.currentScreen instanceof HandledScreen)
503-
mc.currentScreen.close();
499+
if (mc.currentScreen instanceof HandledScreen) mc.currentScreen.close();
504500
mc.setScreen(new BookScreen(BookScreen.Contents.create(itemStack)));
505501
return true;
506502
}
@@ -536,7 +532,7 @@ private boolean previewEntities() {
536532
return isPressed() && entitiesInBuckets.get();
537533
}
538534

539-
private boolean previewBundles() {
535+
public boolean previewBundles() {
540536
return isPressed() && bundles.get();
541537
}
542538

src/main/java/meteordevelopment/meteorclient/utils/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ else if (components.contains(DataComponentTypes.BLOCK_ENTITY_DATA)) {
283283
if (slot.get() >= 0 && slot.get() < items.length) {
284284
switch (StackWithSlot.CODEC.parse(mc.player.getRegistryManager().getOps(NbtOps.INSTANCE), compound.get())) {
285285
case DataResult.Success<StackWithSlot> success -> items[slot.get()] = success.value().stack();
286-
case DataResult.Error<StackWithSlot> error -> items[slot.get()] = ItemStack.EMPTY;
286+
case DataResult.Error<StackWithSlot> ignored -> items[slot.get()] = ItemStack.EMPTY;
287287
default -> throw new MatchException(null, null);
288288
}
289289
}

src/main/java/meteordevelopment/meteorclient/utils/render/PeekScreen.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
3838

3939
if (tooltips.middleClickOpen() && tooltips.middleClickKey().matches(false, button, 0) && focusedSlot != null && !focusedSlot.getStack().isEmpty() && mc.player.currentScreenHandler.getCursorStack().isEmpty()) {
4040
ItemStack itemStack = focusedSlot.getStack();
41-
if (tooltips.openContent(itemStack)) {
42-
return true;
43-
}
41+
return tooltips.openContent(itemStack, contents);
4442
}
4543

4644
return false;
@@ -57,7 +55,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
5755

5856
if (tooltips.middleClickOpen() && tooltips.middleClickKey().matches(true, keyCode, modifiers) && focusedSlot != null && !focusedSlot.getStack().isEmpty() && mc.player.currentScreenHandler.getCursorStack().isEmpty()) {
5957
ItemStack itemStack = focusedSlot.getStack();
60-
if (tooltips.openContent(itemStack)) {
58+
if (tooltips.openContent(itemStack, contents)) {
6159
return true;
6260
}
6361
}
@@ -66,6 +64,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
6664
close();
6765
return true;
6866
}
67+
6968
return false;
7069
}
7170

@@ -84,6 +83,6 @@ protected void drawBackground(DrawContext context, float delta, int mouseX, int
8483

8584
int i = (width - backgroundWidth) / 2;
8685
int j = (height - backgroundHeight) / 2;
87-
context.drawTexture(RenderPipelines.GUI_TEXTURED, TEXTURE, i, j, 0f, 0f, backgroundWidth, backgroundHeight, backgroundWidth, backgroundHeight, 256, 256, ColorHelper.fromFloats(color.r / 255f, color.g / 255f, color.b / 255f, color.a / 255f));
86+
context.drawTexture(RenderPipelines.GUI_TEXTURED, TEXTURE, i, j, 0f, 0f, backgroundWidth, backgroundHeight, backgroundWidth, backgroundHeight, 256, 256, ColorHelper.fromFloats(color.a / 255f, color.r / 255f, color.g / 255f, color.b / 255f));
8887
}
8988
}

0 commit comments

Comments
 (0)