Skip to content

Commit

Permalink
1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
faluhub committed Nov 17, 2022
1 parent 6e01a23 commit 87ff436
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 23 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 31 additions & 3 deletions src/main/java/me/wurgo/practiceseedmod/PracticeSeedMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -93,7 +96,7 @@ public static void playNextSeed(long l) {
GameMode.SURVIVAL,
false,
Difficulty.EASY,
true,
!isRace,
new GameRules(),
DataPackSettings.SAFE_MODE
);
Expand Down Expand Up @@ -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()) {
Expand All @@ -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!");
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
57 changes: 50 additions & 7 deletions src/main/java/me/wurgo/practiceseedmod/gui/LinkUUIDScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
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;

import java.util.UUID;

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:"));
Expand All @@ -26,41 +31,79 @@ 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
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<List<String>> cir) {
if (PracticeSeedMod.running) {
List<String> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public GravelBlockMixin(Settings settings) {

@Override
public List<ItemStack> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,7 +19,7 @@ protected EndermanEntityMixin(EntityType<? extends HostileEntity> 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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/practiceseedmod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down

0 comments on commit 87ff436

Please sign in to comment.