Skip to content

Commit

Permalink
Migrate to 1.16 pre-release 8
Browse files Browse the repository at this point in the history
  • Loading branch information
axieum committed Jun 18, 2020
1 parent 7393d5c commit 91ce2bc
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 61 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Fabric
MINECRAFT_VERSION = 1.15.2
FABRIC_API_VERSION = 0.12.0+build.313-1.15
MINECRAFT_VERSION = 1.16-pre8
FABRIC_API_VERSION = 0.12.4+build.365-1.16
FABRIC_LOADER_VERSION = 0.8.7+build.201
YARN_MAPPINGS = 1.15.2+build.17
YARN_MAPPINGS = 1.16-pre8+build.2

# Mod
MOD_ID = authme
MOD_GROUP = me.axieum.mcmod.authme
MOD_CLASS = AuthMe
MOD_VERSION = 1.1.2
MOD_VERSION = 1.2.1-pre

# Other
org.gradle.jvmargs = -Xmx3G
Expand Down
94 changes: 51 additions & 43 deletions src/main/java/me/axieum/mcmod/authme/gui/AuthScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import com.mojang.authlib.exceptions.InvalidCredentialsException;
import me.axieum.mcmod.authme.gui.widget.PasswordFieldWidget;
import me.axieum.mcmod.authme.util.SessionUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.Session;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
Expand All @@ -28,7 +26,7 @@ public AuthScreen(Screen parentScreen)
{
super(new TranslatableText("gui.authme.auth.title"));
this.parentScreen = parentScreen;
minecraft = MinecraftClient.getInstance();
// this.client = MinecraftClient.getInstance();
lastUsername = SessionUtil.getSession().getUsername();
greeting = getGreeting(lastUsername);
}
Expand All @@ -37,15 +35,15 @@ public AuthScreen(Screen parentScreen)
protected void init()
{
super.init();
minecraft.keyboard.enableRepeatEvents(true);
this.client.keyboard.enableRepeatEvents(true);

// Username Text Field
usernameField = new TextFieldWidget(font,
usernameField = new TextFieldWidget(this.client.textRenderer,
width / 2 - 100,
76,
200,
20,
I18n.translate("gui.authme.auth.field.username"));
new TranslatableText("gui.authme.auth.field.username"));
usernameField.setMaxLength(128);
usernameField.setSuggestion(lastUsername); // Suggest their current username
usernameField.setChangedListener(value -> {
Expand All @@ -57,20 +55,19 @@ protected void init()
children.add(usernameField);

// Password Text Field
passwordField = new PasswordFieldWidget(font,
passwordField = new PasswordFieldWidget(this.client.textRenderer,
width / 2 - 100,
116,
200,
20,
I18n.translate("gui.authme.auth.field.password"));
passwordField.changeFocus(true); // Focus password initially (as we've already suggested a username)
new TranslatableText("gui.authme.auth.field.password"));
passwordField.setChangedListener(value -> {
// Tweak the login button depending on if password is given or not
loginButton.setMessage(I18n.translate("gui.authme.auth.button.login."
+ (value.isEmpty() ? "offline" : "online")));
loginButton.setMessage(new TranslatableText("gui.authme.auth.button.login."
+ (value.isEmpty() ? "offline" : "online")));
loginButton.active = canSubmit();
// Reset the cancel button accordingly (after a successful login)
cancelButton.setMessage(I18n.translate("gui.authme.auth.button.cancel"));
cancelButton.setMessage(new TranslatableText("gui.authme.auth.button.cancel"));
});
children.add(passwordField);

Expand All @@ -79,7 +76,7 @@ protected void init()
height / 4 + 96 + 18,
200,
20,
I18n.translate("gui.authme.auth.button.login.offline"),
new TranslatableText("gui.authme.auth.button.login.offline"),
button -> submit());
loginButton.active = false;
addButton(loginButton);
Expand All @@ -89,7 +86,7 @@ protected void init()
height / 4 + 120 + 18,
200,
20,
I18n.translate("gui.authme.auth.button.cancel"),
new TranslatableText("gui.authme.auth.button.cancel"),
button -> onClose());
addButton(cancelButton);
}
Expand All @@ -104,13 +101,13 @@ public boolean shouldCloseOnEsc()
public void onClose()
{
passwordField.setText("");
minecraft.openScreen(parentScreen);
this.client.openScreen(parentScreen);
}

@Override
public void removed()
{
minecraft.keyboard.enableRepeatEvents(false);
this.client.keyboard.enableRepeatEvents(false);
}

