nosingleplayer: fix crash Shadow (listes+accesseur), retire RenderMixin en double
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
package fr.surviepote.nosingleplayer.mixin;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.components.Renderable;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(Screen.class)
|
||||
public interface ScreenAccessor {
|
||||
|
||||
@Accessor("renderables")
|
||||
List<Renderable> surviepote$getRenderables();
|
||||
}
|
||||
+35
-27
@@ -2,22 +2,23 @@ package fr.surviepote.nosingleplayer.mixin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.FriendsButton;
|
||||
import net.minecraft.client.gui.components.PlainTextButton;
|
||||
import net.minecraft.client.gui.components.SpriteIconButton;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||
import net.minecraft.client.gui.components.Renderable;
|
||||
import net.minecraft.client.gui.screens.ConnectScreen;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.multiplayer.TransferState;
|
||||
import net.minecraft.client.multiplayer.resolver.ServerAddress;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import fr.surviepote.nosingleplayer.NoSingleplayer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@@ -27,14 +28,11 @@ public abstract class TitleScreenMixin {
|
||||
|
||||
private static final String SERVER_HOST = "mcpv.ihorizon.org:25565";
|
||||
|
||||
@Shadow
|
||||
protected int width;
|
||||
|
||||
@Shadow
|
||||
protected int height;
|
||||
|
||||
@Shadow
|
||||
protected abstract <T extends GuiEventListener & Renderable & NarratableEntry> T addRenderableWidget(T widget);
|
||||
@Unique
|
||||
private static void surviepote$removeWidget(TitleScreen self, GuiEventListener widget) {
|
||||
self.children().remove(widget);
|
||||
((ScreenAccessor) self).surviepote$getRenderables().remove(widget);
|
||||
}
|
||||
|
||||
@Inject(method = "init", at = @At("TAIL"))
|
||||
private void surviepote$customizeMenu(CallbackInfo ci) {
|
||||
@@ -45,12 +43,12 @@ public abstract class TitleScreenMixin {
|
||||
String multi = Component.translatable("menu.multiplayer").getString();
|
||||
String realms = Component.translatable("menu.online").getString();
|
||||
|
||||
int joinX = this.width / 2 - 100;
|
||||
int joinY = this.height / 4 + 72;
|
||||
int joinX = minecraft.getWindow().getGuiScaledWidth() / 2 - 100;
|
||||
int joinY = minecraft.getWindow().getGuiScaledHeight() / 4 + 72;
|
||||
boolean foundMulti = false;
|
||||
|
||||
List<SpriteIconButton> iconButtons = new ArrayList<>();
|
||||
for (GuiEventListener child : self.children()) {
|
||||
List<GuiEventListener> toRemove = new ArrayList<>();
|
||||
for (GuiEventListener child : new ArrayList<>(self.children())) {
|
||||
if (child instanceof Button button) {
|
||||
String msg = button.getMessage().getString();
|
||||
if (msg.equals(solo)) {
|
||||
@@ -59,28 +57,38 @@ public abstract class TitleScreenMixin {
|
||||
joinX = button.getX();
|
||||
joinY = button.getY();
|
||||
foundMulti = true;
|
||||
button.visible = false;
|
||||
toRemove.add(button);
|
||||
} else if (msg.equals(realms)) {
|
||||
button.visible = false;
|
||||
toRemove.add(button);
|
||||
}
|
||||
} else if (child instanceof FriendsButton) {
|
||||
((AbstractWidget) child).visible = false;
|
||||
} else if (child instanceof SpriteIconButton iconButton) {
|
||||
iconButtons.add(iconButton);
|
||||
toRemove.add(child);
|
||||
} else if (child instanceof SpriteIconButton) {
|
||||
// Bas-gauche : langue, accessibilité, etc.
|
||||
toRemove.add(child);
|
||||
} else if (child instanceof PlainTextButton) {
|
||||
// Copyright Mojang cliquable en bas.
|
||||
toRemove.add(child);
|
||||
}
|
||||
}
|
||||
// Bas-gauche : langue + accessibilité (icônes).
|
||||
for (SpriteIconButton iconButton : iconButtons) {
|
||||
iconButton.visible = false;
|
||||
for (GuiEventListener widget : toRemove) {
|
||||
surviepote$removeWidget(self, widget);
|
||||
}
|
||||
// RealmsNotificationsScreen : rendu annulé via RealmsNotificationsMixin.
|
||||
|
||||
|
||||
Button join = Button.builder(Component.literal("Rejoindre SurviePote"), pressed -> {
|
||||
ServerData data = new ServerData("SurviePote", SERVER_HOST, ServerData.Type.OTHER);
|
||||
ConnectScreen.startConnecting(self, minecraft, ServerAddress.parseString(SERVER_HOST), data, false, null);
|
||||
ConnectScreen.startConnecting(self, minecraft, ServerAddress.parseString(SERVER_HOST), data, false,
|
||||
new TransferState(Map.of(), Map.of(), false));
|
||||
}).bounds(joinX, joinY, 200, 20).build();
|
||||
this.addRenderableWidget(join); if (!foundMulti) {
|
||||
((ScreenAccessor) self).surviepote$getRenderables().add(join);
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
List rawChildren = (List) self.children();
|
||||
rawChildren.add(join);
|
||||
if (join instanceof AbstractWidget w) {
|
||||
w.visible = true;
|
||||
w.active = true;
|
||||
}
|
||||
if (!foundMulti) {
|
||||
NoSingleplayer.LOGGER.warn("[SurviePote] Bouton Multi introuvable, Join placé par défaut.");
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 629 KiB |
@@ -2,7 +2,12 @@
|
||||
"required": true,
|
||||
"package": "fr.surviepote.nosingleplayer.mixin",
|
||||
"compatibilityLevel": "JAVA_25",
|
||||
"client": ["TitleScreenMixin", "TitleScreenTextMixin", "RealmsNotificationsMixin"],
|
||||
"client": [
|
||||
"TitleScreenMixin",
|
||||
"TitleScreenTextMixin",
|
||||
"RealmsNotificationsMixin",
|
||||
"ScreenAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user