diff options
Diffstat (limited to 'src/main')
10 files changed, 284 insertions, 2 deletions
diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index 29678683..644e97f2 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -160,6 +160,9 @@ public class SkyblockerConfig { public boolean betterPartyFinder = true; @SerialEntry + public boolean fancyCraftingTable = true; + + @SerialEntry public boolean backpackPreviewWithoutShift = false; @SerialEntry diff --git a/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java index fe73a6a7..adcb27a1 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java @@ -42,6 +42,13 @@ public class GeneralCategory { .controller(ConfigUtils::createBooleanController) .build()) .option(Option.<Boolean>createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.general.fancyCraftingTable")) + .binding(defaults.general.fancyCraftingTable, + () -> config.general.fancyCraftingTable, + newValue -> config.general.fancyCraftingTable = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) + .option(Option.<Boolean>createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.general.backpackPreviewWithoutShift")) .binding(defaults.general.backpackPreviewWithoutShift, () -> config.general.backpackPreviewWithoutShift, diff --git a/src/main/java/de/hysky/skyblocker/mixin/HandledScreenProviderMixin.java b/src/main/java/de/hysky/skyblocker/mixin/HandledScreenProviderMixin.java index 94eb53a5..975c9c51 100644 --- a/src/main/java/de/hysky/skyblocker/mixin/HandledScreenProviderMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixin/HandledScreenProviderMixin.java @@ -3,6 +3,9 @@ package de.hysky.skyblocker.mixin; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.dungeon.partyfinder.PartyFinderScreen; +import de.hysky.skyblocker.skyblock.item.SkyblockCraftingTableScreenHandler; +import de.hysky.skyblocker.skyblock.item.SkyblockCraftingTableScreen; +import de.hysky.skyblocker.utils.Utils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ingame.HandledScreens; import net.minecraft.client.network.ClientPlayerEntity; @@ -19,11 +22,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public interface HandledScreenProviderMixin<T extends ScreenHandler> { @Inject(method = "open", at = @At("HEAD"), cancellable = true) default void skyblocker$open(Text name, ScreenHandlerType<T> type, MinecraftClient client, int id, CallbackInfo ci) { - if (!SkyblockerConfigManager.get().general.betterPartyFinder) return; ClientPlayerEntity player = client.player; if (player == null) return; + if (!Utils.isOnSkyblock()) return; T screenHandler = type.create(id, player.getInventory()); - if (screenHandler instanceof GenericContainerScreenHandler containerScreenHandler && PartyFinderScreen.possibleInventoryNames.contains(name.getString().toLowerCase())) { + if (SkyblockerConfigManager.get().general.betterPartyFinder && screenHandler instanceof GenericContainerScreenHandler containerScreenHandler && PartyFinderScreen.possibleInventoryNames.contains(name.getString().toLowerCase())) { if (client.currentScreen != null) { String lowerCase = client.currentScreen.getTitle().getString().toLowerCase(); if (lowerCase.contains("group builder")) return; @@ -42,6 +45,11 @@ public interface HandledScreenProviderMixin<T extends ScreenHandler> { } ci.cancel(); + } else if (SkyblockerConfigManager.get().general.fancyCraftingTable && screenHandler instanceof GenericContainerScreenHandler containerScreenHandler && name.getString().toLowerCase().contains("craft item")) { + SkyblockCraftingTableScreenHandler skyblockCraftingTableScreenHandler = new SkyblockCraftingTableScreenHandler(containerScreenHandler, player.getInventory()); + client.player.currentScreenHandler = skyblockCraftingTableScreenHandler; + client.setScreen(new SkyblockCraftingTableScreen(skyblockCraftingTableScreenHandler, player.getInventory(), Text.literal("Craft Item"))); + ci.cancel(); } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreen.java new file mode 100644 index 00000000..14ddb238 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreen.java @@ -0,0 +1,194 @@ +package de.hysky.skyblocker.skyblock.item; + +import de.hysky.skyblocker.SkyblockerMod; +import de.hysky.skyblocker.skyblock.itemlist.ItemListWidget; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.ButtonTextures; +import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget; +import net.minecraft.client.gui.tooltip.Tooltip; +import net.minecraft.client.gui.widget.TexturedButtonWidget; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.SimpleInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeEntry; +import net.minecraft.recipe.RecipeMatcher; +import net.minecraft.recipe.book.RecipeBookCategory; +import net.minecraft.screen.AbstractRecipeScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.screen.slot.Slot; +import net.minecraft.screen.slot.SlotActionType; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +public class SkyblockCraftingTableScreen extends HandledScreen<SkyblockCraftingTableScreenHandler> { + private static final Identifier TEXTURE = new Identifier("textures/gui/container/crafting_table.png"); + protected static final ButtonTextures MORE_CRAFTS_TEXTURES = new ButtonTextures( + new Identifier(SkyblockerMod.NAMESPACE, "quick_craft/more_button"), + new Identifier(SkyblockerMod.NAMESPACE, "quick_craft/more_button_disabled"), + new Identifier(SkyblockerMod.NAMESPACE, "quick_craft/more_button_highlighted") + ); + + protected static final Identifier QUICK_CRAFT = new Identifier(SkyblockerMod.NAMESPACE, "quick_craft/quick_craft_overlay"); + private final ItemListWidget recipeBook = new ItemListWidget(); + private boolean narrow; + private TexturedButtonWidget moreCraftsButton; + + public SkyblockCraftingTableScreen(SkyblockCraftingTableScreenHandler handler, PlayerInventory inventory, Text title) { + super(handler, inventory, title); + this.backgroundWidth += 22; + } + + @Override + protected void init() { + super.init(); + this.narrow = this.width < 379; + this.recipeBook.initialize(this.width, this.height, this.client, this.narrow, new DummyRecipeScreenHandler()); + this.x = this.recipeBook.findLeftEdge(this.width, this.backgroundWidth) + 11; + this.addDrawableChild(new TexturedButtonWidget(this.x + 5, this.height / 2 - 49, 20, 18, RecipeBookWidget.BUTTON_TEXTURES, button -> { + this.recipeBook.toggleOpen(); + this.x = this.recipeBook.findLeftEdge(this.width, this.backgroundWidth) + 11; + button.setPosition(this.x + 5, this.height / 2 - 49); + if (moreCraftsButton != null) moreCraftsButton.setPosition(this.x + 174, this.y + 62); + })); + moreCraftsButton = new TexturedButtonWidget(this.x + 174, y + 62, 16, 16, MORE_CRAFTS_TEXTURES, + button -> this.onMouseClick(handler.slots.get(26), handler.slots.get(26).id, 0, SlotActionType.PICKUP)); + moreCraftsButton.setTooltipDelay(250); + moreCraftsButton.setTooltip(Tooltip.of(Text.literal("More Crafts"))); + this.addDrawableChild(moreCraftsButton); + assert (client != null ? client.player : null) != null; + client.player.currentScreenHandler = handler; // recipe book replaces it with the Dummy one fucking DUMBASS + this.addSelectableChild(this.recipeBook); + this.setInitialFocus(this.recipeBook); + this.titleX = 29; + } + + @Override + public void handledScreenTick() { + super.handledScreenTick(); + this.recipeBook.update(); + if (moreCraftsButton == null) return; + ItemStack stack = handler.slots.get(26).getStack(); + moreCraftsButton.active = stack.isEmpty() || stack.isOf(Items.PLAYER_HEAD); + } + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + if (this.recipeBook.isOpen() && this.narrow) { + this.renderBackground(context, mouseX, mouseY, delta); + this.recipeBook.render(context, mouseX, mouseY, delta); + } else { + super.render(context, mouseX, mouseY, delta); + this.recipeBook.render(context, mouseX, mouseY, delta); + this.recipeBook.drawGhostSlots(context, this.x, this.y, true, delta); + } + this.drawMouseoverTooltip(context, mouseX, mouseY); + this.recipeBook.drawTooltip(context, this.x, this.y, mouseX, mouseY); + } + + + @Override + protected void drawSlot(DrawContext context, Slot slot) { + if (slot.id == 23 && slot.getStack().isOf(Items.BARRIER)) return; + super.drawSlot(context, slot); + } + + @Override + protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { + int i = this.x; + int j = (this.height - this.backgroundHeight) / 2; + context.drawTexture(TEXTURE, i, j, 0, 0, this.backgroundWidth, this.backgroundHeight); + context.drawGuiTexture(QUICK_CRAFT, i + 173, j, 0, 25, 84); + } + + @Override + protected boolean isPointWithinBounds(int x, int y, int width, int height, double pointX, double pointY) { + return (!this.narrow || !this.recipeBook.isOpen()) && super.isPointWithinBounds(x, y, width, height, pointX, pointY); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (this.recipeBook.mouseClicked(mouseX, mouseY, button)) { + this.setFocused(this.recipeBook); + return true; + } + if (this.narrow && this.recipeBook.isOpen()) { + return true; + } + return super.mouseClicked(mouseX, mouseY, button); + } + + @Override + protected boolean isClickOutsideBounds(double mouseX, double mouseY, int left, int top, int button) { + boolean bl = mouseX < (double) left || mouseY < (double) top || mouseX >= (double) (left + this.backgroundWidth) || mouseY >= (double) (top + this.backgroundHeight); + return this.recipeBook.isClickOutsideBounds(mouseX, mouseY, this.x, this.y, this.backgroundWidth, this.backgroundHeight, button) && bl; + } + + @Override + protected void onMouseClick(Slot slot, int slotId, int button, SlotActionType actionType) { + super.onMouseClick(slot, slotId, button, actionType); + this.recipeBook.slotClicked(slot); + } + + + static class DummyRecipeScreenHandler extends AbstractRecipeScreenHandler<SimpleInventory> { + + public DummyRecipeScreenHandler() { + super(ScreenHandlerType.GENERIC_9X6, -69); + } + + @Override + public void populateRecipeFinder(RecipeMatcher finder) {} + + @Override + public void clearCraftingSlots() {} + + @Override + public boolean matches(RecipeEntry<? extends Recipe<SimpleInventory>> recipe) { + return false; + } + + @Override + public int getCraftingResultSlotIndex() { + return 0; + } + + @Override + public int getCraftingWidth() { + return 0; + } + + @Override + public int getCraftingHeight() { + return 0; + } + + @Override + public int getCraftingSlotCount() { + return 0; + } + + @Override + public RecipeBookCategory getCategory() { + return RecipeBookCategory.CRAFTING; + } + + @Override + public boolean canInsertIntoSlot(int index) { + return false; + } + + @Override + public ItemStack quickMove(PlayerEntity player, int slot) { + return ItemStack.EMPTY; + } + + @Override + public boolean canUse(PlayerEntity player) { + return false; + } + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreenHandler.java b/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreenHandler.java new file mode 100644 index 00000000..04974ade --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreenHandler.java @@ -0,0 +1,69 @@ +package de.hysky.skyblocker.skyblock.item; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.Inventory; +import net.minecraft.screen.GenericContainerScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.screen.slot.Slot; + +import java.util.Arrays; + +public class SkyblockCraftingTableScreenHandler extends GenericContainerScreenHandler { + + private static final int[] normalSlots = new int[]{ + 10, 11, 12, 16, + 19, 20, 21, 23, 25, + 28, 29, 30, 34 + }; + + public SkyblockCraftingTableScreenHandler(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, Inventory inventory, int rows) { + super(type, syncId, playerInventory, inventory, rows); + for (int i = 0; i < rows * 9; i++) { + Slot originalSlot = slots.get(i); + if (Arrays.binarySearch(normalSlots, i) >= 0) { + int[] coords = getCoords(i); + Slot slot = new Slot(originalSlot.inventory, originalSlot.getIndex(), coords[0], coords[1]); + slot.id = i; + slots.set(i, slot); + } else { + DisabledSlot slot = new DisabledSlot(originalSlot.inventory, originalSlot.getIndex(), originalSlot.x, originalSlot.y); + slot.id = i; + slots.set(i, slot); + } + } + int yOffset = (rows - 4) * 18 + 19; + for (int i = rows * 9; i < slots.size(); i++) { + Slot originalSlot = slots.get(i); + Slot slot = new Slot(originalSlot.inventory, originalSlot.getIndex(), originalSlot.x, originalSlot.y - yOffset); + slot.id = i; + slots.set(i, slot); + } + } + + public SkyblockCraftingTableScreenHandler(GenericContainerScreenHandler handler, PlayerInventory playerInventory) { + this(handler.getType(), handler.syncId, playerInventory, handler.getInventory(), handler.getRows()); + } + + private int[] getCoords(int slot) { + if (slot == 23) return new int[]{124, 35}; + if (slot == 16 || slot == 25 || slot == 34) { + int y = (slot / 9 - 1) * 18 + 8; + return new int[]{174, y}; + } + int gridX = slot % 9 - 1; + int gridY = slot / 9 - 1; + return new int[]{30 + gridX * 18, 17 + gridY * 18}; + } + + public static class DisabledSlot extends Slot { + + public DisabledSlot(Inventory inventory, int index, int x, int y) { + super(inventory, index, x, y); + } + + @Override + public boolean isEnabled() { + return false; + } + } +} diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index dd44b8fe..9ed5e4d0 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -154,6 +154,7 @@ "text.autoconfig.skyblocker.option.general.searchOverlay.enableCommands.@Tooltip": "Opens the bazaar search with \"/bzs\" and auction house with \"/ahs\". A re-log is required for this setting to be updated.", "text.autoconfig.skyblocker.option.general.searchOverlay.historyLabel": "History:", "text.autoconfig.skyblocker.option.general.betterPartyFinder": "Better Party Finder", + "text.autoconfig.skyblocker.option.general.fancyCraftingTable": "Fancy Crafting Table UI", "skyblocker.itemTooltip.nullMessage": "§cItem price information on tooltip will renew in max 60 seconds. If not, check latest.log", "skyblocker.itemTooltip.noData": "§cNo Data", diff --git a/src/main/resources/assets/skyblocker/textures/gui/sprites/quick_craft/more_button.png b/src/main/resources/assets/skyblocker/textures/gui/sprites/quick_craft/more_button.png Binary files differnew file mode 100644 index 00000000..7a6e3162 --- /dev/null +++ b/src/main/resources/assets/skyblocker/textures/gui/sprites/quick_craft/more_button.png diff --git a/src/main/resources/assets/skyblocker/textures/gui/sprites/quick_craft/more_button_disabled.png b/src/main/resources/assets/skyblocker/textures/gui/sprites/quick_craft/more_button_disabled.png Binary files differnew file mode 100644 index 00000000..02a22b4f --- /dev/null +++ b/src/main/resources/assets/skyblocker/textures/gui/sprites/quick_craft/more_button_disabled.png diff --git a/src/main/resources/assets/skyblocker/textures/gui/sprites/quick_craft/more_button_highlighted.png b/src/main/resources/assets/skyblocker/textures/gui/sprites/quick_craft/more_button_highlighted.png Binary files differnew file mode 100644 index 00000000..be41b321 --- /dev/null +++ b/src/main/resources/assets/skyblocker/textures/gui/sprites/quick_craft/more_button_highlighted.png diff --git a/src/main/resources/assets/skyblocker/textures/gui/sprites/quick_craft/quick_craft_overlay.png b/src/main/resources/assets/skyblocker/textures/gui/sprites/quick_craft/quick_craft_overlay.png Binary files differnew file mode 100644 index 00000000..d8cf0c2b --- /dev/null +++ b/src/main/resources/assets/skyblocker/textures/gui/sprites/quick_craft/quick_craft_overlay.png |