[NO-ORBIT] Unified Porting Branch
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/api/networking/CommonPacketWrapper.java
|
||||
+++ /dev/null
|
||||
@@ -1,19 +1,0 @@
|
||||
-package com.hypherionmc.craterlib.api.networking;
|
||||
-
|
||||
-import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||
-import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
-import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
-
|
||||
-public record CommonPacketWrapper<T>(PacketHolder<T> container, T packet) implements CustomPacketPayload
|
||||
-{
|
||||
- public void encode(BridgedFriendlyByteBuf buf)
|
||||
- {
|
||||
- container().encoder().accept(packet(), buf);
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public Type<? extends CustomPacketPayload> type()
|
||||
- {
|
||||
- return container.type();
|
||||
- }
|
||||
-}
|
@@ -0,0 +1,11 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/CraterConfigScreen.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/CraterConfigScreen.java
|
||||
@@ -269,7 +269,7 @@
|
||||
Tesselator tesselator = Tesselator.getInstance();
|
||||
BufferBuilder buffer = tesselator.getBuilder();
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
||||
- RenderSystem.setShaderTexture(0, Screen.MENU_BACKGROUND);
|
||||
+ RenderSystem.setShaderTexture(0, Screen.BACKGROUND_LOCATION);
|
||||
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||
buffer.vertex(matrix, minX, maxY, 0.0F).uv(minX / 32.0F, maxY / 32.0F).color(red, green, blue, endAlpha).endVertex();
|
@@ -0,0 +1,43 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/core/networking/data/PacketHolder.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/core/networking/data/PacketHolder.java
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.hypherionmc.craterlib.core.networking.data;
|
||||
|
||||
-import com.hypherionmc.craterlib.api.networking.CommonPacketWrapper;
|
||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
||||
-import net.minecraft.network.FriendlyByteBuf;
|
||||
-import net.minecraft.network.codec.StreamCodec;
|
||||
-import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
@@ -14,27 +10,9 @@
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
-public record PacketHolder<T>(CustomPacketPayload.Type<? extends CustomPacketPayload> type,
|
||||
+public record PacketHolder<T>(ResourceIdentifier type,
|
||||
Class<T> messageType,
|
||||
BiConsumer<T, BridgedFriendlyByteBuf> encoder,
|
||||
Function<BridgedFriendlyByteBuf, T> decoder,
|
||||
Consumer<PacketContext<T>> handler) {
|
||||
-
|
||||
- public PacketHolder(ResourceIdentifier packetId, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||
- this(new CustomPacketPayload.Type<>(packetId.toMojang()), messageType, encoder, decoder, handler);
|
||||
- }
|
||||
-
|
||||
- @SuppressWarnings("unchecked")
|
||||
- public <K extends CustomPacketPayload> CustomPacketPayload.Type<K> getType()
|
||||
- {
|
||||
- return (CustomPacketPayload.Type<K>) type();
|
||||
- }
|
||||
-
|
||||
- public StreamCodec<FriendlyByteBuf, CommonPacketWrapper> getCodec()
|
||||
- {
|
||||
- return CustomPacketPayload.codec(
|
||||
- (packet, buf) -> this.encoder().accept((T)packet.packet(), BridgedFriendlyByteBuf.of(buf)),
|
||||
- (buf) -> new CommonPacketWrapper<>(this, this.decoder().apply(BridgedFriendlyByteBuf.of(buf))));
|
||||
- }
|
||||
-
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/CommandMixin.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/CommandMixin.java
|
||||
@@ -9,28 +9,28 @@
|
||||
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;
|
||||
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(Commands.class)
|
||||
public class CommandMixin {
|
||||
|
||||
@Inject(method = "performCommand",
|
||||
at = @At(value = "INVOKE",
|
||||
- target = "Lnet/minecraft/commands/Commands;finishParsing(Lcom/mojang/brigadier/ParseResults;Ljava/lang/String;Lnet/minecraft/commands/CommandSourceStack;)Lcom/mojang/brigadier/context/ContextChain;",
|
||||
+ target = "Lcom/mojang/brigadier/CommandDispatcher;execute(Lcom/mojang/brigadier/ParseResults;)I",
|
||||
shift = At.Shift.BEFORE
|
||||
), cancellable = true
|
||||
)
|
||||
- private void injectCommandEvent(ParseResults<CommandSourceStack> stackParseResults, String command, CallbackInfo ci) {
|
||||
+ private void injectCommandEvent(ParseResults<CommandSourceStack> stackParseResults, String command, CallbackInfoReturnable<Integer> cir) {
|
||||
CraterCommandEvent commandEvent = CraterCommandEvent.of(stackParseResults, command);
|
||||
CraterEventBus.INSTANCE.postEvent(commandEvent);
|
||||
if (commandEvent.wasCancelled()) {
|
||||
- ci.cancel();
|
||||
+ cir.setReturnValue(1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (commandEvent.getException() != null) {
|
||||
Throwables.throwIfUnchecked(commandEvent.getException());
|
||||
- ci.cancel();
|
||||
+ cir.setReturnValue(1);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,13 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/RealmsMainScreenMixin.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/RealmsMainScreenMixin.java
|
||||
@@ -14,8 +14,8 @@
|
||||
@Mixin(RealmsMainScreen.class)
|
||||
public class RealmsMainScreenMixin {
|
||||
|
||||
- @Inject(at = @At("HEAD"), method = "play(Lcom/mojang/realmsclient/dto/RealmsServer;Lnet/minecraft/client/gui/screens/Screen;Z)V")
|
||||
- private static void play(RealmsServer serverData, Screen arg2, boolean bl, CallbackInfo ci) {
|
||||
+ @Inject(at = @At("HEAD"), method = "play")
|
||||
+ private static void play(RealmsServer serverData, Screen arg2, CallbackInfo ci) {
|
||||
PlayerJoinRealmEvent playerJoinRealm = new PlayerJoinRealmEvent(BridgedRealmsServer.of(serverData));
|
||||
CraterEventBus.INSTANCE.postEvent(playerJoinRealm);
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java
|
||||
@@ -24,9 +24,9 @@
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
- if (internal.players == null) {
|
||||
+ if (!internal.pinged || internal.players == null) {
|
||||
try {
|
||||
- new ServerStatusPinger().pingServer(internal, () -> {}, () -> {});
|
||||
+ new ServerStatusPinger().pingServer(internal, () -> {});
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
@@ -0,0 +1,37 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/utils/ChatUtils.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/utils/ChatUtils.java
|
||||
@@ -5,22 +5,29 @@
|
||||
import me.hypherionmc.mcdiscordformatter.minecraft.MinecraftSerializer;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
+import net.kyori.adventure.text.serializer.json.JSONOptions;
|
||||
+import net.kyori.option.OptionState;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.Util;
|
||||
-import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
|
||||
public class ChatUtils {
|
||||
|
||||
+ private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().options(
|
||||
+ OptionState.optionState()
|
||||
+ .value(JSONOptions.EMIT_HOVER_SHOW_ENTITY_ID_AS_INT_ARRAY, false)
|
||||
+ .value(JSONOptions.EMIT_HOVER_EVENT_TYPE, JSONOptions.HoverEventValueMode.MODERN_ONLY).build()
|
||||
+ ).build();
|
||||
+
|
||||
public static Component adventureToMojang(net.kyori.adventure.text.Component inComponent) {
|
||||
- final String serialised = GsonComponentSerializer.gson().serialize(inComponent);
|
||||
- return Component.Serializer.fromJson(serialised, RegistryAccess.EMPTY);
|
||||
+ final String serialised = adventureSerializer.serialize(inComponent);
|
||||
+ return Component.Serializer.fromJson(serialised);
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.Component mojangToAdventure(Component inComponent) {
|
||||
- final String serialised = Component.Serializer.toJson(inComponent, RegistryAccess.EMPTY);
|
||||
- return GsonComponentSerializer.gson().deserialize(serialised);
|
||||
+ final String serialised = Component.Serializer.toJson(inComponent);
|
||||
+ return adventureSerializer.deserialize(serialised);
|
||||
}
|
||||
|
||||
// Some text components contain duplicate text, resulting in duplicate messages
|
Reference in New Issue
Block a user