-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
813 additions
and
17 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/main/java/io/github/gaming32/worldhost/DeferredToastManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.github.gaming32.worldhost; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.components.toasts.SystemToast; | ||
import net.minecraft.network.chat.CommonComponents; | ||
import net.minecraft.network.chat.Component; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class DeferredToastManager { | ||
@Nullable | ||
public static IconRenderer queuedCustomIcon; | ||
|
||
@FunctionalInterface | ||
public interface IconRenderer { | ||
void draw(PoseStack matrices, int x, int y); | ||
} | ||
|
||
private record ToastInfo(SystemToast.SystemToastIds type, IconRenderer icon, Component title, @Nullable Component description) { | ||
} | ||
|
||
private static List<ToastInfo> deferredToasts = new ArrayList<>(); | ||
|
||
public static void show(SystemToast.SystemToastIds type, Component title, @Nullable Component description) { | ||
show(type, null, title, description); | ||
} | ||
|
||
public static void show(SystemToast.SystemToastIds type, IconRenderer icon, Component title, @Nullable Component description) { | ||
final ToastInfo toast = new ToastInfo(type, icon, title, description); | ||
if (deferredToasts != null) { | ||
deferredToasts.add(toast); | ||
} else { | ||
show(toast); | ||
} | ||
} | ||
|
||
private static void show(ToastInfo toast) { | ||
Minecraft.getInstance().execute(() -> { | ||
queuedCustomIcon = toast.icon; | ||
SystemToast.addOrUpdate( | ||
Minecraft.getInstance().getToasts(), toast.type, toast.title, | ||
Objects.requireNonNullElse(toast.description, CommonComponents.EMPTY) | ||
); | ||
}); | ||
} | ||
|
||
public static void ready() { | ||
if (deferredToasts != null) { | ||
deferredToasts.forEach(DeferredToastManager::show); | ||
deferredToasts = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/io/github/gaming32/worldhost/mixin/MixinMinecraft.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.gaming32.worldhost.mixin; | ||
|
||
import io.github.gaming32.worldhost.DeferredToastManager; | ||
import io.github.gaming32.worldhost.WorldHost; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.screens.Overlay; | ||
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.CallbackInfo; | ||
|
||
@Mixin(Minecraft.class) | ||
public class MixinMinecraft { | ||
@Inject(method = "setOverlay", at = @At("HEAD")) | ||
private void deferredToastReady(Overlay loadingGui, CallbackInfo ci) { | ||
if (loadingGui == null) { | ||
DeferredToastManager.ready(); | ||
} | ||
} | ||
|
||
@Inject(method = "tick", at = @At("RETURN")) | ||
private void tickEvent(CallbackInfo ci) { | ||
//noinspection DataFlowIssue | ||
WorldHost.tickHandler((Minecraft)(Object)this); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/io/github/gaming32/worldhost/protocol/JoinType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.github.gaming32.worldhost.protocol; | ||
|
||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
|
||
public sealed interface JoinType { | ||
record UPnP(int port) implements JoinType { | ||
@Override | ||
public void encode(DataOutputStream dos) throws IOException { | ||
dos.writeByte(0); | ||
dos.writeShort(port); | ||
} | ||
} | ||
|
||
enum Proxy implements JoinType { | ||
INSTANCE; | ||
|
||
@Override | ||
public void encode(DataOutputStream dos) throws IOException { | ||
dos.writeByte(1); | ||
} | ||
} | ||
|
||
void encode(DataOutputStream dos) throws IOException; | ||
} |
Oops, something went wrong.