[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,48 @@
|
||||
--- 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
|
||||
@@ -179,6 +179,7 @@
|
||||
@Override
|
||||
public void render(@NotNull GuiGraphics matrices, int mouseX, int mouseY, float delta) {
|
||||
overlayBackground(matrices.pose(), TOP, height - BOTTOM, 32);
|
||||
+
|
||||
renderScrollBar();
|
||||
|
||||
matrices.pose().pushPose();
|
||||
@@ -187,9 +188,8 @@
|
||||
overlayBackground(matrices.pose(), height - BOTTOM, height, 64);
|
||||
renderShadow(matrices.pose());
|
||||
matrices.drawCenteredString(font, getTitle(), width / 2, 9, 0xFFFFFF);
|
||||
- matrices.pose().popPose();
|
||||
-
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
+ matrices.pose().popPose();
|
||||
|
||||
int y = (int) (TOP + 4 - Math.round(scrollerAmount));
|
||||
for (Option<?> option : options) {
|
||||
@@ -268,9 +268,9 @@
|
||||
protected void overlayBackground(Matrix4f matrix, int minX, int minY, int maxX, int maxY, int red, int green, int blue, int startAlpha, int endAlpha) {
|
||||
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);
|
||||
+ RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
||||
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();
|
||||
buffer.vertex(matrix, maxX, maxY, 0.0F).uv(maxX / 32.0F, maxY / 32.0F).color(red, green, blue, endAlpha).endVertex();
|
||||
@@ -334,12 +334,12 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
- public boolean mouseScrolled(double d, double e, double f, double g) {
|
||||
+ public boolean mouseScrolled(double d, double e, double f) {
|
||||
if (e >= TOP && e <= height - BOTTOM) {
|
||||
scrollerAmount = Mth.clamp(scrollerAmount - f * 16.0D, 0, scrollHeight());
|
||||
return true;
|
||||
}
|
||||
- return super.mouseScrolled(d, e, f, g);
|
||||
+ return super.mouseScrolled(d, e, f);
|
||||
}
|
||||
|
||||
@Override
|
@@ -0,0 +1,28 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/InternalConfigButton.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/InternalConfigButton.java
|
||||
@@ -6,6 +6,7 @@
|
||||
import net.minecraft.client.gui.narration.NarratedElementType;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
import net.minecraft.network.chat.Component;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
@@ -22,7 +23,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
- protected void renderWidget(GuiGraphics arg, int i, int j, float f) {
|
||||
+ public void render(@NotNull GuiGraphics poseStack, int i, int j, float f) {
|
||||
if (cancel) {
|
||||
setMessage(Component.translatable(screen.isEdited() ? "t.clc.cancel_discard" : "gui.cancel"));
|
||||
} else {
|
||||
@@ -30,7 +31,7 @@
|
||||
active = screen.isEdited() && !hasErrors;
|
||||
setMessage(Component.translatable(hasErrors ? "t.clc.error" : "t.clc.save"));
|
||||
}
|
||||
- super.renderWidget(arg, i, j, f);
|
||||
+ super.render(poseStack, i, j, f);
|
||||
}
|
||||
|
||||
@Override
|
@@ -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,26 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/PlayerAdvancementsMixin.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/PlayerAdvancementsMixin.java
|
||||
@@ -5,7 +5,6 @@
|
||||
import com.hypherionmc.craterlib.nojang.advancements.BridgedAdvancement;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
-import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -21,11 +20,10 @@
|
||||
private ServerPlayer player;
|
||||
|
||||
@Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = At.Shift.AFTER))
|
||||
- private void injectAdvancementEvent(AdvancementHolder advancementHolder, String string, CallbackInfoReturnable<Boolean> cir) {
|
||||
- Advancement advancement = advancementHolder.value();
|
||||
+ private void injectAdvancementEvent(Advancement advancement, String string, CallbackInfoReturnable<Boolean> cir) {
|
||||
+ if (advancement.getDisplay() == null || !advancement.getDisplay().shouldAnnounceChat())
|
||||
+ return;
|
||||
|
||||
- if (advancement.display().isPresent() && advancement.display().get().shouldAnnounceChat()) {
|
||||
- CraterEventBus.INSTANCE.postEvent(new CraterAdvancementEvent(BridgedPlayer.of(this.player), BridgedAdvancement.of(advancementHolder.value())));
|
||||
- }
|
||||
+ CraterEventBus.INSTANCE.postEvent(new CraterAdvancementEvent(BridgedPlayer.of(this.player), BridgedAdvancement.of(advancement)));
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/PlayerListMixin.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/PlayerListMixin.java
|
||||
@@ -11,7 +11,6 @@
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
-import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -33,7 +32,7 @@
|
||||
}
|
||||
|
||||
@Inject(method = "placeNewPlayer", at = @At("TAIL"))
|
||||
- private void injectPlayerLoginEvent(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) {
|
||||
+ private void injectPlayerLoginEvent(Connection arg, ServerPlayer serverPlayer, CallbackInfo ci) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer)));
|
||||
}
|
||||
|
@@ -0,0 +1,11 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/ClientLevelMixin.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/ClientLevelMixin.java
|
||||
@@ -15,7 +15,7 @@
|
||||
public class ClientLevelMixin {
|
||||
|
||||
@Inject(method = "addEntity", at = @At("HEAD"))
|
||||
- private void injectSinglePlayerJoinEvent(Entity entity, CallbackInfo ci) {
|
||||
+ private void injectSinglePlayerJoinEvent(int i, Entity entity, CallbackInfo ci) {
|
||||
if (entity instanceof Player player) {
|
||||
CraterSinglePlayerEvent.PlayerLogin playerLogin = new CraterSinglePlayerEvent.PlayerLogin(BridgedPlayer.of(player));
|
||||
CraterEventBus.INSTANCE.postEvent(playerLogin);
|
@@ -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 void play(RealmsServer serverData, Screen arg2, CallbackInfo ci) {
|
||||
PlayerJoinRealmEvent playerJoinRealm = new PlayerJoinRealmEvent(BridgedRealmsServer.of(serverData));
|
||||
CraterEventBus.INSTANCE.postEvent(playerJoinRealm);
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/advancements/BridgedAdvancement.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/advancements/BridgedAdvancement.java
|
||||
@@ -11,8 +11,8 @@
|
||||
private final Advancement internal;
|
||||
|
||||
public Optional<BridgedDisplayInfo> displayInfo() {
|
||||
- if (internal.display().isPresent()) {
|
||||
- return Optional.of(BridgedDisplayInfo.of(internal.display().get()));
|
||||
+ if (internal.getDisplay() != null) {
|
||||
+ return Optional.of(BridgedDisplayInfo.of(internal.getDisplay()));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
@@ -0,0 +1,11 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java
|
||||
@@ -35,7 +35,7 @@
|
||||
}
|
||||
|
||||
public boolean isRealmServer() {
|
||||
- return internal.getCurrentServer() != null && internal.getCurrentServer().isRealm();
|
||||
+ return internal.getCurrentServer() != null && internal.isConnectedToRealms();
|
||||
}
|
||||
|
||||
public boolean isSinglePlayer() {
|
@@ -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