From 1d8249e173a2fef0374c22ab5c118d1d2324d09b Mon Sep 17 00:00:00 2001 From: Emma Date: Sat, 18 Dec 2021 22:18:32 -0500 Subject: [PATCH] Fix vaults, et al. (#40) --- .github/workflows/build.yml | 1 - .github/workflows/release.yml | 1 - .github/workflows/snapshot_publish.yml | 1 - build.gradle | 7 +- .../emcutils/containers/EmpireServer.java | 3 +- .../emcutils/features/ChatChannels.java | 32 ++++--- .../emcutils/features/TabListOrganizer.java | 3 +- .../frydae/emcutils/features/UsableItems.java | 6 +- .../frydae/emcutils/features/VaultScreen.java | 15 ++-- .../emcutils/features/VaultScreenHandler.java | 83 +++++++++++++++++++ .../emcutils/listeners/ChatListener.java | 7 +- .../emcutils/listeners/CommandListener.java | 3 +- .../mixins/ClientEntityPlayerMixin.java | 12 +-- .../mixins/ClientPlayNetworkHandlerMixin.java | 6 +- .../emcutils/tasks/GetChatAlertPitchTask.java | 3 +- .../emcutils/tasks/GetChatAlertSoundTask.java | 3 +- .../emcutils/tasks/GetLocationTask.java | 4 +- .../dev/frydae/emcutils/utils/Config.java | 3 +- .../frydae/emcutils/utils/MidnightConfig.java | 15 +--- .../java/dev/frydae/emcutils/utils/Util.java | 9 +- fabric/build.gradle | 7 ++ .../fabric/EmpireMinecraftUtilitiesImpl.java | 1 - .../voxelMap/GuiPersistentMapMixin.java | 3 +- .../fabric/voxelMap/GuiWaypointsMixin.java | 4 +- .../xaero/SupportXaeroMinimapMixin.java | 3 +- gradle.properties | 16 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 4 + setupAuth.gradle | 2 +- 29 files changed, 175 insertions(+), 84 deletions(-) create mode 100644 common/src/main/java/dev/frydae/emcutils/features/VaultScreenHandler.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 97d9a45..a4caa56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,6 @@ jobs: options: --user root steps: - uses: actions/checkout@v2 - - uses: gradle/wrapper-validation-action@v1 - uses: actions/setup-java@v2 with: distribution: adopt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b46b42f..a13b222 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,6 @@ jobs: options: --user root steps: - uses: actions/checkout@v2 - - uses: gradle/wrapper-validation-action@v1 - uses: actions/setup-java@v2 with: distribution: adopt diff --git a/.github/workflows/snapshot_publish.yml b/.github/workflows/snapshot_publish.yml index cac442d..2446e36 100644 --- a/.github/workflows/snapshot_publish.yml +++ b/.github/workflows/snapshot_publish.yml @@ -10,7 +10,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: gradle/wrapper-validation-action@v1 - uses: actions/setup-java@v2 with: distribution: adopt diff --git a/build.gradle b/build.gradle index 4c31209..f85a1fb 100644 --- a/build.gradle +++ b/build.gradle @@ -45,15 +45,16 @@ allprojects { jar { from "LICENSE" } task modrinth(type: com.modrinth.minotaur.TaskModrinthUpload) { + final String loader = project.name onlyIf { System.getenv().MODRINTH_TOKEN } detectLoaders = false token = System.getenv().MODRINTH_TOKEN projectId = "QYTT62S0" - versionNumber = mod_version + "+" + project.name - versionName = "${rootProject.release_title} (${project.name.toUpperCase().indexOf(0)})" + versionNumber = mod_version + "+" + loader + versionName = "${rootProject.release_title} (${loader.substring(0, 1).toUpperCase() + loader.substring(1)})" changelog = rootProject.changeLog uploadFile = project.file("build/libs/${rootProject.archivesBaseName}-${rootProject.version}.jar") addGameVersion(mc_version) - addLoader(project.name) + addLoader(loader) } } \ No newline at end of file diff --git a/common/src/main/java/dev/frydae/emcutils/containers/EmpireServer.java b/common/src/main/java/dev/frydae/emcutils/containers/EmpireServer.java index 1eaa8ff..e6107d2 100644 --- a/common/src/main/java/dev/frydae/emcutils/containers/EmpireServer.java +++ b/common/src/main/java/dev/frydae/emcutils/containers/EmpireServer.java @@ -5,6 +5,7 @@ import com.google.gson.JsonParser; import dev.frydae.emcutils.utils.Util; import lombok.Getter; +import net.minecraft.client.MinecraftClient; import net.minecraft.util.math.Vec3d; import java.io.BufferedReader; @@ -80,7 +81,7 @@ public static List getAllResidences() { } public void sendToServer() { - Util.getPlayer().sendChatMessage(getCommand()); + MinecraftClient.getInstance().player.sendChatMessage(getCommand()); Util.setCurrentServer(getName()); } diff --git a/common/src/main/java/dev/frydae/emcutils/features/ChatChannels.java b/common/src/main/java/dev/frydae/emcutils/features/ChatChannels.java index 0507589..5cc7e78 100644 --- a/common/src/main/java/dev/frydae/emcutils/features/ChatChannels.java +++ b/common/src/main/java/dev/frydae/emcutils/features/ChatChannels.java @@ -5,8 +5,11 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.LiteralText; import net.minecraft.util.Formatting; @@ -20,6 +23,8 @@ public class ChatChannels { @Setter private static String targetUsername = null; @Setter private static int targetGroupId = 0; private static long lastClickedButtonTime = 0L; + private static final ClientPlayerEntity player = MinecraftClient.getInstance().player; + private static final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; public static void handleChatScreenRender(Screen screen, MatrixStack matrices) { if (Util.isOnEMC) { @@ -44,7 +49,8 @@ public static void handleChatScreenMouseClicked(Screen screen, double mouseX, do currentChannel = channel; channel.executeCommand(); - Util.getClient().player.playSound(Config.getChatAlertSound().getSoundEvent(), 5, Config.getChatAlertPitch()); + if (Config.getChatAlertSound() != Config.ChatAlertSound.NULL) + player.playSound(Config.getChatAlertSound().getSoundEvent(), 5, Config.getChatAlertPitch()); // Cancel private conversation if in one inPrivateConversation = false; @@ -56,8 +62,8 @@ public static void handleChatScreenMouseClicked(Screen screen, double mouseX, do } private static boolean isInBounds(Screen screen, String text, int offset, double mouseX, double mouseY) { - int width = Util.getClient().textRenderer.getWidth(text); - int height = Util.getClient().textRenderer.fontHeight; + int width = textRenderer.getWidth(text); + int height = textRenderer.fontHeight; // Check X coordinate if (mouseX < offset + 1 || mouseX >= offset + width) { @@ -69,26 +75,26 @@ private static boolean isInBounds(Screen screen, String text, int offset, double } private static void drawButton(Screen screen, MatrixStack matrices, ChatChannel channel) { - int width = Util.getClient().textRenderer.getWidth(channel.name); - int height = Util.getClient().textRenderer.fontHeight; + int width = textRenderer.getWidth(channel.name); + int height = textRenderer.fontHeight; if (currentChannel == channel && !inPrivateConversation) { DrawableHelper.fill(matrices, channel.getOffset(), screen.height - 33, channel.getOffset() + width + 5, screen.height - (32 - height - 4), (0xff << 24) | channel.format.getColorValue()); } DrawableHelper.fill(matrices, channel.getOffset() + 1, screen.height - 32, channel.getOffset() + width + 4, screen.height - (32 - height - 3), (0xc0 << 24)); - Util.getClient().textRenderer.draw(matrices, new LiteralText(channel.name), channel.getOffset() + 3, screen.height - 30, channel.format.getColorValue()); + textRenderer.draw(matrices, new LiteralText(channel.name), channel.getOffset() + 3, screen.height - 30, channel.format.getColorValue()); } private static void drawPrivateConversation(Screen screen, MatrixStack matrices) { - int fullWidth = Util.getClient().textRenderer.getWidth("PM with: " + targetUsername); - int nameWidth = Util.getClient().textRenderer.getWidth(targetUsername); - int height = Util.getClient().textRenderer.fontHeight; + int fullWidth = textRenderer.getWidth("PM with: " + targetUsername); + int nameWidth = textRenderer.getWidth(targetUsername); + int height = textRenderer.fontHeight; DrawableHelper.fill(matrices, screen.width - 3, screen.height - 33, screen.width - fullWidth - 8, screen.height - (32 - height - 4), (0xff << 24) | Formatting.LIGHT_PURPLE.getColorValue()); DrawableHelper.fill(matrices, screen.width - 4, screen.height - 32, screen.width - fullWidth - 7, screen.height - (32 - height - 3), (0xc0 << 24)); - Util.getClient().textRenderer.draw(matrices, new LiteralText("PM with: "), screen.width - fullWidth - 5, screen.height - 30, Formatting.WHITE.getColorValue()); - Util.getClient().textRenderer.draw(matrices, new LiteralText(targetUsername), screen.width - nameWidth - 5, screen.height - 30, groupIdToFormatting(targetGroupId).getColorValue()); + textRenderer.draw(matrices, new LiteralText("PM with: "), screen.width - fullWidth - 5, screen.height - 30, Formatting.WHITE.getColorValue()); + textRenderer.draw(matrices, new LiteralText(targetUsername), screen.width - nameWidth - 5, screen.height - 30, groupIdToFormatting(targetGroupId).getColorValue()); } public static Formatting groupIdToFormatting(int groupId) { @@ -131,11 +137,11 @@ public int getOffset() { return 2; } - return adjustAgainst.getOffset() + Util.getClient().textRenderer.getWidth(adjustAgainst.name) + 6; + return adjustAgainst.getOffset() + textRenderer.getWidth(adjustAgainst.name) + 6; } public void executeCommand() { - Util.getClient().player.sendChatMessage(command); + player.sendChatMessage(command); } } } diff --git a/common/src/main/java/dev/frydae/emcutils/features/TabListOrganizer.java b/common/src/main/java/dev/frydae/emcutils/features/TabListOrganizer.java index c818910..5c45a27 100644 --- a/common/src/main/java/dev/frydae/emcutils/features/TabListOrganizer.java +++ b/common/src/main/java/dev/frydae/emcutils/features/TabListOrganizer.java @@ -8,7 +8,6 @@ import net.minecraft.client.network.PlayerListEntry; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; public class TabListOrganizer { @@ -21,7 +20,7 @@ public static List sortPlayers(List original) } for (PlayerListEntry entry : original) { - char server = Objects.requireNonNull(entry.getDisplayName()).getSiblings().get(0).getString().charAt(1); + char server = entry.getDisplayName().getSiblings().get(0).getString().charAt(1); String playerName = entry.getDisplayName().getSiblings().get(1).getString(); EnhancedTabListEntry enhancedEntry = new EnhancedTabListEntry(EmpireServer.getByTabListDisplay(server), playerName, entry); diff --git a/common/src/main/java/dev/frydae/emcutils/features/UsableItems.java b/common/src/main/java/dev/frydae/emcutils/features/UsableItems.java index 4f586bd..0429c2c 100644 --- a/common/src/main/java/dev/frydae/emcutils/features/UsableItems.java +++ b/common/src/main/java/dev/frydae/emcutils/features/UsableItems.java @@ -12,8 +12,6 @@ import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import java.util.Objects; - public class UsableItems { public UsableItems() { ClientTooltipEvent.ITEM.register(((itemStack, list, tooltipContext) -> { @@ -47,7 +45,7 @@ public UsableItems() { private static boolean isUsableItemWithCooldown(ItemStack item) { if (item != null && item.getNbt() != null) { if (item.getNbt().get("display") != null) { - String displayString = Objects.requireNonNull(item.getNbt().get("display")).toString(); + String displayString = item.getNbt().get("display").toString(); JsonObject display = new JsonParser().parse(displayString).getAsJsonObject(); JsonArray originalLore = display.getAsJsonArray("OriginalLore"); @@ -81,7 +79,7 @@ private static boolean isUsableItemWithCooldown(ItemStack item) { private static long getSecondsUntilUsable(ItemStack item) { if (item != null && item.getNbt() != null) { if (item.getNbt().get("display") != null) { - String displayString = Objects.requireNonNull(item.getNbt().get("display")).toString(); + String displayString = item.getNbt().get("display").toString(); JsonObject display = new JsonParser().parse(displayString).getAsJsonObject(); JsonArray originalLore = display.getAsJsonArray("OriginalLore"); diff --git a/common/src/main/java/dev/frydae/emcutils/features/VaultScreen.java b/common/src/main/java/dev/frydae/emcutils/features/VaultScreen.java index d82cf0a..6095f1d 100644 --- a/common/src/main/java/dev/frydae/emcutils/features/VaultScreen.java +++ b/common/src/main/java/dev/frydae/emcutils/features/VaultScreen.java @@ -20,7 +20,6 @@ import net.minecraft.item.Items; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtHelper; -import net.minecraft.screen.GenericContainerScreenHandler; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.sound.SoundEvents; import net.minecraft.text.LiteralText; @@ -35,8 +34,8 @@ import static dev.frydae.emcutils.utils.Util.MODID; @SuppressWarnings("SpellCheckingInspection") -public class VaultScreen extends HandledScreen implements ScreenHandlerProvider { - public static final RegistrySupplier> GENERIC_9X7; +public class VaultScreen extends HandledScreen implements ScreenHandlerProvider { + public static final RegistrySupplier> GENERIC_9X7; private static final Identifier TEXTURE = new Identifier(MODID, Config.returnVaultScreenOption()); private final int vaultPage; private final int[] slotOffsets = {8, 26, 44, 62, 80, 98, 116, 134, 152}; @@ -44,12 +43,12 @@ public class VaultScreen extends HandledScreen im static { Registrar> screenHandlers = EmpireMinecraftUtilities.REGISTRIES.get(Registry.MENU_KEY); - GENERIC_9X7 = screenHandlers.register(new Identifier(MODID, "generic_9x7"), () -> MenuRegistry.of(CreateGeneric9x7::createGeneric9x7)); + GENERIC_9X7 = screenHandlers.register(new Identifier(MODID, "generic_9x7"), () -> MenuRegistry.of(VaultScreenHandler::createGeneric9x7)); } public static void initStatic() {} - public VaultScreen(GenericContainerScreenHandler handler, PlayerInventory inventory, Text title) { + public VaultScreen(VaultScreenHandler handler, PlayerInventory inventory, Text title) { super(handler, inventory, title); super.init(MinecraftClient.getInstance(), MinecraftClient.getInstance().getWindow().getScaledWidth(), MinecraftClient.getInstance().getWindow().getScaledHeight()); this.passEvents = false; @@ -64,10 +63,8 @@ public VaultScreen(GenericContainerScreenHandler handler, PlayerInventory invent } } - private static final class CreateGeneric9x7 { - static GenericContainerScreenHandler createGeneric9x7(int syncId, PlayerInventory playerInventory) { - return new GenericContainerScreenHandler(GENERIC_9X7.get(), syncId, playerInventory, 7); - } + public static VaultScreenHandler createGeneric9x7(int syncId, PlayerInventory playerInventory) { + return new VaultScreenHandler(GENERIC_9X7.get(), syncId, playerInventory, 6); } /** diff --git a/common/src/main/java/dev/frydae/emcutils/features/VaultScreenHandler.java b/common/src/main/java/dev/frydae/emcutils/features/VaultScreenHandler.java new file mode 100644 index 0000000..18341b2 --- /dev/null +++ b/common/src/main/java/dev/frydae/emcutils/features/VaultScreenHandler.java @@ -0,0 +1,83 @@ +package dev.frydae.emcutils.features; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.Inventory; +import net.minecraft.inventory.SimpleInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.screen.slot.Slot; + +public class VaultScreenHandler extends ScreenHandler { + private final Inventory inventory; + private final int rows; + + public VaultScreenHandler(ScreenHandlerType type, int syncId, PlayerInventory playerInventory, int rows) { + this(type, syncId, playerInventory, new SimpleInventory(9 * rows), rows); + } + + public VaultScreenHandler(ScreenHandlerType type, int syncId, PlayerInventory playerInventory, Inventory inventory, int rows) { + super(type, syncId); + checkSize(inventory, rows * 9); + this.inventory = inventory; + this.rows = rows; + inventory.onOpen(playerInventory.player); + int i = (6 - 3) * 18; + + for (int row = 0; row < 6; ++row) { + for (int column = 0; column < 9; ++column) { + this.addSlot(new Slot(inventory, column + row * 9, 8 + column * 18, 18 + row * 18)); + } + } + + for (int row = 0; row < 3; ++row) { + for (int column = 0; column < 9; ++column) { + this.addSlot(new Slot(playerInventory, column + row * 9 + 9, 8 + column * 18, 103 + row * 18 + i)); + } + } + + for (int row = 0; row < 9; ++row) { + this.addSlot(new Slot(playerInventory, row, 8 + row * 18, 161 + i)); + } + } + + public static VaultScreenHandler createGeneric9x7(int syncId, PlayerInventory playerInventory) { + return new VaultScreenHandler(VaultScreen.GENERIC_9X7.get(), syncId, playerInventory, 6); + } + + public boolean canUse(PlayerEntity player) { + return this.inventory.canPlayerUse(player); + } + + public ItemStack transferSlot(PlayerEntity player, int index) { + ItemStack itemStack = ItemStack.EMPTY; + Slot slot = this.slots.get(index); + + if (slot.hasStack()) { + ItemStack itemStack2 = slot.getStack(); + itemStack = itemStack2.copy(); + + if (index < this.rows * 9) { + if (!this.insertItem(itemStack2, this.rows * 9, this.slots.size(), true)) { + return ItemStack.EMPTY; + } + } else if (!this.insertItem(itemStack2, 0, this.rows * 9, false)) { + return ItemStack.EMPTY; + } + + if (itemStack2.isEmpty()) { + slot.setStack(ItemStack.EMPTY); + } else { + slot.markDirty(); + } + } + + return itemStack; + } + + public void close(PlayerEntity player) { + super.close(player); + this.inventory.onClose(player); + } +} \ No newline at end of file diff --git a/common/src/main/java/dev/frydae/emcutils/listeners/ChatListener.java b/common/src/main/java/dev/frydae/emcutils/listeners/ChatListener.java index 08eb93b..08f1ebb 100644 --- a/common/src/main/java/dev/frydae/emcutils/listeners/ChatListener.java +++ b/common/src/main/java/dev/frydae/emcutils/listeners/ChatListener.java @@ -14,7 +14,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; -import java.util.Objects; public class ChatListener { private static final String WELCOME_TO_EMC = "Welcome to Empire Minecraft - .*, .*!"; @@ -80,7 +79,7 @@ private static ActionResult handleChatChannelChange(ClientPlayerEntity player, T private static ActionResult userGroupReceiver(ClientPlayerEntity player, Text text) { if (text.getString().matches(WELCOME_TO_EMC)) { - int group = getGroupIdFromColor(Objects.requireNonNull(text.getSiblings().get(5).getStyle().getColor())); + int group = getGroupIdFromColor(text.getSiblings().get(5).getStyle().getColor()); Util.setPlayerGroupId(group); } @@ -102,11 +101,11 @@ public static int getPlayerGroupIdFromTabList(String user) { List entries = Util.getPlayerListEntries(); for (PlayerListEntry entry : entries) { - if (Objects.requireNonNull(entry.getDisplayName()).getSiblings().get(1).getString().equalsIgnoreCase(user)) { + if (entry.getDisplayName().getSiblings().get(1).getString().equalsIgnoreCase(user)) { if (entry.getDisplayName().getSiblings().size() > 1) { Text coloredName = entry.getDisplayName().getSiblings().get(1); - return getGroupIdFromColor(Objects.requireNonNull(coloredName.getStyle().getColor())); + return getGroupIdFromColor(coloredName.getStyle().getColor()); } } } diff --git a/common/src/main/java/dev/frydae/emcutils/listeners/CommandListener.java b/common/src/main/java/dev/frydae/emcutils/listeners/CommandListener.java index 9aa0173..f49ab83 100644 --- a/common/src/main/java/dev/frydae/emcutils/listeners/CommandListener.java +++ b/common/src/main/java/dev/frydae/emcutils/listeners/CommandListener.java @@ -4,6 +4,7 @@ import dev.frydae.emcutils.features.VisitResidenceHandler; import dev.frydae.emcutils.interfaces.CommandCallback; import dev.frydae.emcutils.utils.Util; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.util.ActionResult; import org.apache.commons.lang3.math.NumberUtils; @@ -36,7 +37,7 @@ private static ActionResult handleResidenceHomeCommand(ClientPlayerEntity player } } else return ActionResult.PASS; - String resName = Util.getPlayer().getEntityName() + (num > 1 ? "-" + num : ""); // FIXME: this is what causes #33 + String resName = MinecraftClient.getInstance().player.getEntityName() + (num > 1 ? "-" + num : ""); // FIXME: this is what causes #33 EmpireServer server = VisitResidenceHandler.getResidenceServer(resName); diff --git a/common/src/main/java/dev/frydae/emcutils/mixins/ClientEntityPlayerMixin.java b/common/src/main/java/dev/frydae/emcutils/mixins/ClientEntityPlayerMixin.java index da2d4d7..9ea4e4f 100644 --- a/common/src/main/java/dev/frydae/emcutils/mixins/ClientEntityPlayerMixin.java +++ b/common/src/main/java/dev/frydae/emcutils/mixins/ClientEntityPlayerMixin.java @@ -3,7 +3,7 @@ import com.google.common.collect.Lists; import dev.frydae.emcutils.interfaces.ChatCallback; import dev.frydae.emcutils.interfaces.CommandCallback; -import dev.frydae.emcutils.utils.Util; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.util.ActionResult; import org.spongepowered.asm.mixin.Mixin; @@ -16,18 +16,20 @@ @Mixin(ClientPlayerEntity.class) public abstract class ClientEntityPlayerMixin { + private static final ClientPlayerEntity player = MinecraftClient.getInstance().player; + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V"), method = "sendChatMessage", cancellable = true) public void onPreSendMessage(String message, CallbackInfo info) { if (message.startsWith("/")) { message = message.substring(1); String[] parts = message.split(" "); - ActionResult commandResult = CommandCallback.PRE_EXECUTE_COMMAND.invoker().onPreExecuteCommand(Util.getPlayer(), parts[0], parts.length > 1 ? Arrays.stream(parts, 1, parts.length).collect(Collectors.toList()) : Lists.newArrayList()); + ActionResult commandResult = CommandCallback.PRE_EXECUTE_COMMAND.invoker().onPreExecuteCommand(player, parts[0], parts.length > 1 ? Arrays.stream(parts, 1, parts.length).collect(Collectors.toList()) : Lists.newArrayList()); if (commandResult == ActionResult.FAIL) { info.cancel(); } } else { - ActionResult messageResult = ChatCallback.PRE_SEND_MESSAGE.invoker().onPreSendMessage(Util.getPlayer(), message); + ActionResult messageResult = ChatCallback.PRE_SEND_MESSAGE.invoker().onPreSendMessage(player, message); if (messageResult == ActionResult.FAIL) { info.cancel(); @@ -40,9 +42,9 @@ public void onPostSendMessage(String message, CallbackInfo info) { if (message.startsWith("/")) { message = message.substring(1); String[] parts = message.split(" "); - CommandCallback.POST_EXECUTE_COMMAND.invoker().onPostExecuteCommand(Util.getPlayer(), parts[0], parts.length > 1 ? Arrays.stream(parts, 1, parts.length).collect(Collectors.toList()) : Lists.newArrayList()); + CommandCallback.POST_EXECUTE_COMMAND.invoker().onPostExecuteCommand(player, parts[0], parts.length > 1 ? Arrays.stream(parts, 1, parts.length).collect(Collectors.toList()) : Lists.newArrayList()); } else { - ChatCallback.POST_SEND_MESSAGE.invoker().onPostSendMessage(Util.getPlayer(), message); + ChatCallback.POST_SEND_MESSAGE.invoker().onPostSendMessage(player, message); } } } diff --git a/common/src/main/java/dev/frydae/emcutils/mixins/ClientPlayNetworkHandlerMixin.java b/common/src/main/java/dev/frydae/emcutils/mixins/ClientPlayNetworkHandlerMixin.java index 950205d..489400c 100644 --- a/common/src/main/java/dev/frydae/emcutils/mixins/ClientPlayNetworkHandlerMixin.java +++ b/common/src/main/java/dev/frydae/emcutils/mixins/ClientPlayNetworkHandlerMixin.java @@ -7,6 +7,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ingame.HandledScreens; import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket; @@ -20,10 +21,11 @@ @Mixin(ClientPlayNetworkHandler.class) public abstract class ClientPlayNetworkHandlerMixin { + private static final ClientPlayerEntity player = MinecraftClient.getInstance().player; @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;addChatMessage(Lnet/minecraft/network/MessageType;Lnet/minecraft/text/Text;Ljava/util/UUID;)V"), method = "onGameMessage", cancellable = true) public void onPreReceiveMessage(GameMessageS2CPacket packet, CallbackInfo info) { - ActionResult result = ChatCallback.PRE_RECEIVE_MESSAGE.invoker().onPreReceiveMessage(Util.getPlayer(), packet.getMessage()); + ActionResult result = ChatCallback.PRE_RECEIVE_MESSAGE.invoker().onPreReceiveMessage(player, packet.getMessage()); if (result != ActionResult.PASS) { info.cancel(); @@ -32,7 +34,7 @@ public void onPreReceiveMessage(GameMessageS2CPacket packet, CallbackInfo info) @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;addChatMessage(Lnet/minecraft/network/MessageType;Lnet/minecraft/text/Text;Ljava/util/UUID;)V", shift = At.Shift.AFTER), method = "onGameMessage") public void onPostReceiveMessage(GameMessageS2CPacket packet, CallbackInfo info) { - ChatCallback.POST_RECEIVE_MESSAGE.invoker().onPostReceiveMessage(Util.getPlayer(), packet.getMessage()); + ChatCallback.POST_RECEIVE_MESSAGE.invoker().onPostReceiveMessage(player, packet.getMessage()); } @Inject(at = @At("TAIL"), method = "onGameJoin") diff --git a/common/src/main/java/dev/frydae/emcutils/tasks/GetChatAlertPitchTask.java b/common/src/main/java/dev/frydae/emcutils/tasks/GetChatAlertPitchTask.java index cb47180..fefaca2 100644 --- a/common/src/main/java/dev/frydae/emcutils/tasks/GetChatAlertPitchTask.java +++ b/common/src/main/java/dev/frydae/emcutils/tasks/GetChatAlertPitchTask.java @@ -3,13 +3,14 @@ import dev.frydae.emcutils.interfaces.Task; import dev.frydae.emcutils.listeners.ChatListener; import dev.frydae.emcutils.utils.Util; +import net.minecraft.client.MinecraftClient; public class GetChatAlertPitchTask implements Task { @Override public void execute() { Util.getInstance().setHideFeatureMessages(true); ChatListener.currentMessage = ChatListener.ChatMessage.CHAT_ALERT_SOUND_PITCH; - Util.getPlayer().sendChatMessage("/ps set chatalertpitch"); + MinecraftClient.getInstance().player.sendChatMessage("/ps set chatalertpitch"); } @Override diff --git a/common/src/main/java/dev/frydae/emcutils/tasks/GetChatAlertSoundTask.java b/common/src/main/java/dev/frydae/emcutils/tasks/GetChatAlertSoundTask.java index 37831f0..02fbc53 100644 --- a/common/src/main/java/dev/frydae/emcutils/tasks/GetChatAlertSoundTask.java +++ b/common/src/main/java/dev/frydae/emcutils/tasks/GetChatAlertSoundTask.java @@ -3,13 +3,14 @@ import dev.frydae.emcutils.interfaces.Task; import dev.frydae.emcutils.listeners.ChatListener; import dev.frydae.emcutils.utils.Util; +import net.minecraft.client.MinecraftClient; public class GetChatAlertSoundTask implements Task { @Override public void execute() { Util.getInstance().setHideFeatureMessages(true); ChatListener.currentMessage = ChatListener.ChatMessage.CHAT_ALERT_SOUND; - Util.getPlayer().sendChatMessage("/ps set chatalertsound"); + MinecraftClient.getInstance().player.sendChatMessage("/ps set chatalertsound"); } @Override diff --git a/common/src/main/java/dev/frydae/emcutils/tasks/GetLocationTask.java b/common/src/main/java/dev/frydae/emcutils/tasks/GetLocationTask.java index 2226363..c1bf622 100644 --- a/common/src/main/java/dev/frydae/emcutils/tasks/GetLocationTask.java +++ b/common/src/main/java/dev/frydae/emcutils/tasks/GetLocationTask.java @@ -2,13 +2,13 @@ import dev.frydae.emcutils.interfaces.Task; import dev.frydae.emcutils.listeners.ChatListener; -import dev.frydae.emcutils.utils.Util; +import net.minecraft.client.MinecraftClient; public class GetLocationTask implements Task { @Override public void execute() { ChatListener.currentMessage = ChatListener.ChatMessage.LOCATION; - Util.getPlayer().sendChatMessage("/loc"); + MinecraftClient.getInstance().player.sendChatMessage("/loc"); } @Override diff --git a/common/src/main/java/dev/frydae/emcutils/utils/Config.java b/common/src/main/java/dev/frydae/emcutils/utils/Config.java index 48c8b92..ddb1164 100644 --- a/common/src/main/java/dev/frydae/emcutils/utils/Config.java +++ b/common/src/main/java/dev/frydae/emcutils/utils/Config.java @@ -58,7 +58,8 @@ public enum ChatAlertSound { LEVEL_UP(SoundEvents.ENTITY_PLAYER_LEVELUP), ORB_PICKUP(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP), NOTE_PLING(SoundEvents.BLOCK_NOTE_BLOCK_PLING), - ITEM_PICKUP(SoundEvents.ENTITY_ITEM_PICKUP); + ITEM_PICKUP(SoundEvents.ENTITY_ITEM_PICKUP), + NULL(null); @Getter private final String name; @Getter private final SoundEvent soundEvent; diff --git a/common/src/main/java/dev/frydae/emcutils/utils/MidnightConfig.java b/common/src/main/java/dev/frydae/emcutils/utils/MidnightConfig.java index 445b2c6..bc4655f 100644 --- a/common/src/main/java/dev/frydae/emcutils/utils/MidnightConfig.java +++ b/common/src/main/java/dev/frydae/emcutils/utils/MidnightConfig.java @@ -31,14 +31,7 @@ import java.lang.reflect.Modifier; import java.nio.file.Files; import java.nio.file.Path; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; @@ -225,7 +218,7 @@ protected void init() { } } } - Objects.requireNonNull(client).setScreen(parent); + client.setScreen(parent); })); ButtonWidget done = this.addDrawableChild(new ButtonWidget(this.width / 2 + 4, this.height - 28, 150, 20, ScreenTexts.DONE, (button) -> { @@ -237,7 +230,7 @@ protected void init() { } } write(modid); - Objects.requireNonNull(client).setScreen(parent); + client.setScreen(parent); })); this.list = new MidnightConfigListWidget(this.client, this.width, this.height, 32, this.height - 32, 25); @@ -249,7 +242,7 @@ protected void init() { info.value = info.defaultValue; info.tempValue = info.value.toString(); double scrollAmount = list.getScrollAmount(); - Objects.requireNonNull(client).setScreen(this); + client.setScreen(this); list.setScrollAmount(scrollAmount); })); diff --git a/common/src/main/java/dev/frydae/emcutils/utils/Util.java b/common/src/main/java/dev/frydae/emcutils/utils/Util.java index 0b041c6..e03c31a 100644 --- a/common/src/main/java/dev/frydae/emcutils/utils/Util.java +++ b/common/src/main/java/dev/frydae/emcutils/utils/Util.java @@ -8,7 +8,6 @@ import lombok.Setter; import lombok.SneakyThrows; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.PlayerListEntry; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -16,7 +15,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.Queue; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -36,8 +34,7 @@ public class Util { private static volatile Util singleton; @Getter @Setter private boolean shouldRunTasks = false; @Setter public static boolean worldLoaded = false; - @Getter public static ClientPlayerEntity player = MinecraftClient.getInstance().player; - @Getter public static final MinecraftClient client = MinecraftClient.getInstance(); + private static final MinecraftClient client = MinecraftClient.getInstance(); public static void setCurrentServer(String name) { for (EmpireServer server : EmpireServer.values()) { @@ -52,7 +49,7 @@ public static void setCurrentServer(String name) { public static List getPlayerListEntries() { return Lists.newArrayList(((PlayerListHudAccessor) client.inGameHud.getPlayerListHud()) - .getEntryOrdering().sortedCopy(Objects.requireNonNull(client.getNetworkHandler()).getPlayerList())); + .getEntryOrdering().sortedCopy(client.getNetworkHandler().getPlayerList())); } public static Queue getOnJoinCommandQueue() { @@ -74,7 +71,7 @@ public void run() { while ((command = onJoinCommandQueue.poll()) != null) { if (command.startsWith("/")) command = command.substring(1); - if (worldLoaded) Util.getPlayer().sendChatMessage("/" + command); + if (worldLoaded) client.player.sendChatMessage("/" + command); //noinspection BusyWait Thread.sleep(100); diff --git a/fabric/build.gradle b/fabric/build.gradle index 06c376c..eb5dd88 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -27,6 +27,10 @@ repositories { includeGroup "xaero" } } + maven { + url "https://api.modrinth.com/maven" + content { includeGroup "maven.modrinth" } + } } configurations { @@ -53,6 +57,9 @@ dependencies { modCompileOnly "xaero:minimap:${rootProject.xmm_version}+${rootProject.mc_version_major}" modCompileOnly "xaero:map:${rootProject.xwm_version}+${rootProject.mc_version_major}" + modRuntimeOnly "maven.modrinth:clean-logs:1.0.1" + runtimeOnly "com.moandjiezana.toml:toml4j:0.7.2" + common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false } } diff --git a/fabric/src/main/java/dev/frydae/emcutils/fabric/EmpireMinecraftUtilitiesImpl.java b/fabric/src/main/java/dev/frydae/emcutils/fabric/EmpireMinecraftUtilitiesImpl.java index 42170a9..ffd93cb 100644 --- a/fabric/src/main/java/dev/frydae/emcutils/fabric/EmpireMinecraftUtilitiesImpl.java +++ b/fabric/src/main/java/dev/frydae/emcutils/fabric/EmpireMinecraftUtilitiesImpl.java @@ -8,7 +8,6 @@ import dev.frydae.emcutils.tasks.Tasks; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; import static dev.frydae.emcutils.utils.Util.LOG; import static dev.frydae.emcutils.utils.Util.MODID; diff --git a/fabric/src/main/java/dev/frydae/emcutils/mixins/fabric/voxelMap/GuiPersistentMapMixin.java b/fabric/src/main/java/dev/frydae/emcutils/mixins/fabric/voxelMap/GuiPersistentMapMixin.java index 167d498..752498b 100644 --- a/fabric/src/main/java/dev/frydae/emcutils/mixins/fabric/voxelMap/GuiPersistentMapMixin.java +++ b/fabric/src/main/java/dev/frydae/emcutils/mixins/fabric/voxelMap/GuiPersistentMapMixin.java @@ -5,6 +5,7 @@ import com.mamiyaotaru.voxelmap.util.Waypoint; import dev.frydae.emcutils.containers.EmpireResidence; import dev.frydae.emcutils.utils.Util; +import net.minecraft.client.MinecraftClient; import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; @@ -33,7 +34,7 @@ public void redirectTeleport(Popup popup, int action, CallbackInfo ci, EmpireResidence res = Util.getCurrentServer().getResidenceByLoc(pos); if (res != null) { - Util.getPlayer().sendChatMessage(res.getVisitCommand()); + MinecraftClient.getInstance().player.sendChatMessage(res.getVisitCommand()); ci.cancel(); } diff --git a/fabric/src/main/java/dev/frydae/emcutils/mixins/fabric/voxelMap/GuiWaypointsMixin.java b/fabric/src/main/java/dev/frydae/emcutils/mixins/fabric/voxelMap/GuiWaypointsMixin.java index 0589314..2316f72 100644 --- a/fabric/src/main/java/dev/frydae/emcutils/mixins/fabric/voxelMap/GuiWaypointsMixin.java +++ b/fabric/src/main/java/dev/frydae/emcutils/mixins/fabric/voxelMap/GuiWaypointsMixin.java @@ -4,6 +4,7 @@ import com.mamiyaotaru.voxelmap.util.Waypoint; import dev.frydae.emcutils.containers.EmpireResidence; import dev.frydae.emcutils.utils.Util; +import net.minecraft.client.MinecraftClient; import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; @@ -24,8 +25,7 @@ public void handleTeleport(CallbackInfo ci) { EmpireResidence res = Util.getCurrentServer().getResidenceByLoc(pos); if (res != null) { - Util.getPlayer().sendChatMessage(res.getVisitCommand()); - + MinecraftClient.getInstance().player.sendChatMessage(res.getVisitCommand()); } ci.cancel(); } diff --git a/fabric/src/main/java/dev/frydae/emcutils/mixins/fabric/xaero/SupportXaeroMinimapMixin.java b/fabric/src/main/java/dev/frydae/emcutils/mixins/fabric/xaero/SupportXaeroMinimapMixin.java index 0e394f0..5231645 100644 --- a/fabric/src/main/java/dev/frydae/emcutils/mixins/fabric/xaero/SupportXaeroMinimapMixin.java +++ b/fabric/src/main/java/dev/frydae/emcutils/mixins/fabric/xaero/SupportXaeroMinimapMixin.java @@ -2,6 +2,7 @@ import dev.frydae.emcutils.containers.EmpireResidence; import dev.frydae.emcutils.utils.Util; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; @@ -27,7 +28,7 @@ public void teleportToResidenceOnEMC(Screen screen, Waypoint w, CallbackInfo ci) new Vec3d(w.getX(), 64, w.getZ()) ); - if (res != null) Util.getPlayer().sendChatMessage(res.getVisitCommand()); + if (res != null) MinecraftClient.getInstance().player.sendChatMessage(res.getVisitCommand()); } } } diff --git a/gradle.properties b/gradle.properties index 6e97b09..eaa5cc4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,20 +4,20 @@ org.gradle.parallel=true mc_version=1.17.1 mc_version_major=1.17 -mod_version=2.3.3 +mod_version=2.4.0-beta.1 -release_title=Fix vaults not working -changeLog=Fixed a bug where vaults would not work at all. Whoops. +release_title=Fix funky vault bug, et al +changeLog=Fixes the following: \n\n-Vault buttons are positioned weirdly\n\n-Typing /home crashes game\n\n-No option for no channel switch sound # https://fabricmc.net/versions.html -yarn_mappings=64 -loader_version=0.12.5 -fabric_version=0.43.1 +yarn_mappings=65 +loader_version=0.12.12 +fabric_version=0.44.0 -forge_version=37.0.126 +forge_version=37.1.1 # https://maven.shedaniel.me/dev/architectury/architectury/ -architectury_version=2.6.35 +architectury_version=2.8.53 # https://modrinth.com/mod/modmenu/versions modmenu_version=2.0.14 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e750102..d2880ba 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 29f5766..abe6b36 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,6 +8,10 @@ pluginManagement { name = 'Architectury' url = 'https://maven.architectury.dev/' } + maven { + name = 'Quilt' + url = 'https://maven.quiltmc.org/repository/release' + } maven { name = 'Forge' url = 'https://maven.minecraftforge.net/' diff --git a/setupAuth.gradle b/setupAuth.gradle index 644d5b7..8e93d9f 100644 --- a/setupAuth.gradle +++ b/setupAuth.gradle @@ -25,7 +25,7 @@ import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService rootProject.ext.credentials = new Properties() try { - rootProject.ext.credentials.load(new FileReader(file('credentials.properties'))) + rootProject.ext.credentials.load(new FileReader(rootProject.file('credentials.properties'))) } catch (IOException ignore) { }