Skip to content

Commit

Permalink
Clean up @djlawler 's mixin, bump version to 2.0.0 for stable release
Browse files Browse the repository at this point in the history
  • Loading branch information
triphora committed Jun 27, 2021
1 parent 398587c commit 8e01b4e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 33 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ yarn_mappings=11
loader_version=0.11.6
fabric_version=0.36.0+1.17
# Mod Properties
mod_version=2.0.0-alpha.3-SNAPSHOT
mod_version=2.0.0
maven_group=dev.frydae
archives_base_name=empire-minecraft-utilities
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public class ConnectScreenMixin {
@Inject(method = "connect(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/network/ServerAddress;)V", at = @At(value = "HEAD"))
public void onConnect(MinecraftClient client, ServerAddress address, CallbackInfo ci) {
Util.setServerAddress(String.valueOf(address));
// Util.IS_ON_EMC = address.equals(".*.emc.gs?.");
Util.IS_ON_EMC = address.getAddress().matches(".*.emc.gs?.");
}
}
37 changes: 7 additions & 30 deletions src/main/java/dev/frydae/emcutils/mixins/MinecraftClientMixin.java
Original file line number Diff line number Diff line change
@@ -1,64 +1,41 @@
package dev.frydae.emcutils.mixins;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.DeathScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.sound.SoundManager;
import net.minecraft.client.util.Window;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
//import dev.frydae.emcutils.utils.Log;
import dev.frydae.emcutils.features.vaultButtons.VaultScreen;

@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
@Shadow
private SoundManager soundManager;
@Final
@Shadow
private Window window;

@Inject(at = @At("INVOKE"), method = "openScreen", cancellable = true)
public void onOpenScreen(@Nullable Screen screen, CallbackInfo ci) {
//Log.info("MinecraftClient openScreen called!");
if (!(screen instanceof VaultScreen)) {
//Log.info("openScreen NOT for VaultScreen");
return;
}

//Log.info("openScreen just for VaultScreen");
MinecraftClient mc = (MinecraftClient) (Object) this;

if (mc.currentScreen != null) {
mc.currentScreen.removed();
}

if (screen == null && mc.world == null) {
screen = new TitleScreen();
} else if (screen == null && mc.player.isDead()) {
if (mc.player.showsDeathScreen()) {
screen = new DeathScreen((Text)null, mc.world.getLevelProperties().isHardcore());
} else {
mc.player.requestRespawn();
}
}

mc.currentScreen = (Screen) screen;
if (screen != null) {
mc.mouse.unlockCursor();
KeyBinding.unpressAll();
((Screen)screen).init(mc, window.getScaledWidth(), window.getScaledHeight());
mc.skipGameRender = false;
} else {
soundManager.resumeAll();
mc.mouse.lockCursor();
}
mc.currentScreen = screen;
mc.mouse.unlockCursor();
KeyBinding.unpressAll();
screen.init(mc, window.getScaledWidth(), window.getScaledHeight());
mc.skipGameRender = false;

mc.updateWindowTitle();
ci.cancel();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/frydae/emcutils/utils/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.stream.Collectors;

public class Util {
public static boolean IS_ON_EMC = true;
public static boolean IS_ON_EMC = false;
@Getter
@Setter
private static String serverAddress;
Expand Down

0 comments on commit 8e01b4e

Please sign in to comment.