diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2022-11-08 12:03:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-08 12:03:58 +0100 |
commit | 1773ed4e9e58f1851796f2a9a6af1f93618b89ef (patch) | |
tree | 2c2b10fdca453d343556ad9d6666fd8ae39e866f /src/main/java/io | |
parent | 3075fb0e8438a9ab701ddbef0eba75064b475f6f (diff) | |
download | NotEnoughUpdates-1773ed4e9e58f1851796f2a9a6af1f93618b89ef.tar.gz NotEnoughUpdates-1773ed4e9e58f1851796f2a9a6af1f93618b89ef.tar.bz2 NotEnoughUpdates-1773ed4e9e58f1851796f2a9a6af1f93618b89ef.zip |
Abiphone favourites (#415)
* Added abiphone favourites.
* less empty lines
* getProfileSpecific cant be null
* Add support for using 'favourite item' keybind to toggle favourite contacts
* Use item instead of ugly panel highlight (thanks nea)
* no more random static methods, fixed profileSpecific errors (thanks nea)
* Better wording
* Less random gray out names
* F3+H support
* Allow calling non favourite contacts while in "all contacts" view
* Made the code sane + made it work with non removable contacts
* Made the code even more sane.
* This is a NEU feature and not made by hypixel
* Support for deleting contacts again, blocks this in favourite only mode. Support shift+right click to toggle favourites, ignored f3+h totally + made better looking lore order
* fixed click problems (thanks jani)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: nopo <nopotheemail@gmail.com>
Diffstat (limited to 'src/main/java/io')
8 files changed, 414 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 726acb32..8ea94615 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -36,6 +36,7 @@ import io.github.moulberry.notenoughupdates.listener.NEUEventListener; import io.github.moulberry.notenoughupdates.listener.OldAnimationChecker; import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.listener.WorldListener; +import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneFavourites; import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AntiCoopAdd; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning; @@ -338,6 +339,7 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(new GlowingMushroomHighlighter()); MinecraftForge.EVENT_BUS.register(new WorldListener(this)); MinecraftForge.EVENT_BUS.register(TitleUtil.getInstance()); + MinecraftForge.EVENT_BUS.register(AbiphoneFavourites.getInstance()); if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) { IReloadableResourceManager manager = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java index 2b14bfed..cedc12d7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java @@ -32,6 +32,7 @@ import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.Entity; +import net.minecraft.inventory.Slot; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumChatFormatting; @@ -517,4 +518,24 @@ public class RenderUtils { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.popMatrix(); } + + public static void highlightSlot(Slot slot, Color color) { + boolean lightingState = GL11.glIsEnabled(GL11.GL_LIGHTING); + + GlStateManager.disableLighting(); + GlStateManager.color(1f, 1f, 1f, 1f); + + GlStateManager.pushMatrix(); + GlStateManager.translate(0f, 0f, 110 + Minecraft.getMinecraft().getRenderItem().zLevel); + Gui.drawRect( + slot.xDisplayPosition, + slot.yDisplayPosition, + slot.xDisplayPosition + 16, + slot.yDisplayPosition + 16, + color.getRGB() + ); + GlStateManager.popMatrix(); + + if (lightingState) GlStateManager.enableLighting(); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/events/ReplaceItemEvent.java b/src/main/java/io/github/moulberry/notenoughupdates/events/ReplaceItemEvent.java new file mode 100644 index 00000000..2cdcf083 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/events/ReplaceItemEvent.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.events; + +import net.minecraft.inventory.InventoryBasic; +import net.minecraft.item.ItemStack; + +public class ReplaceItemEvent extends NEUEvent { + + final ItemStack original; + final InventoryBasic inventory; + final int slotNumber; + ItemStack replaceWith; + + public ReplaceItemEvent(ItemStack original, InventoryBasic inventory, int slotNumber) { + this.original = original; + this.inventory = inventory; + this.slotNumber = slotNumber; + this.replaceWith = original; + } + + public ItemStack getOriginal() { + return original; + } + + public InventoryBasic getInventory() { + return inventory; + } + + public int getSlotNumber() { + return slotNumber; + } + + public ItemStack getReplacement() { + return replaceWith; + } + + public void replaceWith(ItemStack is) { + this.replaceWith = is; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneFavourites.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneFavourites.java new file mode 100644 index 00000000..f3f83c30 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneFavourites.java @@ -0,0 +1,257 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.miscfeatures; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.config.KeybindHelper; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent; +import io.github.moulberry.notenoughupdates.events.SlotClickEvent; +import io.github.moulberry.notenoughupdates.options.NEUConfig; +import io.github.moulberry.notenoughupdates.util.ItemUtils; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IChatComponent; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +public class AbiphoneFavourites { + + private static final AbiphoneFavourites INSTANCE = new AbiphoneFavourites(); + private long lastClick = 0L; + + public static AbiphoneFavourites getInstance() { + return INSTANCE; + } + + private final ItemStack ITEM_STACK_FAVOURITE_ONLY = Utils.createItemStack( + Items.diamond, + "§6Show only favourite contacts", + "§7Non favourite contacts are hidden.", + "§7Only favourite contacts can be called.", + "§8This is a NEU feature and not made by hypixel.", + " ", + "§eClick to show all contacts!" + ); + private final ItemStack ITEM_STACK_ALL = Utils.createItemStack( + Items.emerald, + "§aShow all contacts", + "§7Favourite contacts are marked §6orange§7.", + "§7All contacts can be called.", + "§8This is a NEU feature and not made by hypixel.", + " ", + "§eClick to show only favourite contacts!" + ); + + @SubscribeEvent + public void onItemTooltip(ItemTooltipEvent event) { + if (isWrongInventory()) return; + + List<String> list = event.toolTip; + if (list == null) return; + if (list.isEmpty()) return; + + ItemStack stack = event.itemStack; + if (!isContact(stack)) return; + String rawName = stack.getDisplayName(); + String name = StringUtils.cleanColour(rawName); + + if (isAbiphoneShowOnlyFavourites()) { + if (!getFavouriteContacts().contains(name)) { + list.clear(); + return; + } + } + + if (isAbiphoneShowOnlyFavourites()) { + list.removeIf(s -> s.contains("§eRight-click to remove contact!")); + return; + } + + int index = list.indexOf("§5§o") + 1; + if (getFavouriteContacts().contains(name)) { + list.set(0, rawName + " §f- §6Favourite"); + list.add(index, "§eShift-click to remove from the favourites!"); + } else { + list.add(index, "§eShift-click to add to the favourites!"); + } + + if (KeybindHelper.isKeyPressed(NotEnoughUpdates.INSTANCE.manager.keybindFavourite.getKeyCode())) { + if (System.currentTimeMillis() > lastClick + 500) { + toggleFavouriteContact(rawName, name); + lastClick = System.currentTimeMillis(); + } + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) + public void onStackClick(SlotClickEvent event) { + if (isWrongInventory()) return; + + ItemStack stack = event.slot.getStack(); + if (stack == null || stack.getDisplayName() == null) return; + + if ((stack == ITEM_STACK_FAVOURITE_ONLY || stack == ITEM_STACK_ALL)) { + if (System.currentTimeMillis() > lastClick + 200) { + NEUConfig.HiddenProfileSpecific profileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); + if (profileSpecific != null) { + profileSpecific.abiphoneShowOnlyFavourites = + !isAbiphoneShowOnlyFavourites(); + lastClick = System.currentTimeMillis(); + } + } + event.setCanceled(true); + return; + } + + if (!isContact(stack)) return; + + int clickType = event.clickType; + int clickedButton = event.clickedButton; + + //allows removing the contact + if (clickType == 0 && clickedButton == 1) { + if (!isAbiphoneShowOnlyFavourites()) { + return; + } + } + String rawName = stack.getDisplayName(); + String name = StringUtils.cleanColour(rawName); + + //allows calling + if (clickType == 0 && clickedButton == 0) { + if (!isAbiphoneShowOnlyFavourites() || getFavouriteContacts().contains(name)) { + return; + } + } + + //toggle favourite contact + if (clickType == 1) { + if (!isAbiphoneShowOnlyFavourites()) { + toggleFavouriteContact(rawName, name); + } + } + + event.setCanceled(true); + } + + @SubscribeEvent + public void replaceItem(ReplaceItemEvent event) { + IChatComponent chatComponent = event.getInventory().getDisplayName(); + if (chatComponent == null || isWrongInventory()) return; + ItemStack original = event.getOriginal(); + if (original == null) return; + if (original.getItem() != Item.getItemFromBlock(Blocks.stained_glass_pane)) return; + + if (event.getSlotNumber() > 2 && event.getSlotNumber() < 6) { + event.replaceWith(isAbiphoneShowOnlyFavourites() ? ITEM_STACK_FAVOURITE_ONLY : ITEM_STACK_ALL); + } + } + + private void toggleFavouriteContact(String rawName, String name) { + if (getFavouriteContacts().contains(name)) { + getFavouriteContacts().remove(name); + Utils.addChatMessage("§e[NEU] Removed §r" + rawName + " §efrom your favourite contacts!"); + } else { + getFavouriteContacts().add(name); + Utils.addChatMessage("§e[NEU] Added §r" + rawName + " §eto your favourite contacts!"); + } + } + + public boolean onRenderStack(ItemStack stack) { + if (isWrongInventory()) return false; + + if (stack == null || stack.getDisplayName() == null) return false; + + if (!isContact(stack)) return false; + + String rawName = stack.getDisplayName(); + String name = StringUtils.cleanColour(rawName); + + return isAbiphoneShowOnlyFavourites() && !getFavouriteContacts().contains(name); + } + + public void onDrawBackground(GuiScreen screen) { + if (isWrongInventory()) return; + + GuiContainer container = (GuiContainer) screen; + + for (Slot slot : container.inventorySlots.inventorySlots) { + if (slot == null) continue; + ItemStack stack = slot.getStack(); + if (stack == null) continue; + + if (!isContact(stack)) continue; + + String rawName = stack.getDisplayName(); + String name = StringUtils.cleanColour(rawName); + + if (!isAbiphoneShowOnlyFavourites()) { + if (getFavouriteContacts().contains(name)) { + RenderUtils.highlightSlot(slot, Color.ORANGE); + } + } + } + } + + private boolean isWrongInventory() { + return !NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() + || !NotEnoughUpdates.INSTANCE.config.misc.abiphoneFavourites + || !Utils.getOpenChestName().startsWith("Abiphone "); + } + + private boolean isContact(ItemStack stack) { + for (String line : ItemUtils.getLore(stack)) { + if (line.equals("§eLeft-click to call!") || line.equals("§eClick to call!")) { + return true; + } + } + + return false; + } + + private List<String> getFavouriteContacts() { + NEUConfig.HiddenProfileSpecific profileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); + if (profileSpecific != null) { + return profileSpecific.abiphoneFavouriteContacts; + } + return new ArrayList<>(); + } + + private boolean isAbiphoneShowOnlyFavourites() { + NEUConfig.HiddenProfileSpecific profileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); + if (profileSpecific != null) { + return profileSpecific.abiphoneShowOnlyFavourites; + } + return false; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java index cb4cfa6c..91d92091 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java @@ -23,6 +23,7 @@ import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.listener.RenderListener; +import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneFavourites; import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionSortModeWarning; @@ -153,6 +154,10 @@ public abstract class MixinGuiContainer extends GuiScreen { ci.cancel(); return; } + if (AbiphoneFavourites.getInstance().onRenderStack(stack)) { + ci.cancel(); + return; + } } RenderHelper.enableGUIStandardItemLighting(); @@ -321,4 +326,9 @@ public abstract class MixinGuiContainer extends GuiScreen { ci.cancel(); } } + + @Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;color(FFFF)V", ordinal = 1)) + private void drawBackground(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { + AbiphoneFavourites.getInstance().onDrawBackground(this); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryBasic.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryBasic.java new file mode 100644 index 00000000..c290c12f --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryBasic.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.mixins; + +import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent; +import net.minecraft.inventory.InventoryBasic; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IChatComponent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(InventoryBasic.class) +public abstract class MixinInventoryBasic { + @Shadow + private ItemStack[] inventoryContents; + + @Shadow + public abstract IChatComponent getDisplayName(); + + @Inject(method = "getStackInSlot", at = @At("HEAD"), cancellable = true) + public void on(int index, CallbackInfoReturnable<ItemStack> cir) { + ReplaceItemEvent replaceItemEvent = new ReplaceItemEvent( + index >= 0 && index < this.inventoryContents.length ? this.inventoryContents[index] : null, + ((InventoryBasic) (Object) this), + index + ); + replaceItemEvent.post(); + if (replaceItemEvent.getReplacement() != replaceItemEvent.getOriginal()) { + cir.setReturnValue(replaceItemEvent.getReplacement()); + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index adbd52f1..f936ceb1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -571,6 +571,12 @@ public class NEUConfig extends Config { @Expose public int gemstonePowderFound = 0; + + @Expose + public List<String> abiphoneFavouriteContacts = new ArrayList<>(); + + @Expose + public boolean abiphoneShowOnlyFavourites = false; } public HiddenLocationSpecific getLocationSpecific() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java index dbf79bce..ce8325bb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java @@ -287,4 +287,12 @@ public class Misc { @ConfigEditorBoolean public boolean textFieldTweaksEnabled = true; + @Expose + @ConfigOption( + name = "Abiphone Favourites", + desc = "Allows to set abiphone contacts as favourites, toggle between displaying all contacts or favourites only and deactivates the option to remove contacts at all." + ) + @ConfigEditorBoolean + public boolean abiphoneFavourites = true; + } |