diff options
| author | Yasin <19829407+LifeIsAParadox@users.noreply.github.com> | 2025-06-23 06:39:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-23 00:39:35 -0400 |
| commit | 97d4244e5072d42e0e76f5229b500e2a478acfb0 (patch) | |
| tree | a80e31e8a0b4bf1fdf8afc963a8ce8d2ea454db3 /src/main/java | |
| parent | 37436e08c3e6c880c251259cb9618d488de1ee9b (diff) | |
| download | Skyblocker-97d4244e5072d42e0e76f5229b500e2a478acfb0.tar.gz Skyblocker-97d4244e5072d42e0e76f5229b500e2a478acfb0.tar.bz2 Skyblocker-97d4244e5072d42e0e76f5229b500e2a478acfb0.zip | |
Small Fixes and Recipe Book Search Persistence (#1276)
* Update build.gradle
fix gradle error
* Update gradle.properties
fix modmenu error
* Update SkyblockRecipeBookWidget.java
recipe book dont forget
* Update ItemProtection.java
only block protected items to be placed into item frame while in private island and garden
* Update PartyFinderScreen.java
debug button only in debugging mode
---------
Co-authored-by: Aaron <51387595+AzureAaron@users.noreply.github.com>
Diffstat (limited to 'src/main/java')
3 files changed, 53 insertions, 34 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyFinderScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyFinderScreen.java index d2cfeac2..4b372558 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyFinderScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyFinderScreen.java @@ -5,6 +5,7 @@ import com.mojang.authlib.properties.PropertyMap; import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.annotations.Init; +import de.hysky.skyblocker.debug.Debug; import de.hysky.skyblocker.utils.ItemUtils; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; import net.minecraft.block.entity.SignBlockEntity; @@ -221,7 +222,9 @@ public class PartyFinderScreen extends Screen { addDrawableChild(settingsButton); addDrawableChild(createPartyButton); addDrawableChild(settingsContainer); - addDrawableChild(ButtonWidget.builder(Text.of("DEBUG"), (a) -> DEBUG = !DEBUG).dimensions(width - 40, 0, 40, 20).build()); + if (Debug.debugEnabled()) { + addDrawableChild(ButtonWidget.builder(Text.of("DEBUG"), (a) -> DEBUG = !DEBUG).dimensions(width - 40, 0, 40, 20).build()); + } dirtiedTime = System.currentTimeMillis(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/ItemProtection.java b/src/main/java/de/hysky/skyblocker/skyblock/item/ItemProtection.java index fcf2ae61..c691cc56 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/ItemProtection.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/ItemProtection.java @@ -2,12 +2,12 @@ package de.hysky.skyblocker.skyblock.item; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; - import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.annotations.Init; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.ItemUtils; +import de.hysky.skyblocker.utils.Location; import de.hysky.skyblocker.utils.Utils; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; @@ -27,7 +27,6 @@ import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; - import net.minecraft.util.hit.EntityHitResult; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; @@ -50,8 +49,8 @@ public class ItemProtection { public static boolean isItemProtected(ItemStack stack) { if (stack == null) return false; - String itemUuid = ItemUtils.getItemUuid(stack); - return SkyblockerConfigManager.get().general.protectedItems.contains(itemUuid); + String itemUuid = ItemUtils.getItemUuid(stack); + return SkyblockerConfigManager.get().general.protectedItems.contains(itemUuid); } private static void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) { @@ -92,7 +91,7 @@ public class ItemProtection { public static void handleKeyPressed(ItemStack heldItem) { PlayerEntity playerEntity = MinecraftClient.getInstance().player; - if (playerEntity == null){ + if (playerEntity == null) { return; } if (!Utils.isOnSkyblock()) { @@ -100,10 +99,10 @@ public class ItemProtection { return; } - if (heldItem.isEmpty()) { + if (heldItem.isEmpty()) { playerEntity.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.itemProtection.noItemUuid")), false); - return; - } + return; + } String itemUuid = ItemUtils.getItemUuid(heldItem); if (!itemUuid.isEmpty()) { @@ -134,6 +133,11 @@ public class ItemProtection { private static ActionResult onEntityInteract(PlayerEntity playerEntity, World world, Hand hand, Entity entity, @Nullable EntityHitResult entityHitResult) { if (!Utils.isOnSkyblock() || !world.isClient) return ActionResult.PASS; + + Location location = Utils.getLocation(); + if (!(location == Location.PRIVATE_ISLAND || location == Location.GARDEN)) { + return ActionResult.PASS; + } if (entity instanceof ItemFrameEntity itemFrame && itemFrame.getHeldItemStack().isEmpty()) { if (isItemProtected(playerEntity.getStackInHand(hand)) || HotbarSlotLock.isLocked(playerEntity.getInventory().getSelectedSlot())) { return ActionResult.FAIL; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/recipebook/SkyblockRecipeBookWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/recipebook/SkyblockRecipeBookWidget.java index adc9993b..680af462 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/recipebook/SkyblockRecipeBookWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/recipebook/SkyblockRecipeBookWidget.java @@ -1,15 +1,8 @@ package de.hysky.skyblocker.skyblock.itemlist.recipebook; -import java.util.List; -import java.util.Locale; - -import de.hysky.skyblocker.utils.render.gui.CyclingTextureWidget; -import net.minecraft.screen.ScreenHandler; -import org.jetbrains.annotations.Nullable; - import com.google.common.collect.Lists; - import de.hysky.skyblocker.mixins.accessors.RecipeBookWidgetAccessor; +import de.hysky.skyblocker.utils.render.gui.CyclingTextureWidget; import it.unimi.dsi.fastutil.Pair; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; @@ -23,9 +16,14 @@ import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.render.RenderLayer; import net.minecraft.recipe.RecipeFinder; import net.minecraft.recipe.display.RecipeDisplay; +import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; import net.minecraft.util.context.ContextParameterMap; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Locale; /** * Based on {@link net.minecraft.client.gui.screen.recipebook.RecipeBookWidget}. @@ -38,13 +36,14 @@ public class SkyblockRecipeBookWidget extends RecipeBookWidget<NoopRecipeScreenH // 81 is the search field's width, 4 is the space between it and the toggle crafting button, and 26 is the toggle crafting button's width, which we replace // with the filtering button. 26 - 14 - 4 = 12 - 4 = 8 (The additional space left to the search field.) private static final int SEARCH_FIELD_WIDTH = 81 + 4 + 8; + private static String lastSearch = ""; /** * The tabs in the Skyblock recipe book. */ private final List<RecipeTab> tabs = List.of( new SkyblockCraftingTab(this, SkyblockCraftingTab.CRAFTING_TABLE, new SkyblockCraftingRecipeResults()), new UpcomingEventsTab() - ); + ); private final List<Pair<RecipeTab, SkyblockRecipeTabButton>> tabButtons = Lists.newArrayList(); private Pair<RecipeTab, SkyblockRecipeTabButton> currentTab; @@ -65,29 +64,41 @@ public class SkyblockRecipeBookWidget extends RecipeBookWidget<NoopRecipeScreenH int left = accessor().invokeGetLeft(); int top = accessor().invokeGetTop(); - //Init Search Field - String defaultSearchText = this.searchField != null ? this.searchField.getText() : ""; - this.searchField = new TextFieldWidget(this.client.textRenderer, left + 25, top + 13, SEARCH_FIELD_WIDTH, 9 + 5, Text.translatable("itemGroup.search")); - this.searchField.setMaxLength(60); //Set at 60 due to the longest Skyblock item name being 55 characters long + // Init Search Field only once + if (this.searchField == null) { + this.searchField = new TextFieldWidget(this.client.textRenderer, left + 25, top + 13, SEARCH_FIELD_WIDTH, 14, Text.translatable("itemGroup.search")); + this.searchField.setMaxLength(60); //Set at 60 due to the longest Skyblock item name being 55 characters long + this.searchField.setEditableColor(0xFFFFFF); + this.searchField.setText(lastSearch); + this.searchField.setPlaceholder(SEARCH_HINT_TEXT); + } + + this.searchField.setX(left + 25); + this.searchField.setY(top + 13); this.searchField.setVisible(true); - this.searchField.setEditableColor(0xFFFFFF); - this.searchField.setText(defaultSearchText); - this.searchField.setPlaceholder(SEARCH_HINT_TEXT); + //This field's name is misleading, the rectangle is actually the area of the magnifying glass icon rather than the entire search field this.searchFieldRect = ScreenRect.of(NavigationAxis.HORIZONTAL, left + 8, this.searchField.getY(), this.searchField.getX() - left, this.searchField.getHeight()); - this.filterOption = new CyclingTextureWidget<>(this.searchField.getRight() + 4, this.searchField.getY(), 14, 14, FilterOption.ALL); - this.filterOption.setCycleListener(this::refilterSearchResults); - this.filterOption.setTextSupplier(option -> Text.translatable("skyblocker.config.general.itemList.filter." + option.name().toLowerCase(Locale.ENGLISH))); + // Init filter option once + if (this.filterOption == null) { + this.filterOption = new CyclingTextureWidget<>(this.searchField.getRight() + 4, this.searchField.getY(), 14, 14, FilterOption.ALL); + this.filterOption.setCycleListener(this::refilterSearchResults); + this.filterOption.setTextSupplier(option -> Text.translatable("skyblocker.config.general.itemList.filter." + option.name().toLowerCase(Locale.ENGLISH))); + } + + // Always update position of filter option + this.filterOption.setX(this.searchField.getRight() + 4); + this.filterOption.setY(this.searchField.getY()); - //Setup Tabs + // Setup Tabs this.tabButtons.clear(); for (RecipeTab tab : this.tabs) { this.tabButtons.add(Pair.of(tab, new SkyblockRecipeTabButton(tab.icon()))); } - //Since we clear the tabs when this is called, if a tab is set we need to update the instance + // Since we clear the tabs when this is called, if a tab is set we need to update the instance if (this.currentTab != null) { this.currentTab = this.tabButtons.stream() .filter(button -> button.first().equals(this.currentTab.first())) @@ -95,18 +106,17 @@ public class SkyblockRecipeBookWidget extends RecipeBookWidget<NoopRecipeScreenH .orElse(null); } - //If there is no current tab, set it to the first one + // If there is no current tab, set it to the first one if (this.currentTab == null) { this.currentTab = this.tabButtons.getFirst(); } - //Set the current tab as toggled & refresh positions this.currentTab.right().setToggled(true); this.refreshTabButtons(false); - //Tab Init + // Tab Init this.currentTab.left().initialize(this.client, left, top); - this.currentTab.left().updateSearchResults(defaultSearchText, FilterOption.ALL); + this.currentTab.left().updateSearchResults(this.searchField.getText().toLowerCase(Locale.ENGLISH), this.filterOption.getCurrent()); } @Override @@ -204,6 +214,7 @@ public class SkyblockRecipeBookWidget extends RecipeBookWidget<NoopRecipeScreenH protected void refilterSearchResults(FilterOption filterOption) { assert this.searchField != null; + lastSearch = this.searchField.getText(); String query = this.searchField.getText().toLowerCase(Locale.ENGLISH); // Doesn't trigger the pirate speak check since the query wasn't changed. this.currentTab.left().updateSearchResults(query, filterOption, true); @@ -212,6 +223,7 @@ public class SkyblockRecipeBookWidget extends RecipeBookWidget<NoopRecipeScreenH @Override protected void refreshSearchResults() { assert this.searchField != null; + lastSearch = this.searchField.getText(); String query = this.searchField.getText().toLowerCase(Locale.ENGLISH); this.triggerPirateSpeakEasterEgg(query); |
