Skip to content

Commit

Permalink
Don't assume that all ButtonWidgets have text associated with them
Browse files Browse the repository at this point in the history
  • Loading branch information
BluCobalt committed Aug 2, 2024
1 parent 1eecef8 commit c73c7d4
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
- name: Ensure gradlew is executable
run: chmod +x gradlew
Expand Down
9 changes: 4 additions & 5 deletions base/src/main/java/dev/blucobalt/realmsfix/Entrypoint.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* This file is part of realmsfix.
*
* <p>
* realmsfix is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* <p>
* realmsfix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with realmsfix. If not, see <http://www.gnu.org/licenses/>.
*/
Expand All @@ -29,11 +29,10 @@
public class Entrypoint
implements PreLaunchEntrypoint
{
private static final HashMap<String, String> VERSION_MAP;
private static final HashMap<String, String> VERSION_MAP = new HashMap<>();
private static final Logger LOGGER = LogManager.getLogger("realmsfix");

static {
VERSION_MAP = new HashMap<>();
VERSION_MAP.put("1.21", "1.21");
VERSION_MAP.put("1.20", "1.20.4");
VERSION_MAP.put("1.19", "1.19.4");
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx8G
org.gradle.caching=true
#fabric.loom.multiProjectOptimisation=true

version = 2.0.4
version = 2.0.5
yarn_1_21 = 1.21+build.7
yarn_1_20_4 = 1.20.4+build.3
yarn_1_19_4 = 1.19.4+build.2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* This file is part of realmsfix.
*
* <p>
* realmsfix is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* <p>
* realmsfix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with realmsfix. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -44,14 +44,17 @@ public void donothing(int y, int spacingY, CallbackInfo ci)
TitleScreenAccessor1_19_4 ts = (TitleScreenAccessor1_19_4) MinecraftClient.getInstance().currentScreen;
List<Drawable> drawables = ts.getDrawables();
for (Drawable drawable : drawables) {
if (drawable instanceof ButtonWidget){
ButtonWidget buttonWidget = (ButtonWidget) drawable;
Text message = buttonWidget.getMessage();
if (drawable instanceof ButtonWidget button) {
Text message = button.getMessage();
MutableText t = (MutableText) message;
TranslatableTextAccessor1_19_4 accessor = (TranslatableTextAccessor1_19_4) t.getContent();
if (accessor.getKey().equals("menu.online")){
((ButtonWidget) drawable).visible = false;
}

try {
TranslatableTextAccessor1_19_4 accessor = (TranslatableTextAccessor1_19_4) t.getContent();
if (accessor.getKey().equals("menu.online")) {
((ButtonWidget) drawable).visible = false;
}
} catch (ClassCastException ignored)
{}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* This file is part of realmsfix.
*
* <p>
* realmsfix is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* <p>
* realmsfix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with realmsfix. If not, see <http://www.gnu.org/licenses/>.
*/
Expand All @@ -28,7 +28,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

Expand All @@ -44,14 +43,17 @@ public void donothing(int y, int spacingY, CallbackInfo ci)
TitleScreenAccessor1_20_4 ts = (TitleScreenAccessor1_20_4) MinecraftClient.getInstance().currentScreen;
List<Drawable> drawables = ts.getDrawables();
for (Drawable drawable : drawables) {
if (drawable instanceof ButtonWidget){
ButtonWidget buttonWidget = (ButtonWidget) drawable;
Text message = buttonWidget.getMessage();
if (drawable instanceof ButtonWidget button) {
Text message = button.getMessage();
MutableText t = (MutableText) message;
TranslatableTextAccessor1_20_4 accessor = (TranslatableTextAccessor1_20_4) t.getContent();
if (accessor.getKey().equals("menu.online")){
((ButtonWidget) drawable).visible = false;
}

try {
TranslatableTextAccessor1_20_4 accessor = (TranslatableTextAccessor1_20_4) t.getContent();
if (accessor.getKey().equals("menu.online")) {
((ButtonWidget) drawable).visible = false;
}
} catch (ClassCastException ignored)
{}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"required": true,
"minVersion": "0.8",
"package": "dev.blucobalt.realmsfix.mixin",
"compatibilityLevel": "JAVA_8",
"compatibilityLevel": "JAVA_17",
"injectors": {
"defaultRequire": 1
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* This file is part of realmsfix.
*
* <p>
* realmsfix is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* <p>
* realmsfix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with realmsfix. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -39,18 +39,22 @@ public class TitleScreenMixin1_21
@Inject(method = "initWidgetsNormal", at = @At(value = "TAIL"))
public void donothing(int y, int spacingY, CallbackInfo ci)
{
if (MinecraftClient.getInstance().currentScreen instanceof TitleScreen){
if (MinecraftClient.getInstance().currentScreen instanceof TitleScreen) {
TitleScreenAccessor1_21 ts = (TitleScreenAccessor1_21) MinecraftClient.getInstance().currentScreen;
List<Drawable> drawables = ts.getDrawables();

for (Drawable drawable : drawables) {
if (drawable instanceof ButtonWidget){
ButtonWidget buttonWidget = (ButtonWidget) drawable;
Text message = buttonWidget.getMessage();
if (drawable instanceof ButtonWidget button) {
Text message = button.getMessage();
MutableText t = (MutableText) message;
TranslatableTextAccessor1_21 accessor = (TranslatableTextAccessor1_21) t.getContent();
if (accessor.getKey().equals("menu.online")){
((ButtonWidget) drawable).visible = false;
}

try {
TranslatableTextAccessor1_21 accessor = (TranslatableTextAccessor1_21) t.getContent();
if (accessor.getKey().equals("menu.online")) {
((ButtonWidget) drawable).visible = false;
}
} catch (ClassCastException ignored)
{}
}
}
}
Expand Down

0 comments on commit c73c7d4

Please sign in to comment.