Skip to content

Fix errors in 1.19 #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 1.19-compat
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CompatManager() {
.addImplementation(12, 15, ChatPacketImpl12To15::new)
.addImplementation(16, 16, ChatPacketImpl16::new)
.addImplementation(17, 18, ChatPacketImpl17To18::new)
.addImplementation(17, Integer.MAX_VALUE, ChatPacketImpl19ToFuture::new)
.addImplementation(19, Integer.MAX_VALUE, ChatPacketImpl19ToFuture::new)
.getImplementation(version)
.orElseThrow(() -> new IllegalStateException(
"Missing ChatPacket implementation for major version: " + version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ChatComponentImpl19ToFuture() throws ClassNotFoundException, NoSuchMethod
Class<?> IChatBaseComponent_ChatSerializer = ReflectionHelper.getClass("net.minecraft.network.chat.IChatBaseComponent$ChatSerializer");

fromText = MethodHandles.lookup().unreflect(IChatBaseComponent.getMethod("b", String.class));
fromJson = MethodHandles.lookup().unreflect(IChatBaseComponent_ChatSerializer.getMethod("a", JsonElement.class, Type.class, JsonDeserializationContext.class));
fromJson = MethodHandles.lookup().unreflect(IChatBaseComponent_ChatSerializer.getMethod("a", String.class));
}

@Override
Expand All @@ -35,7 +35,7 @@ public Object createComponent(String message) {
@Override
public Object fromJson(JsonObject json) {
try {
return fromJson.invoke(json, null, null);
return fromJson.invoke(json.toString());
} catch (Throwable e) {
e.printStackTrace();
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,38 @@

public class ChatPacketImpl19ToFuture implements ChatPacketCompat {
private final Constructor<?> chatPacketContructor;
private static Object enumChatMessageTypeMessage;
private static Object enumChatMessageTypeActionbar;
private static int enumChatMessageTypeMessage;
private static int enumChatMessageTypeActionbar;

public ChatPacketImpl19ToFuture() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class<?> NMS_I_CHAT_BASE_COMPONENT = ReflectionHelper.getClass("net.minecraft.network.chat.IChatBaseComponent");
Class<?> NMS_CHAT_MESSAGE_TYPE = ReflectionHelper.getClass("net.minecraft.network.chat.ChatMessageType");
// Class<?> NMS_CHAT_MESSAGE_TYPE = ReflectionHelper.getClass("net.minecraft.network.chat.ChatMessageType");

// TODO: looks like it might need to use ClientboundPlayerChatPacket instead?
// here's the signature, unsure how to use it as of yet tho:
// public ClientboundPlayerChatPacket(PlayerChatMessage playerChatMessage, ChatMessageType.b boundNetwork) {
// this.a = playerChatMessage;
// this.b = boundNetwork;
// }
Class<?> NMS_PACKET_PLAY_OUT_CHAT = ReflectionHelper.getClass("net.minecraft.network.protocol.game.PacketPlayOutChat");
Class<?> NMS_PACKET_PLAY_OUT_CHAT = ReflectionHelper.getClass("net.minecraft.network.protocol.game.ClientboundSystemChatPacket");

chatPacketContructor = NMS_PACKET_PLAY_OUT_CHAT.getConstructor(
NMS_I_CHAT_BASE_COMPONENT,
NMS_CHAT_MESSAGE_TYPE,
UUID.class
int.class
);

Method getChatMessageType = NMS_CHAT_MESSAGE_TYPE.getMethod("a", byte.class);
// Method getChatMessageType = NMS_CHAT_MESSAGE_TYPE.getMethod("a", byte.class);

enumChatMessageTypeMessage = getChatMessageType.invoke(null, (byte) 1);
enumChatMessageTypeActionbar = getChatMessageType.invoke(null, (byte) 2);
enumChatMessageTypeMessage = 0; // getChatMessageType.invoke(null, (byte) 1);
enumChatMessageTypeActionbar = 0; // getChatMessageType.invoke(null, (byte) 2);

}

private Object createPacket(Object chatComponent, Object type) {
private Object createPacket(Object chatComponent, int type) {
try {
return chatPacketContructor.newInstance(
chatComponent,
type,
UUID.randomUUID()
type
);
} catch (Exception e) {
e.printStackTrace();
Expand Down