/**
Expand All @@ -124,23 +121,33 @@ public void setMessage(Text message)
}

@Override
public void render(int mouseX, int mouseY, float delta)
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta)
{
renderBackground();
renderBackground(matrices);

drawCenteredString(font, title.asFormattedString(), width / 2, 17, 16777215);
drawCenteredString(font, greeting.asFormattedString(), width / 2, 34, 16777215);
drawCenteredText(matrices, this.client.textRenderer, title, width / 2, 17, 16777215);
drawCenteredText(matrices, this.client.textRenderer, greeting, width / 2, 34, 16777215);

if (message != null)
drawCenteredString(font, message.asFormattedString(), width / 2, height / 4 + 86, 16777215);

drawString(font, I18n.translate("gui.authme.auth.field.username"), width / 2 - 100, 64, 10526880);
drawString(font, I18n.translate("gui.authme.auth.field.password"), width / 2 - 100, 104, 10526880);

usernameField.render(mouseX, mouseY, delta);
passwordField.render(mouseX, mouseY, delta);

super.render(mouseX, mouseY, delta);
drawCenteredText(matrices, this.client.textRenderer, message, width / 2, height / 4 + 86, 16777215);

drawTextWithShadow(matrices,
this.client.textRenderer,
new TranslatableText("gui.authme.auth.field.username"),
width / 2 - 100,
64,
10526880);
drawTextWithShadow(matrices,
this.client.textRenderer,
new TranslatableText("gui.authme.auth.field.password"),
width / 2 - 100,
104,
10526880);

usernameField.render(matrices, mouseX, mouseY, delta);
passwordField.render(matrices, mouseX, mouseY, delta);

super.render(matrices, mouseX, mouseY, delta);
}

/**
Expand Down Expand Up @@ -169,15 +176,15 @@ public void submit()
// Play offline
Session offlineSession = SessionUtil.login(username);

lastUsername = offlineSession.getUsername();
greeting = getGreeting(lastUsername);
message = new TranslatableText("gui.authme.auth.message.success.offline")
.setStyle(new Style().setBold(true).setColor(Formatting.AQUA));
this.lastUsername = offlineSession.getUsername();
this.greeting = getGreeting(lastUsername);
this.message = new TranslatableText("gui.authme.auth.message.success.offline")
.styled(style -> style.withBold(true).withColor(Formatting.AQUA));

// Reset form
usernameField.setText("");
passwordField.setText("");
cancelButton.setMessage(I18n.translate("gui.authme.auth.button.return"));
cancelButton.setMessage(new TranslatableText("gui.authme.auth.button.return"));
} else {
// Login
SessionUtil.login(username, password)
Expand All @@ -188,25 +195,26 @@ public void submit()

// Set the message contents and style it as successful
message = new TranslatableText("gui.authme.auth.message.success")
.setStyle(new Style().setBold(true).setColor(Formatting.GREEN));
.styled(style -> style.withBold(true).withColor(Formatting.GREEN));

// Reset form
usernameField.setText("");
passwordField.setText("");
cancelButton.setMessage(I18n.translate("gui.authme.auth.button.return"));
cancelButton.setMessage(new TranslatableText("gui.authme.auth.button.return"));
})
.exceptionally(e -> {
// Failed login attempt
loginButton.active = true; // re-enable login button to try again with same credentials

// Set the message contents and style it as an error
final TranslatableText text;
if (e.getCause() instanceof InvalidCredentialsException)
message = new TranslatableText("gui.authme.auth.message.failed.credentials");
text = new TranslatableText("gui.authme.auth.message.failed.credentials");
else
message = new TranslatableText("gui.authme.auth.message.failed.generic",
e.getCause().getMessage());
text = new TranslatableText("gui.authme.auth.message.failed.generic",
e.getCause().getMessage());

message.setStyle(new Style().setBold(true).setColor(Formatting.RED));
this.message = text.styled(style -> style.withBold(true).withColor(Formatting.RED));

return null;
});
Expand All @@ -222,7 +230,7 @@ public void submit()
protected static Text getGreeting(String username)
{
return new TranslatableText("gui.authme.auth.greeting",
new LiteralText(username).setStyle(new Style().setColor(Formatting.YELLOW)))
.setStyle(new Style().setColor(Formatting.GRAY));
new LiteralText(username).styled(style -> style.withColor(Formatting.YELLOW)))
.styled(style -> style.withColor(Formatting.GRAY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

public class PasswordFieldWidget extends TextFieldWidget
{
public PasswordFieldWidget(TextRenderer font, int x, int y, int width, int height, String msg)
public PasswordFieldWidget(TextRenderer font, int x, int y, int width, int height, Text msg)
{
super(font, x, y, width, height, null, msg);
setMaxLength(256);
setRenderTextProvider((value, limit) -> Formatting.OBFUSCATED + value);

// // NB: Overriding the rendered characters affects interaction, as the
// // actual rendered characters have different widths to the actual text.
// setTextFormatter((value, limit) -> StringUtils.repeat('\u204E', value.length()));
// setRenderTextProvider((value, limit) -> StringUtils.repeat('\u204E', value.length()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
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;
Expand All @@ -19,9 +19,11 @@
public abstract class DisconnectedScreenMixin extends Screen
{
@Shadow
@Final
private Text reason;

@Shadow
@Final
private Screen parent;

protected DisconnectedScreenMixin(Text title) { super(title); }
Expand All @@ -40,8 +42,8 @@ private void init(CallbackInfo info)
backButton.y,
backButton.getWidth(),
20,
I18n.translate("gui.authme.disconnect.button.auth"),
button -> this.minecraft.openScreen(new AuthScreen(parent))));
new TranslatableText("gui.authme.disconnect.button.auth"),
button -> this.client.openScreen(new AuthScreen(parent))));

// Move back button below
backButton.y += 26;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -39,8 +40,8 @@ private void init(CallbackInfo info)
new Identifier("minecraft:textures/gui/widgets.png"),
256,
256,
button -> this.minecraft.openScreen(new AuthScreen(this)),
I18n.translate("gui.authme.multiplayer.button.auth"));
button -> this.client.openScreen(new AuthScreen(this)),
new TranslatableText("gui.authme.multiplayer.button.auth"));
this.addButton(authButton);

// Fetch current session status
Expand All @@ -49,13 +50,14 @@ private void init(CallbackInfo info)
}

@Inject(method = "render", at = @At("TAIL"))
public void render(int mouseX, int mouseY, float delta, CallbackInfo info)
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info)
{
// Draw status text/icon on button
this.drawString(this.minecraft.textRenderer,
Formatting.BOLD + status.toString(),
authButton.x + authButton.getWidth() - 6,
authButton.y - 1,
status.color);
this.drawCenteredString(matrices,
this.client.textRenderer,
Formatting.BOLD + status.toString(),
authButton.x + authButton.getWidth(),
authButton.y - 1,
status.color);
}
}

0 comments on commit 91ce2bc

Please sign in to comment.