From 814899ac030f79032c5fc1c81d327715bd64ee81 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 1 Oct 2024 14:02:21 +0100 Subject: [PATCH] Store container on close --- .../chesttracker/CivChestTrackerPlugin.java | 76 +++++++++++++++- .../ContainerLocationDeciderScreen.java | 9 +- .../gui/widgets/ForgetContainerButton.java | 22 ----- .../gui/widgets/OpenedInventoryButtons.java | 81 +++++++++++++++++ .../gui/widgets/TrackContainerButton.java | 22 ----- .../chesttracker/mixing/InventoryWindow.java | 28 ++++++ .../mixins/InventoryContextButtonsMixin.java | 52 +++-------- ...owMixin.java => InventoryWindowMixin.java} | 21 ++++- .../SetBlockPositionBasedOnMemoryMixin.java | 82 ------------------ ...egisterDefaultChestTrackerPluginMixin.java | 17 ++++ .../DoNotRegisterHypixelProviderMixin.java | 26 ------ .../civ/chesttracker/utilities/Shortcuts.java | 43 ++++++--- .../assets/civchesttracker/lang/en_us.json | 8 +- .../textures/gui/sprites/cannot.png | Bin 0 -> 210 bytes .../gui/sprites/cannot_highlighted.png | Bin 0 -> 217 bytes .../textures/gui/sprites/unknown.png | Bin 0 -> 235 bytes .../gui/sprites/unknown_highlighted.png | Bin 0 -> 213 bytes .../resources/civchesttracker.mixins.json | 8 +- 18 files changed, 277 insertions(+), 218 deletions(-) delete mode 100644 src/main/java/uk/protonull/civ/chesttracker/gui/widgets/ForgetContainerButton.java create mode 100644 src/main/java/uk/protonull/civ/chesttracker/gui/widgets/OpenedInventoryButtons.java delete mode 100644 src/main/java/uk/protonull/civ/chesttracker/gui/widgets/TrackContainerButton.java rename src/main/java/uk/protonull/civ/chesttracker/mixins/{retention/RetainPlayerOnInventoryWindowMixin.java => InventoryWindowMixin.java} (65%) delete mode 100644 src/main/java/uk/protonull/civ/chesttracker/mixins/SetBlockPositionBasedOnMemoryMixin.java create mode 100644 src/main/java/uk/protonull/civ/chesttracker/mixins/cruft/DoNotRegisterDefaultChestTrackerPluginMixin.java delete mode 100644 src/main/java/uk/protonull/civ/chesttracker/mixins/cruft/DoNotRegisterHypixelProviderMixin.java create mode 100644 src/main/resources/assets/civchesttracker/textures/gui/sprites/cannot.png create mode 100644 src/main/resources/assets/civchesttracker/textures/gui/sprites/cannot_highlighted.png create mode 100644 src/main/resources/assets/civchesttracker/textures/gui/sprites/unknown.png create mode 100644 src/main/resources/assets/civchesttracker/textures/gui/sprites/unknown_highlighted.png diff --git a/src/main/java/uk/protonull/civ/chesttracker/CivChestTrackerPlugin.java b/src/main/java/uk/protonull/civ/chesttracker/CivChestTrackerPlugin.java index cef2787..37b6f07 100644 --- a/src/main/java/uk/protonull/civ/chesttracker/CivChestTrackerPlugin.java +++ b/src/main/java/uk/protonull/civ/chesttracker/CivChestTrackerPlugin.java @@ -1,5 +1,10 @@ package uk.protonull.civ.chesttracker; +import java.util.List; +import java.util.Optional; +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.components.CommonButtons; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.BeaconScreen; import net.minecraft.client.gui.screens.inventory.CartographyTableScreen; import net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen; @@ -8,18 +13,27 @@ import net.minecraft.client.gui.screens.inventory.ItemCombinerScreen; import net.minecraft.client.gui.screens.inventory.LoomScreen; import net.minecraft.client.gui.screens.inventory.StonecutterScreen; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; import red.jackf.chesttracker.api.ChestTrackerPlugin; import red.jackf.chesttracker.api.gui.ScreenBlacklist; +import red.jackf.chesttracker.api.memory.Memory; +import red.jackf.chesttracker.api.providers.MemoryLocation; import red.jackf.chesttracker.api.providers.ProviderUtils; import red.jackf.chesttracker.api.providers.ServerProvider; import red.jackf.chesttracker.api.providers.context.ScreenCloseContext; import red.jackf.chesttracker.api.providers.context.ScreenOpenContext; +import red.jackf.chesttracker.impl.memory.MemoryBankImpl; +import red.jackf.chesttracker.impl.memory.MemoryKeyImpl; import red.jackf.jackfredlib.client.api.gps.Coordinate; import uk.protonull.civ.chesttracker.gui.screens.ContainerLocationDeciderScreen; +import uk.protonull.civ.chesttracker.mixing.InventoryWindow; +import uk.protonull.civ.chesttracker.utilities.Shortcuts; public final class CivChestTrackerPlugin implements ChestTrackerPlugin { + public static final String ID = "civchesttracker"; + /** * Pretty heavily based on {@link red.jackf.chesttracker.impl.DefaultChestTrackerPlugin} */ @@ -53,6 +67,8 @@ public ResourceLocation id() { public boolean appliesTo( final @NotNull Coordinate coordinate ) { + CommonButtons lol; + return true; // Apply to singleplayer, multiplayer, etc } @@ -60,14 +76,68 @@ public boolean appliesTo( public void onScreenOpen( final @NotNull ScreenOpenContext context ) { - + final AbstractContainerScreen screen = context.getScreen(); + if (ScreenBlacklist.isBlacklisted(screen.getClass())) { + return; + } + final MemoryBankImpl serverStorage = Shortcuts.getChestTrackerStorage(); + if (serverStorage == null) { + return; + } + final ResourceLocation dimensionKey = Shortcuts.getDimensionKeyFromInventoryWindow(screen); + final MemoryKeyImpl dimensionStorage = serverStorage.getKeyInternal(dimensionKey).orElse(null); + if (dimensionStorage == null) { + return; + } + final Memory foundContainer = Shortcuts.destructivelyFindFirstContainerWithName( + dimensionStorage, + context.getScreen().getTitle() + ); + if (foundContainer == null) { + return; + } + InventoryWindow.setIdentifier(screen, MemoryLocation.inWorld( + dimensionKey, + Shortcuts.getMemoryLocation(foundContainer) + )); } @Override public void onScreenClose( - final ScreenCloseContext context + final @NotNull ScreenCloseContext context ) { - + final MemoryBankImpl serverStorage = Shortcuts.getChestTrackerStorage(); + if (serverStorage == null) { + return; + } + final MemoryLocation inventoryIdentifier = InventoryWindow.getIdentifier(context.getScreen()); + if (inventoryIdentifier == null) { + return; + } + final boolean alreadyExisted = serverStorage.getMemory(inventoryIdentifier).isPresent(); + final var memory = new Memory( + context.getItems(), + context.getTitle(), + List.of(), + Optional.empty(), + Memory.UNKNOWN_LOADED_TIMESTAMP, + Memory.UNKNOWN_WORLD_TIMESTAMP, + Memory.UNKNOWN_REAL_TIMESTAMP + ); + Shortcuts.setMemoryLocation(memory, inventoryIdentifier.position()); + serverStorage.addMemory( + inventoryIdentifier.memoryKey(), + inventoryIdentifier.position(), + memory + ); + Shortcuts.printMessage( + Component + .literal(alreadyExisted + ? "Updated inventory '" + context.getTitle().getString() + "'" + : "Now tracking inventory '" + context.getTitle().getString() + "'" + ) + .withStyle(ChatFormatting.GREEN) + ); } } } diff --git a/src/main/java/uk/protonull/civ/chesttracker/gui/screens/ContainerLocationDeciderScreen.java b/src/main/java/uk/protonull/civ/chesttracker/gui/screens/ContainerLocationDeciderScreen.java index 302774d..4aee637 100644 --- a/src/main/java/uk/protonull/civ/chesttracker/gui/screens/ContainerLocationDeciderScreen.java +++ b/src/main/java/uk/protonull/civ/chesttracker/gui/screens/ContainerLocationDeciderScreen.java @@ -17,6 +17,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import uk.protonull.civ.chesttracker.gui.widgets.TextRenderable; +import uk.protonull.civ.chesttracker.mixing.InventoryWindow; import uk.protonull.civ.chesttracker.utilities.Shortcuts; public class ContainerLocationDeciderScreen extends Screen { @@ -43,11 +44,11 @@ public ContainerLocationDeciderScreen( final @NotNull AbstractContainerScreen parent, final @NotNull Consumer<@NotNull BlockPos> setInventoryLocation ) { - super(Component.empty()); + super(Component.translatable("civchesttracker.picker.header")); this.parent = Objects.requireNonNull(parent); this.setInventoryLocation = Objects.requireNonNull(setInventoryLocation); { - final LocalPlayer player = Shortcuts.getPlayerFromInventoryWindow(parent); + final LocalPlayer player = InventoryWindow.getPlayer(parent); this.playerEyePosition = player.getEyePosition(); this.playerLookDirection = player.getLookAngle().normalize(); } @@ -60,7 +61,7 @@ protected void init() { this.font, this.width / 2, 20, - Component.literal("Where is this inventory?"), + Component.translatable("civchesttracker.picker.header"), PICKER_COLOUR_RBG )); @@ -69,7 +70,7 @@ protected void init() { this.height - 40 - Button.DEFAULT_HEIGHT, Button.DEFAULT_WIDTH, Button.DEFAULT_HEIGHT, - Component.literal("Confirm"), + Component.translatable("civchesttracker.picker.confirm"), (button) -> { final BlockPos blockPos = currentPickerLocation; if (blockPos != null) { diff --git a/src/main/java/uk/protonull/civ/chesttracker/gui/widgets/ForgetContainerButton.java b/src/main/java/uk/protonull/civ/chesttracker/gui/widgets/ForgetContainerButton.java deleted file mode 100644 index f6f5b94..0000000 --- a/src/main/java/uk/protonull/civ/chesttracker/gui/widgets/ForgetContainerButton.java +++ /dev/null @@ -1,22 +0,0 @@ -package uk.protonull.civ.chesttracker.gui.widgets; - -import java.util.Objects; -import net.minecraft.client.gui.components.WidgetSprites; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; -import red.jackf.chesttracker.impl.gui.invbutton.ui.SecondaryButton; -import red.jackf.chesttracker.impl.util.GuiUtil; - -public class ForgetContainerButton extends SecondaryButton { - private static final WidgetSprites SPRITES = GuiUtil.twoSprite("inventory_button/forget"); - - public ForgetContainerButton( - final @NotNull Runnable onClick - ) { - super( - SPRITES, - Component.translatable("civchesttracker.inventoryButton.remove"), - Objects.requireNonNull(onClick) - ); - } -} diff --git a/src/main/java/uk/protonull/civ/chesttracker/gui/widgets/OpenedInventoryButtons.java b/src/main/java/uk/protonull/civ/chesttracker/gui/widgets/OpenedInventoryButtons.java new file mode 100644 index 0000000..077b7f6 --- /dev/null +++ b/src/main/java/uk/protonull/civ/chesttracker/gui/widgets/OpenedInventoryButtons.java @@ -0,0 +1,81 @@ +package uk.protonull.civ.chesttracker.gui.widgets; + +import com.google.common.util.concurrent.Runnables; +import java.util.function.Consumer; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.WidgetSprites; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; +import red.jackf.chesttracker.api.providers.MemoryLocation; +import red.jackf.chesttracker.impl.gui.invbutton.ui.SecondaryButton; +import red.jackf.chesttracker.impl.gui.screen.MemoryBankManagerScreen; +import red.jackf.chesttracker.impl.memory.MemoryBankImpl; +import red.jackf.chesttracker.impl.util.GuiUtil; +import uk.protonull.civ.chesttracker.CivChestTrackerPlugin; +import uk.protonull.civ.chesttracker.gui.screens.ContainerLocationDeciderScreen; +import uk.protonull.civ.chesttracker.utilities.Shortcuts; + +public final class OpenedInventoryButtons { + public static final SecondaryButton BLACKLISTED = new SecondaryButton( + new WidgetSprites( + ResourceLocation.fromNamespaceAndPath(CivChestTrackerPlugin.ID, "cannot"), + ResourceLocation.fromNamespaceAndPath(CivChestTrackerPlugin.ID, "cannot_highlighted") + ), + Component.translatable("civchesttracker.inventoryButton.blacklisted"), + Runnables.doNothing() + ); + + public static final class NoMemoryBank extends SecondaryButton { + private static final WidgetSprites SPRITES = new WidgetSprites( + ResourceLocation.fromNamespaceAndPath(CivChestTrackerPlugin.ID, "unknown"), + ResourceLocation.fromNamespaceAndPath(CivChestTrackerPlugin.ID, "unknown_highlighted") + ); + public NoMemoryBank( + final @NotNull AbstractContainerScreen parent + ) { + super( + SPRITES, + Component.translatable("civchesttracker.inventoryButton.nomemorybank"), + () -> Minecraft.getInstance().setScreen(new MemoryBankManagerScreen(parent, Runnables.doNothing())) + ); + } + } + + public static final class ForgetContainer extends SecondaryButton { + private static final WidgetSprites SPRITES = GuiUtil.twoSprite("inventory_button/forget"); + public ForgetContainer( + final @NotNull AbstractContainerScreen parent, + final @NotNull MemoryBankImpl serverStorage, + final @NotNull MemoryLocation target + ) { + super( + SPRITES, + Component.translatable("civchesttracker.inventoryButton.forgetcontainer"), + () -> { + serverStorage.removeMemory(target.memoryKey(), target.position()); + Shortcuts.forciblyRefreshScreen(parent); + } + ); + } + } + + public static final class TrackContainer extends SecondaryButton { + private static final WidgetSprites SPRITES = GuiUtil.twoSprite("inventory_button/remember_container/never"); + public TrackContainer( + final @NotNull AbstractContainerScreen parent, + final @NotNull Consumer<@NotNull BlockPos> setInventoryLocation + ) { + super( + SPRITES, + Component.translatable("civchesttracker.inventoryButton.trackcontainer"), + () -> Minecraft.getInstance().setScreen(new ContainerLocationDeciderScreen( + parent, + setInventoryLocation + )) + ); + } + } +} diff --git a/src/main/java/uk/protonull/civ/chesttracker/gui/widgets/TrackContainerButton.java b/src/main/java/uk/protonull/civ/chesttracker/gui/widgets/TrackContainerButton.java deleted file mode 100644 index ce93bcc..0000000 --- a/src/main/java/uk/protonull/civ/chesttracker/gui/widgets/TrackContainerButton.java +++ /dev/null @@ -1,22 +0,0 @@ -package uk.protonull.civ.chesttracker.gui.widgets; - -import java.util.Objects; -import net.minecraft.client.gui.components.WidgetSprites; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; -import red.jackf.chesttracker.impl.gui.invbutton.ui.SecondaryButton; -import red.jackf.chesttracker.impl.util.GuiUtil; - -public class TrackContainerButton extends SecondaryButton { - private static final WidgetSprites SPRITES = GuiUtil.twoSprite("inventory_button/remember_container/never"); - - public TrackContainerButton( - final @NotNull Runnable onClick - ) { - super( - SPRITES, - Component.translatable("civchesttracker.inventoryButton.nottracked"), - Objects.requireNonNull(onClick) - ); - } -} diff --git a/src/main/java/uk/protonull/civ/chesttracker/mixing/InventoryWindow.java b/src/main/java/uk/protonull/civ/chesttracker/mixing/InventoryWindow.java index a612d4e..4f710c0 100644 --- a/src/main/java/uk/protonull/civ/chesttracker/mixing/InventoryWindow.java +++ b/src/main/java/uk/protonull/civ/chesttracker/mixing/InventoryWindow.java @@ -1,8 +1,36 @@ package uk.protonull.civ.chesttracker.mixing; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.player.LocalPlayer; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import red.jackf.chesttracker.api.providers.MemoryLocation; public interface InventoryWindow { @NotNull LocalPlayer civchesttracker$getPlayer(); + + @Nullable MemoryLocation civchesttracker$getInventoryIdentifier(); + + void civchesttracker$setInventoryIdentifier( + MemoryLocation inventoryIdentifier + ); + + static @NotNull LocalPlayer getPlayer( + final @NotNull AbstractContainerScreen screen + ) { + return ((InventoryWindow) screen).civchesttracker$getPlayer(); + } + + static @Nullable MemoryLocation getIdentifier( + final @NotNull AbstractContainerScreen screen + ) { + return ((InventoryWindow) screen).civchesttracker$getInventoryIdentifier(); + } + + static void setIdentifier( + final @NotNull AbstractContainerScreen screen, + final MemoryLocation inventoryIdentifier + ) { + ((InventoryWindow) screen).civchesttracker$setInventoryIdentifier(inventoryIdentifier); + } } diff --git a/src/main/java/uk/protonull/civ/chesttracker/mixins/InventoryContextButtonsMixin.java b/src/main/java/uk/protonull/civ/chesttracker/mixins/InventoryContextButtonsMixin.java index 5bab1c2..fdc2069 100644 --- a/src/main/java/uk/protonull/civ/chesttracker/mixins/InventoryContextButtonsMixin.java +++ b/src/main/java/uk/protonull/civ/chesttracker/mixins/InventoryContextButtonsMixin.java @@ -2,11 +2,8 @@ import com.llamalad7.mixinextras.sugar.Local; import java.util.List; -import java.util.Optional; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.client.player.LocalPlayer; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -24,10 +21,8 @@ import red.jackf.chesttracker.impl.gui.invbutton.ui.RenameButton; import red.jackf.chesttracker.impl.gui.invbutton.ui.SecondaryButton; import red.jackf.chesttracker.impl.memory.MemoryBankImpl; -import red.jackf.chesttracker.impl.memory.MemoryKeyImpl; -import uk.protonull.civ.chesttracker.gui.screens.ContainerLocationDeciderScreen; -import uk.protonull.civ.chesttracker.gui.widgets.ForgetContainerButton; -import uk.protonull.civ.chesttracker.gui.widgets.TrackContainerButton; +import uk.protonull.civ.chesttracker.gui.widgets.OpenedInventoryButtons; +import uk.protonull.civ.chesttracker.mixing.InventoryWindow; import uk.protonull.civ.chesttracker.utilities.Shortcuts; @Mixin(InventoryButton.class) @@ -42,13 +37,6 @@ public abstract class InventoryContextButtonsMixin { @Shadow(remap = false) private List secondaryButtons; - @Shadow - protected static void setRestoreLocation( - final @NotNull AbstractContainerScreen screen, - final @NotNull MemoryLocation location - ) { } - - @SuppressWarnings("OptionalUsedAsFieldOrParameterType") @Redirect( method = "", at = @At( @@ -60,51 +48,39 @@ protected static void setRestoreLocation( protected boolean civchesttracker$replaceBlacklistCheck( final @NotNull Class screenClass, // local captures - final @Local(argsOnly = true) AbstractContainerScreen parent, - final @Local(argsOnly = true) Optional target + final @Local(argsOnly = true) AbstractContainerScreen parent ) { - addExtraButtons(screenClass, parent, target.orElse(null)); + addExtraButtons(screenClass, parent); return true; } @Unique private void addExtraButtons( final @NotNull Class screenClass, - final @NotNull AbstractContainerScreen parent, - final MemoryLocation target + final @NotNull AbstractContainerScreen parent ) { this.secondaryButtons.clear(); if (ScreenBlacklist.isBlacklisted(screenClass)) { - LOGGER.info("screen is blacklisted!"); + this.secondaryButtons.add(OpenedInventoryButtons.BLACKLISTED); return; } final MemoryBankImpl serverStorage = Shortcuts.getChestTrackerStorage(); if (serverStorage == null) { - LOGGER.info("Server storage is null!"); + this.secondaryButtons.add(new OpenedInventoryButtons.NoMemoryBank(parent)); return; } + final MemoryLocation target = InventoryWindow.getIdentifier(parent); if (target != null) { - this.secondaryButtons.add(new ForgetContainerButton(() -> { - serverStorage.removeMemory(target.memoryKey(), target.position()); - Shortcuts.forciblyRefreshScreen(parent); - })); + this.secondaryButtons.add(new OpenedInventoryButtons.ForgetContainer(parent, serverStorage, target)); this.secondaryButtons.add(new RenameButton(parent, serverStorage, target)); return; } - // TODO: Lol - final LocalPlayer player = Shortcuts.getPlayerFromInventoryWindow(parent); - final ResourceLocation dimensionKey = player.clientLevel.dimension().location(); - final MemoryKeyImpl dimensionStorage = Shortcuts.getStorageForDimension(serverStorage, dimensionKey); - if (dimensionStorage == null) { - return; - } + final ResourceLocation dimensionKey = Shortcuts.getDimensionKeyFromInventoryWindow(parent); // Inventory is not being tracked yet, add button to offer tracking - this.secondaryButtons.add(new TrackContainerButton(() -> { - Minecraft.getInstance().setScreen(new ContainerLocationDeciderScreen( - parent, - (blockPos) -> setRestoreLocation(parent, MemoryLocation.inWorld(dimensionKey, blockPos)) - )); - })); + this.secondaryButtons.add(new OpenedInventoryButtons.TrackContainer( + parent, + (blockPos) -> InventoryWindow.setIdentifier(parent, MemoryLocation.inWorld(dimensionKey, blockPos)) + )); } @ModifyVariable( diff --git a/src/main/java/uk/protonull/civ/chesttracker/mixins/retention/RetainPlayerOnInventoryWindowMixin.java b/src/main/java/uk/protonull/civ/chesttracker/mixins/InventoryWindowMixin.java similarity index 65% rename from src/main/java/uk/protonull/civ/chesttracker/mixins/retention/RetainPlayerOnInventoryWindowMixin.java rename to src/main/java/uk/protonull/civ/chesttracker/mixins/InventoryWindowMixin.java index 07e2359..bfd7864 100644 --- a/src/main/java/uk/protonull/civ/chesttracker/mixins/retention/RetainPlayerOnInventoryWindowMixin.java +++ b/src/main/java/uk/protonull/civ/chesttracker/mixins/InventoryWindowMixin.java @@ -1,21 +1,26 @@ -package uk.protonull.civ.chesttracker.mixins.retention; +package uk.protonull.civ.chesttracker.mixins; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.player.LocalPlayer; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; +import red.jackf.chesttracker.api.providers.MemoryLocation; import uk.protonull.civ.chesttracker.mixing.InventoryWindow; @Mixin(AbstractContainerScreen.class) -public abstract class RetainPlayerOnInventoryWindowMixin implements InventoryWindow { +public abstract class InventoryWindowMixin implements InventoryWindow { @Unique private LocalPlayer player; + @Unique + private MemoryLocation inventoryIdentifier; + @Redirect( method = "", at = @At( @@ -34,4 +39,16 @@ public abstract class RetainPlayerOnInventoryWindowMixin implements InventoryWin public @NotNull LocalPlayer civchesttracker$getPlayer() { return this.player; } + + @Override + public @Nullable MemoryLocation civchesttracker$getInventoryIdentifier() { + return this.inventoryIdentifier; + } + + @Override + public void civchesttracker$setInventoryIdentifier( + final MemoryLocation inventoryIdentifier + ) { + this.inventoryIdentifier = inventoryIdentifier; + } } diff --git a/src/main/java/uk/protonull/civ/chesttracker/mixins/SetBlockPositionBasedOnMemoryMixin.java b/src/main/java/uk/protonull/civ/chesttracker/mixins/SetBlockPositionBasedOnMemoryMixin.java deleted file mode 100644 index e621b60..0000000 --- a/src/main/java/uk/protonull/civ/chesttracker/mixins/SetBlockPositionBasedOnMemoryMixin.java +++ /dev/null @@ -1,82 +0,0 @@ -package uk.protonull.civ.chesttracker.mixins; - -import com.llamalad7.mixinextras.sugar.Local; -import java.util.Optional; -import net.minecraft.client.player.LocalPlayer; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; -import red.jackf.chesttracker.api.ClientBlockSource; -import red.jackf.chesttracker.api.memory.Memory; -import red.jackf.chesttracker.api.providers.InteractionTracker; -import red.jackf.chesttracker.api.providers.context.ScreenOpenContext; -import red.jackf.chesttracker.api.providers.defaults.DefaultProvider; -import red.jackf.chesttracker.impl.memory.MemoryBankImpl; -import red.jackf.chesttracker.impl.memory.MemoryKeyImpl; -import red.jackf.chesttracker.impl.util.CachedClientBlockSource; -import uk.protonull.civ.chesttracker.utilities.Shortcuts; - -@Mixin(DefaultProvider.class) -public abstract class SetBlockPositionBasedOnMemoryMixin { - @SuppressWarnings("UnstableApiUsage") - @Redirect( - method = "onScreenOpen", - at = @At( - value = "INVOKE", - target = "Lred/jackf/chesttracker/api/providers/InteractionTracker;getLastBlockSource()Ljava/util/Optional;" - ), - remap = false - ) - protected Optional civchesttracker$onlyReturnPresetLocations( - final @NotNull InteractionTracker instance, - final @NotNull @Local(argsOnly = true) ScreenOpenContext context - ) { - final MemoryBankImpl serverStorage = Shortcuts.getChestTrackerStorage(); - if (serverStorage == null) { - return Optional.empty(); - } - final LocalPlayer player = Shortcuts.getPlayerFromInventoryWindow(context.getScreen()); - final MemoryKeyImpl dimensionStorage = Shortcuts.getStorageForDimension( - serverStorage, - player.clientLevel.dimension().location() - ); - if (dimensionStorage == null) { - return Optional.empty(); - } - final Memory matchingContainer = destructivelyFindFirstContainerWithName( - dimensionStorage, - context.getScreen().getTitle() - ); - if (matchingContainer == null) { - return Optional.empty(); - } - return Optional.of(new CachedClientBlockSource( - player.clientLevel, - Shortcuts.getMemoryLocation(matchingContainer) - )); - } - - @Unique - private static @Nullable Memory destructivelyFindFirstContainerWithName( - final @NotNull MemoryKeyImpl dimensionStorage, - final @NotNull Component inventoryName - ) { - Memory found = null; - for (final var iter = dimensionStorage.getMemories().values().iterator(); iter.hasNext();) { - final Memory memory = iter.next(); - if (!inventoryName.equals(memory.savedName())) { - continue; - } - if (found == null) { - found = memory; - continue; - } - iter.remove(); - } - return found; - } -} diff --git a/src/main/java/uk/protonull/civ/chesttracker/mixins/cruft/DoNotRegisterDefaultChestTrackerPluginMixin.java b/src/main/java/uk/protonull/civ/chesttracker/mixins/cruft/DoNotRegisterDefaultChestTrackerPluginMixin.java new file mode 100644 index 0000000..61a755b --- /dev/null +++ b/src/main/java/uk/protonull/civ/chesttracker/mixins/cruft/DoNotRegisterDefaultChestTrackerPluginMixin.java @@ -0,0 +1,17 @@ +package uk.protonull.civ.chesttracker.mixins.cruft; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import red.jackf.chesttracker.impl.DefaultChestTrackerPlugin; + +@Mixin(DefaultChestTrackerPlugin.class) +public abstract class DoNotRegisterDefaultChestTrackerPluginMixin { + /** + * @author Protonull + * @reason Do not register the default plugin. + */ + @Overwrite(remap = false) + public void load() { + // DO NOTHING + } +} diff --git a/src/main/java/uk/protonull/civ/chesttracker/mixins/cruft/DoNotRegisterHypixelProviderMixin.java b/src/main/java/uk/protonull/civ/chesttracker/mixins/cruft/DoNotRegisterHypixelProviderMixin.java deleted file mode 100644 index 97454e1..0000000 --- a/src/main/java/uk/protonull/civ/chesttracker/mixins/cruft/DoNotRegisterHypixelProviderMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package uk.protonull.civ.chesttracker.mixins.cruft; - -import org.jetbrains.annotations.NotNull; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; -import red.jackf.chesttracker.api.providers.ServerProvider; -import red.jackf.chesttracker.impl.DefaultChestTrackerPlugin; - -@Mixin(DefaultChestTrackerPlugin.class) -public abstract class DoNotRegisterHypixelProviderMixin { - @Redirect( - method = "load", - at = @At( - value = "INVOKE", - target = "Lred/jackf/chesttracker/api/providers/ProviderUtils;registerProvider(Lred/jackf/chesttracker/api/providers/ServerProvider;)Lred/jackf/chesttracker/api/providers/ServerProvider;", - ordinal = 1 - ), - remap = false - ) - protected T civchesttracker$voidRegistration( - final @NotNull T provider - ) { - return provider; // Do nothing - } -} diff --git a/src/main/java/uk/protonull/civ/chesttracker/utilities/Shortcuts.java b/src/main/java/uk/protonull/civ/chesttracker/utilities/Shortcuts.java index 2b32c85..e06b0ae 100644 --- a/src/main/java/uk/protonull/civ/chesttracker/utilities/Shortcuts.java +++ b/src/main/java/uk/protonull/civ/chesttracker/utilities/Shortcuts.java @@ -1,10 +1,11 @@ package uk.protonull.civ.chesttracker.utilities; +import java.util.Objects; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; @@ -21,24 +22,17 @@ public final class Shortcuts { return MemoryBankAccessImpl.INSTANCE.getLoadedInternal().orElse(null); } - public static @Nullable MemoryKeyImpl getStorageForDimension( - final @NotNull MemoryBankImpl serverStorage, - final @NotNull ResourceLocation dimension - ) { - return serverStorage.getKeyInternal(dimension).orElse(null); - } - public static @NotNull BlockPos getMemoryLocation( final @NotNull Memory memory ) { - return ((MemoryAccessor) (Object) memory).civchesttracker$getPosition(); + return Objects.requireNonNull(((MemoryAccessor) (Object) memory).civchesttracker$getPosition()); } public static void setMemoryLocation( final @NotNull Memory memory, final @NotNull BlockPos pos ) { - ((MemoryAccessor) (Object) memory).civchesttracker$setPosition(pos); + ((MemoryAccessor) (Object) memory).civchesttracker$setPosition(Objects.requireNonNull(pos)); } public static void forciblyRefreshScreen( @@ -51,10 +45,10 @@ public static void forciblyRefreshScreen( ); } - public static @NotNull LocalPlayer getPlayerFromInventoryWindow( + public static @NotNull ResourceLocation getDimensionKeyFromInventoryWindow( final @NotNull AbstractContainerScreen screen ) { - return ((InventoryWindow) screen).civchesttracker$getPlayer(); + return InventoryWindow.getPlayer(screen).clientLevel.dimension().location(); } public static @NotNull BlockPos asBlockPos( @@ -77,4 +71,29 @@ public static void forciblyRefreshScreen( (double) amount ); } + + public static @Nullable Memory destructivelyFindFirstContainerWithName( + final @NotNull MemoryKeyImpl dimensionStorage, + final @NotNull Component inventoryName + ) { + Memory found = null; + for (final var iter = dimensionStorage.getMemories().values().iterator(); iter.hasNext();) { + final Memory memory = iter.next(); + if (!inventoryName.equals(memory.savedName())) { + continue; + } + if (found == null) { + found = memory; + continue; + } + iter.remove(); + } + return found; + } + + public static void printMessage( + final @NotNull Component message + ) { + Minecraft.getInstance().gui.getChat().addMessage(message); + } } diff --git a/src/main/resources/assets/civchesttracker/lang/en_us.json b/src/main/resources/assets/civchesttracker/lang/en_us.json index 1925867..42c43bd 100644 --- a/src/main/resources/assets/civchesttracker/lang/en_us.json +++ b/src/main/resources/assets/civchesttracker/lang/en_us.json @@ -1,4 +1,8 @@ { - "civchesttracker.inventoryButton.nottracked": "Start tracking inventory?", - "civchesttracker.inventoryButton.remove": "Forget inventory?" + "civchesttracker.inventoryButton.blacklisted": "This inventory type is blacklisted!", + "civchesttracker.inventoryButton.nomemorybank": "There isn't a memory bank yet. Click to manage.", + "civchesttracker.inventoryButton.forgetcontainer": "Forget inventory?", + "civchesttracker.inventoryButton.trackcontainer": "Start tracking inventory?", + "civchesttracker.picker.header": "Where is this inventory?", + "civchesttracker.picker.confirm": "Confirm" } diff --git a/src/main/resources/assets/civchesttracker/textures/gui/sprites/cannot.png b/src/main/resources/assets/civchesttracker/textures/gui/sprites/cannot.png new file mode 100644 index 0000000000000000000000000000000000000000..6bda970ed0f8a7ac9b46ad23ac20567490af36a3 GIT binary patch literal 210 zcmeAS@N?(olHy`uVBq!ia0vp^+#t-s3?%0jwTl2L#^NA%Cx&(BWL^R}iUB?$u7M0J z77R>#L}YJ!1u>$fRB=&($XUYiwV^<2b9Gl=<|h%nH$6>u7M0J z77R>#L}YJ!1{{zW_%-|J3ink=lFBm8S1whGl zML(YbCEPt-978x}`kr;-1@v@z3VlT-mI(H!CaQUEXSjaBXnj6 z*V);Zj6<{6n+EU6sX5ovIi11w>0gm@t-AkpT;42l-fRAd0gYtvboFyt=akR{0M^A! AOaK4? literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/civchesttracker/textures/gui/sprites/unknown.png b/src/main/resources/assets/civchesttracker/textures/gui/sprites/unknown.png new file mode 100644 index 0000000000000000000000000000000000000000..58bdba63f41b3472d1ca0562308e9780b58c7927 GIT binary patch literal 235 zcmeAS@N?(olHy`uVBq!ia0vp^+#t-s1|(OmDOUqhjKx9jP7LeL$-D$|mU_B4hDc0J zPH|v99z5mW;TzM6-x(^MHhdIx;vmyRqdA4s1)U9j6nzAlfk0ea7(_MydUCsm2MBy# zaP5qkDZ!I|C$&XWHV3+P}5Pgg&ebxsLQ0Q4eOHvj+t literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/civchesttracker/textures/gui/sprites/unknown_highlighted.png b/src/main/resources/assets/civchesttracker/textures/gui/sprites/unknown_highlighted.png new file mode 100644 index 0000000000000000000000000000000000000000..ef4733a478eb7125ca2affe647aa9d4b701fab6f GIT binary patch literal 213 zcmeAS@N?(olHy`uVBq!ia0vp^+#t-s1|(OmDOUqhjKx9jP7LeL$-D$|`aNA7LnNjq zr#LYG2Lk?NV;vF96WU514!u^BF^kP4U#C(_UApS zw&T!aO|Spw(>4CLd;SBdI~#NL|N7G=50Z2YwjX4fuvYX@N?OJDzxvG_yN+MTt%_aN zn55;`dOv#$hqg