diff --git a/gradle.properties b/gradle.properties index 3b9cc53..33c50a5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,6 @@ yarn_mappings=1.16.1+build.21 loader_version=0.12.12 # Mod Properties -mod_version=1.2.0 +mod_version=1.3.0 maven_group=me.wurgo archives_base_name=practiceseedmod diff --git a/src/main/java/me/wurgo/practiceseedmod/PracticeSeedMod.java b/src/main/java/me/wurgo/practiceseedmod/PracticeSeedMod.java index 44ea4ae..0a34675 100644 --- a/src/main/java/me/wurgo/practiceseedmod/PracticeSeedMod.java +++ b/src/main/java/me/wurgo/practiceseedmod/PracticeSeedMod.java @@ -49,6 +49,9 @@ public class PracticeSeedMod implements ClientModInitializer { public static String seedNotes; public static Random barteringRandom; public static Random blazeDropRandom; + public static boolean isRace; + public static String racePassword; + public static String raceHost; public static void log(Object msg) { LOGGER.log(Level.INFO, msg); @@ -93,7 +96,7 @@ public static void playNextSeed(long l) { GameMode.SURVIVAL, false, Difficulty.EASY, - true, + !isRace, new GameRules(), DataPackSettings.SAFE_MODE ); @@ -147,10 +150,12 @@ public void onInitializeClient() { JsonParser parser = new JsonParser(); JsonArray args = parser.parse(Arrays.toString(args1)).getAsJsonArray().get(0).getAsJsonArray(); - if (args.get(0).getAsString().equals(uuid.toString())) { + if (uuid != null && args.get(0).getAsString().equals(uuid.toString())) { try { long l = Long.parseLong(args.get(1).getAsString()); - queue.add(l); + if (!(running && isRace)) { + queue.add(l); + } JsonElement notesElement = args.get(2); if (notesElement != null && !notesElement.isJsonNull()) { @@ -163,6 +168,29 @@ public void onInitializeClient() { } } catch (NumberFormatException ignored) { log("Invalid seed!"); + } catch(IndexOutOfBoundsException ignored) { + log("Invalid request received!"); + } + } + }); + SOCKET.on("race-seed", args1 -> { + JsonParser parser = new JsonParser(); + JsonArray args = parser.parse(Arrays.toString(args1)).getAsJsonArray().get(0).getAsJsonArray(); + + if (args.get(0).getAsString().equals(racePassword) && isRace) { + try { + queue.clear(); + long l = Long.parseLong(args.get(1).getAsString()); + queue.add(l); + + raceHost = args.get(2).getAsString(); + + running = true; + playNextSeed(); + } catch (NumberFormatException ignored) { + log("Invalid seed!"); + } catch (IndexOutOfBoundsException ignored) { + log("Invalid request received!"); } } }); diff --git a/src/main/java/me/wurgo/practiceseedmod/gui/DownloadUpdateScreen.java b/src/main/java/me/wurgo/practiceseedmod/gui/DownloadUpdateScreen.java index 628d2d0..7b17e86 100644 --- a/src/main/java/me/wurgo/practiceseedmod/gui/DownloadUpdateScreen.java +++ b/src/main/java/me/wurgo/practiceseedmod/gui/DownloadUpdateScreen.java @@ -71,7 +71,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { String modVersion = PracticeSeedMod.MOD_CONTAINER.getMetadata().getVersion().getFriendlyString(); this.drawCenteredString(matrices, this.textRenderer, "New Update for " + PracticeSeedMod.MOD_CONTAINER.getMetadata().getName() + " has been found!", width / 2, height / 2 - 20, whiteColor); - this.drawCenteredString(matrices, this.textRenderer, String.format("Do you want to download it? (Current : %s, Latest : %s)", modVersion.split("\\+")[0], UpdateChecker.LATEST_VERSION), width / 2, height / 2 - 9, whiteColor); + this.drawCenteredString(matrices, this.textRenderer, String.format("Do you want to download it? (Current: %s, Latest: %s)", modVersion.split("\\+")[0], UpdateChecker.LATEST_VERSION), width / 2, height / 2 - 9, whiteColor); } else if (currentStatus == Status.DOWNLOADING) { this.drawCenteredString(matrices, this.textRenderer, String.format("Downloading '%s'...", UpdateChecker.LATEST_DOWNLOAD_NAME), width / 2, height / 2 - 20, whiteColor); } else if (currentStatus == Status.DONE) { diff --git a/src/main/java/me/wurgo/practiceseedmod/gui/LinkUUIDScreen.java b/src/main/java/me/wurgo/practiceseedmod/gui/LinkUUIDScreen.java index 3acac0e..9039ff6 100644 --- a/src/main/java/me/wurgo/practiceseedmod/gui/LinkUUIDScreen.java +++ b/src/main/java/me/wurgo/practiceseedmod/gui/LinkUUIDScreen.java @@ -4,6 +4,7 @@ import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ScreenTexts; import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.LiteralText; @@ -11,6 +12,10 @@ public class LinkUUIDScreen extends Screen { private final Screen parent; + private boolean hasCopied = false; + private boolean hasTyped = false; + private ButtonWidget copyButton; + private TextFieldWidget passwordField; public LinkUUIDScreen(Screen parent) { super(new LiteralText("Link UUID:")); @@ -26,29 +31,38 @@ public boolean shouldCloseOnEsc() { @Override protected void init() { - int buttonWidth = 100; + int buttonWidth = 150; - this.addButton( + this.copyButton = this.addButton( new ButtonWidget( this.width / 2 - buttonWidth / 2, - this.height / 2, + this.height / 2 + 25, buttonWidth, 20, new LiteralText("Copy UUID"), b -> { if (this.client != null) { - if (b.getMessage().getString().equals("Copy UUID")) { + if (!this.hasCopied && !this.hasTyped) { this.client.keyboard.setClipboard(PracticeSeedMod.uuid.toString()); - b.setMessage(ScreenTexts.DONE); + this.hasCopied = true; } else { - this.client.openScreen(null); + this.onClose(); } } } ) ); - super.init(); + this.passwordField = new TextFieldWidget( + this.textRenderer, + this.width / 2 - buttonWidth / 2, + this.height / 2, + buttonWidth, + 20, + new LiteralText("") + ); + this.passwordField.setMaxLength(50); + this.addChild(this.passwordField); } @Override @@ -56,11 +70,40 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { this.renderBackground(matrices); this.drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 13, 16777215); + this.drawCenteredString( + matrices, + this.textRenderer, + "Race Password (Optional)", + this.width / 2, + this.height / 2 - 15, + 16777215 + ); + + this.copyButton.setMessage(this.hasCopied || this.hasTyped ? ScreenTexts.DONE : new LiteralText("Copy UUID")); + this.hasTyped = this.passwordField.getText().length() > 0; + this.passwordField.setEditable(!this.hasCopied); + if (this.passwordField.isFocused() && this.hasCopied) { + this.passwordField.setSelected(false); + } + + this.passwordField.render(matrices, mouseX, mouseY, delta); + super.render(matrices, mouseX, mouseY, delta); } @Override public void onClose() { + if (this.hasTyped) { + PracticeSeedMod.isRace = true; + PracticeSeedMod.racePassword = this.passwordField.getText(); + PracticeSeedMod.uuid = null; + PracticeSeedMod.log("Linked Multiplayer: " + PracticeSeedMod.racePassword); + } else { + PracticeSeedMod.isRace = false; + PracticeSeedMod.racePassword = null; + PracticeSeedMod.log("Linked UUID: " + PracticeSeedMod.uuid); + } + if (this.client != null) { this.client.openScreen(this.parent); } diff --git a/src/main/java/me/wurgo/practiceseedmod/mixin/core/MinecraftClientMixin.java b/src/main/java/me/wurgo/practiceseedmod/mixin/core/MinecraftClientMixin.java index 6e535b7..b7b3492 100644 --- a/src/main/java/me/wurgo/practiceseedmod/mixin/core/MinecraftClientMixin.java +++ b/src/main/java/me/wurgo/practiceseedmod/mixin/core/MinecraftClientMixin.java @@ -1,11 +1,14 @@ package me.wurgo.practiceseedmod.mixin.core; import me.wurgo.practiceseedmod.PracticeSeedMod; +import me.wurgo.practiceseedmod.core.UpdateChecker; +import me.wurgo.practiceseedmod.gui.DownloadUpdateScreen; import me.wurgo.practiceseedmod.gui.LinkUUIDScreen; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.SaveLevelScreen; import net.minecraft.client.gui.screen.Screen; import net.minecraft.text.LiteralText; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -26,6 +29,10 @@ public abstract class MinecraftClientMixin { ) ) private void otherScreen(MinecraftClient instance, Screen screen) { + if (UpdateChecker.LATEST_DOWNLOAD_URL != null && !DownloadUpdateScreen.CHECKED) { + instance.openScreen(new DownloadUpdateScreen()); + return; + } instance.openScreen(new LinkUUIDScreen(null)); } diff --git a/src/main/java/me/wurgo/practiceseedmod/mixin/gui/DebugHudMixin.java b/src/main/java/me/wurgo/practiceseedmod/mixin/gui/DebugHudMixin.java new file mode 100644 index 0000000..8caf174 --- /dev/null +++ b/src/main/java/me/wurgo/practiceseedmod/mixin/gui/DebugHudMixin.java @@ -0,0 +1,28 @@ +package me.wurgo.practiceseedmod.mixin.gui; + +import me.wurgo.practiceseedmod.PracticeSeedMod; +import net.minecraft.client.gui.hud.DebugHud; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(DebugHud.class) +public class DebugHudMixin { + @Inject(method = "getRightText", at = @At("RETURN"), cancellable = true) + private void addDebugText(CallbackInfoReturnable> cir) { + if (PracticeSeedMod.running) { + List list = cir.getReturnValue(); + list.add(""); + if (PracticeSeedMod.isRace) { + list.add("Race hosted by " + PracticeSeedMod.raceHost); + list.add("Racing on seed '" + PracticeSeedMod.currentSeed + "'"); + } else { + list.add("Practicing on seed '" + PracticeSeedMod.currentSeed + "'"); + } + cir.setReturnValue(list); + } + } +} diff --git a/src/main/java/me/wurgo/practiceseedmod/mixin/gui/TitleScreenMixin.java b/src/main/java/me/wurgo/practiceseedmod/mixin/gui/TitleScreenMixin.java index 30179f0..b4362c4 100644 --- a/src/main/java/me/wurgo/practiceseedmod/mixin/gui/TitleScreenMixin.java +++ b/src/main/java/me/wurgo/practiceseedmod/mixin/gui/TitleScreenMixin.java @@ -42,12 +42,6 @@ private void addNewButton(int y, int spacingY, CallbackInfo ci) { @Inject(method = "tick", at = @At("HEAD"), cancellable = true) private void playNextSeed(CallbackInfo ci) { - if (UpdateChecker.LATEST_DOWNLOAD_URL != null && !DownloadUpdateScreen.CHECKED && this.client != null) { - this.client.openScreen(new DownloadUpdateScreen()); - ci.cancel(); - return; - } - PracticeSeedMod.currentSeed = null; if (PracticeSeedMod.playNextSeed()) { ci.cancel(); } else { PracticeSeedMod.running = false; } diff --git a/src/main/java/me/wurgo/practiceseedmod/mixin/mechanics/blocks/GravelBlockMixin.java b/src/main/java/me/wurgo/practiceseedmod/mixin/mechanics/blocks/GravelBlockMixin.java index 139402d..b69629b 100644 --- a/src/main/java/me/wurgo/practiceseedmod/mixin/mechanics/blocks/GravelBlockMixin.java +++ b/src/main/java/me/wurgo/practiceseedmod/mixin/mechanics/blocks/GravelBlockMixin.java @@ -22,7 +22,7 @@ public GravelBlockMixin(Settings settings) { @Override public List getDroppedStacks(BlockState state, LootContext.Builder builder) { - if (PracticeSeedMod.running && !WorldConstants.hasDroppedFlint && new ConfigWrapper(ConfigWriter.INSTANCE).getBoolValue("firstTryFlint", true)) { + if (!WorldConstants.hasDroppedFlint && new ConfigWrapper(ConfigWriter.INSTANCE).getBoolValue("firstTryFlint", true)) { WorldConstants.hasDroppedFlint = true; return List.of(new ItemStack(Items.FLINT)); } diff --git a/src/main/java/me/wurgo/practiceseedmod/mixin/mechanics/entities/BlazeEntityMixin.java b/src/main/java/me/wurgo/practiceseedmod/mixin/mechanics/entities/BlazeEntityMixin.java index f6458c1..313da86 100644 --- a/src/main/java/me/wurgo/practiceseedmod/mixin/mechanics/entities/BlazeEntityMixin.java +++ b/src/main/java/me/wurgo/practiceseedmod/mixin/mechanics/entities/BlazeEntityMixin.java @@ -33,7 +33,7 @@ private void fakeDropStack(ItemStack stack) { protected void dropLoot(DamageSource source, boolean causedByPlayer) { if (this.world.getServer() == null) { return; } - if (PracticeSeedMod.running && new ConfigWrapper(ConfigWriter.INSTANCE).getBoolValue("guaranteeDrops", true)) { + if (new ConfigWrapper(ConfigWriter.INSTANCE).getBoolValue("guaranteeDrops", true)) { Identifier identifier = this.getLootTable(); LootTable lootTable = this.world.getServer().getLootManager().getTable(identifier); LootContext.Builder builder = this.getLootContextBuilder(causedByPlayer, source); diff --git a/src/main/java/me/wurgo/practiceseedmod/mixin/mechanics/entities/EndermanEntityMixin.java b/src/main/java/me/wurgo/practiceseedmod/mixin/mechanics/entities/EndermanEntityMixin.java index f3feb4a..c776c5b 100644 --- a/src/main/java/me/wurgo/practiceseedmod/mixin/mechanics/entities/EndermanEntityMixin.java +++ b/src/main/java/me/wurgo/practiceseedmod/mixin/mechanics/entities/EndermanEntityMixin.java @@ -1,6 +1,5 @@ package me.wurgo.practiceseedmod.mixin.mechanics.entities; -import me.wurgo.practiceseedmod.PracticeSeedMod; import me.wurgo.practiceseedmod.core.config.ConfigWrapper; import me.wurgo.practiceseedmod.core.config.ConfigWriter; import net.minecraft.entity.EntityType; @@ -20,7 +19,7 @@ protected EndermanEntityMixin(EntityType entityType, Wo @Override protected void dropLoot(DamageSource source, boolean causedByPlayer) { - if (PracticeSeedMod.running && new ConfigWrapper(ConfigWriter.INSTANCE).getBoolValue("guaranteeDrops", true)) { + if (new ConfigWrapper(ConfigWriter.INSTANCE).getBoolValue("guaranteeDrops", true)) { this.dropStack(new ItemStack(Items.ENDER_PEARL)); return; } diff --git a/src/main/resources/practiceseedmod.mixins.json b/src/main/resources/practiceseedmod.mixins.json index d39c8aa..b2886be 100644 --- a/src/main/resources/practiceseedmod.mixins.json +++ b/src/main/resources/practiceseedmod.mixins.json @@ -5,13 +5,14 @@ "compatibilityLevel": "JAVA_16", "client": [ "gui.CreateWorldScreenMixin", + "gui.DebugHudMixin", "gui.GameMenuScreenMixin", + "gui.TitleScreenMixin", "core.CommandManagerMixin", "core.MinecraftClientMixin", "core.MinecraftServerMixin", "core.ServerChunkManagerMixin", - "gui.TitleScreenMixin", "mechanics.blocks.GravelBlockMixin",