Skip to content

Commit

Permalink
Compile and mixin fixes.
Browse files Browse the repository at this point in the history
Enough to get to the main menu
  • Loading branch information
modmuss50 committed Aug 4, 2023
1 parent 5a4f031 commit 54e1b91
Show file tree
Hide file tree
Showing 33 changed files with 167 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.client.network.ClientCommandSource;
import net.minecraft.client.network.ClientDynamicRegistryType;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.CommandSource;
import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.resource.featuretoggle.FeatureSet;
import net.minecraft.registry.CombinedDynamicRegistries;

import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
Expand All @@ -48,17 +47,19 @@ abstract class ClientPlayNetworkHandlerMixin {
@Final
private ClientCommandSource commandSource;

@Final
@Shadow
private FeatureSet enabledFeatures;

@Final
@Shadow
private CombinedDynamicRegistries<ClientDynamicRegistryType> combinedDynamicRegistries;
private DynamicRegistryManager.Immutable combinedDynamicRegistries;

@Inject(method = "onGameJoin", at = @At("RETURN"))
private void onGameJoin(GameJoinS2CPacket packet, CallbackInfo info) {
final CommandDispatcher<FabricClientCommandSource> dispatcher = new CommandDispatcher<>();
ClientCommandInternals.setActiveDispatcher(dispatcher);
ClientCommandRegistrationCallback.EVENT.invoker().register(dispatcher, CommandRegistryAccess.of(this.combinedDynamicRegistries.getCombinedRegistryManager(), this.enabledFeatures));
ClientCommandRegistrationCallback.EVENT.invoker().register(dispatcher, CommandRegistryAccess.of(this.combinedDynamicRegistries, this.enabledFeatures));
ClientCommandInternals.finalizeInit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public void onInitialize() {
// - instant health potions can be brewed from awkward potions with any item in the 'minecraft:small_flowers' tag
// - dirty potions can be brewed by adding any item in the 'minecraft:dirt' tag to any standard potion

Registry.register(Registries.GAME_EVENT, TEST_EVENT_ID, TEST_EVENT);
CompostingChanceRegistry.INSTANCE.add(Items.OBSIDIAN, 0.5F);
FlammableBlockRegistry.getDefaultInstance().add(Blocks.DIAMOND_BLOCK, 4, 4);
FlammableBlockRegistry.getDefaultInstance().add(BlockTags.SAND, 4, 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void onClearWorld(CallbackInfo ci) {
method = "onSynchronizeTags",
at = @At(
value = "INVOKE",
target = "java/util/Map.forEach(Ljava/util/function/BiConsumer;)V",
target = "Lnet/minecraft/client/network/ClientCommonNetworkHandler;onSynchronizeTags(Lnet/minecraft/network/packet/s2c/common/SynchronizeTagsS2CPacket;)V",
shift = At.Shift.AFTER, by = 1
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.listener.ServerPlayPacketListener;
import net.minecraft.network.listener.ServerCommonPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.util.Identifier;
import net.minecraft.util.thread.ThreadExecutor;
Expand Down Expand Up @@ -331,7 +331,7 @@ public static boolean canSend(PacketType<?> type) {
* @param buf the packet byte buf which represents the payload of the packet
* @return a new packet
*/
public static Packet<ServerPlayPacketListener> createC2SPacket(Identifier channelName, PacketByteBuf buf) {
public static Packet<ServerCommonPacketListener> createC2SPacket(Identifier channelName, PacketByteBuf buf) {
Objects.requireNonNull(channelName, "Channel name cannot be null");
Objects.requireNonNull(buf, "Buf cannot be null");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.impl.networking.AbstractNetworkAddon;
import net.fabricmc.fabric.impl.networking.GenericFutureListenerHolder;
import net.fabricmc.fabric.impl.networking.PacketByteBufLoginQueryRequestPayload;
import net.fabricmc.fabric.impl.networking.PacketByteBufLoginQueryResponse;
import net.fabricmc.fabric.mixin.networking.client.accessor.ClientLoginNetworkHandlerAccessor;

public final class ClientLoginNetworkAddon extends AbstractNetworkAddon<ClientLoginNetworking.LoginQueryRequestHandler> {
Expand All @@ -55,7 +57,8 @@ public ClientLoginNetworkAddon(ClientLoginNetworkHandler handler, MinecraftClien
}

public boolean handlePacket(LoginQueryRequestS2CPacket packet) {
return handlePacket(packet.getQueryId(), packet.getChannel(), packet.getPayload());
PacketByteBufLoginQueryRequestPayload payload = (PacketByteBufLoginQueryRequestPayload) packet.payload();
return handlePacket(packet.queryId(), packet.payload().id(), payload.data());
}

private boolean handlePacket(int queryId, Identifier channelName, PacketByteBuf originalBuf) {
Expand Down Expand Up @@ -83,7 +86,7 @@ private boolean handlePacket(int queryId, Identifier channelName, PacketByteBuf
try {
CompletableFuture<@Nullable PacketByteBuf> future = handler.receive(this.client, this.handler, buf, futureListeners::add);
future.thenAccept(result -> {
LoginQueryResponseC2SPacket packet = new LoginQueryResponseC2SPacket(queryId, result);
LoginQueryResponseC2SPacket packet = new LoginQueryResponseC2SPacket(queryId, new PacketByteBufLoginQueryResponse(result));
GenericFutureListener<? extends Future<? super Void>> listener = null;

for (GenericFutureListener<? extends Future<? super Void>> each : futureListeners) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import net.minecraft.client.network.ClientLoginNetworkHandler;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.listener.ServerPlayPacketListener;
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
import net.minecraft.network.listener.ServerCommonPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket;
import net.minecraft.util.Identifier;

import net.fabricmc.fabric.api.client.networking.v1.ClientLoginNetworking;
Expand All @@ -42,6 +42,7 @@
import net.fabricmc.fabric.impl.networking.GlobalReceiverRegistry;
import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions;
import net.fabricmc.fabric.impl.networking.NetworkingImpl;
import net.fabricmc.fabric.impl.networking.PacketByteBufPayload;
import net.fabricmc.fabric.mixin.networking.client.accessor.ClientLoginNetworkHandlerAccessor;
import net.fabricmc.fabric.mixin.networking.client.accessor.ConnectScreenAccessor;
import net.fabricmc.fabric.mixin.networking.client.accessor.MinecraftClientAccessor;
Expand All @@ -59,8 +60,8 @@ public static ClientLoginNetworkAddon getAddon(ClientLoginNetworkHandler handler
return (ClientLoginNetworkAddon) ((NetworkHandlerExtensions) handler).getAddon();
}

public static Packet<ServerPlayPacketListener> createPlayC2SPacket(Identifier channelName, PacketByteBuf buf) {
return new CustomPayloadC2SPacket(channelName, buf);
public static Packet<ServerCommonPacketListener> createPlayC2SPacket(Identifier channelName, PacketByteBuf buf) {
return new CustomPayloadC2SPacket(new PacketByteBufPayload(channelName, buf));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.network.packet.Packet;
import net.minecraft.util.Identifier;

import net.fabricmc.fabric.api.client.networking.v1.C2SPlayChannelEvents;
Expand All @@ -36,6 +35,7 @@
import net.fabricmc.fabric.impl.networking.AbstractChanneledNetworkAddon;
import net.fabricmc.fabric.impl.networking.ChannelInfoHolder;
import net.fabricmc.fabric.impl.networking.NetworkingImpl;
import net.fabricmc.fabric.impl.networking.PacketByteBufPayload;

public final class ClientPlayNetworkAddon extends AbstractChanneledNetworkAddon<ClientPlayNetworking.PlayChannelHandler> {
private final ClientPlayNetworkHandler handler;
Expand Down Expand Up @@ -80,16 +80,14 @@ public void onServerReady() {
/**
* Handles an incoming packet.
*
* @param packet the packet to handle
* @param payload the payload to handle
* @return true if the packet has been handled
*/
public boolean handle(CustomPayloadS2CPacket packet) {
PacketByteBuf buf = packet.getData();

public boolean handle(PacketByteBufPayload payload) {
try {
return this.handle(packet.getChannel(), buf);
return this.handle(payload.id(), payload.data());
} finally {
buf.release();
payload.data().release();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.fabricmc.fabric.mixin.networking.client;

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 net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.text.Text;

import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions;

@Mixin(ClientCommonNetworkHandler.class)
public abstract class ClientCommonNetworkHandlerMixin implements NetworkHandlerExtensions {
@Inject(method = "onDisconnected", at = @At("HEAD"))
private void handleDisconnection(Text reason, CallbackInfo ci) {
this.getAddon().handleDisconnect();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,35 @@

package net.fabricmc.fabric.mixin.networking.client;

import org.spongepowered.asm.mixin.Final;
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;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.client.network.ClientConnectionState;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import net.minecraft.text.Text;

import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions;
import net.fabricmc.fabric.impl.networking.PacketByteBufPayload;
import net.fabricmc.fabric.impl.networking.client.ClientNetworkingImpl;
import net.fabricmc.fabric.impl.networking.client.ClientPlayNetworkAddon;

// We want to apply a bit earlier than other mods which may not use us in order to prevent refCount issues
@Mixin(value = ClientPlayNetworkHandler.class, priority = 999)
abstract class ClientPlayNetworkHandlerMixin implements NetworkHandlerExtensions {
@Final
@Shadow
private MinecraftClient client;

abstract class ClientPlayNetworkHandlerMixin extends ClientCommonNetworkHandler implements NetworkHandlerExtensions {
@Unique
private ClientPlayNetworkAddon addon;

protected ClientPlayNetworkHandlerMixin(MinecraftClient client, ClientConnection connection, ClientConnectionState connectionState) {
super(client, connection, connectionState);
}

@Inject(method = "<init>", at = @At("RETURN"))
private void initAddon(CallbackInfo ci) {
this.addon = new ClientPlayNetworkAddon((ClientPlayNetworkHandler) (Object) this, this.client);
Expand All @@ -58,17 +59,12 @@ private void handleServerPlayReady(GameJoinS2CPacket packet, CallbackInfo ci) {
}

@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
private void handleCustomPayload(CustomPayloadS2CPacket packet, CallbackInfo ci) {
if (this.addon.handle(packet)) {
private void handleCustomPayload(CustomPayload payload, CallbackInfo ci) {
if (payload instanceof PacketByteBufPayload byteBufPayload && this.addon.handle(byteBufPayload)) {
ci.cancel();
}
}

@Inject(method = "onDisconnected", at = @At("HEAD"))
private void handleDisconnection(Text reason, CallbackInfo ci) {
this.addon.handleDisconnect();
}

@Override
public ClientPlayNetworkAddon getAddon() {
return this.addon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"accessor.ClientLoginNetworkHandlerAccessor",
"accessor.ConnectScreenAccessor",
"accessor.MinecraftClientAccessor",
"ClientCommonNetworkHandlerMixin",
"ClientLoginNetworkHandlerMixin",
"ClientPlayNetworkHandlerMixin"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import org.jetbrains.annotations.Nullable;

import net.minecraft.network.packet.Packet;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.listener.ClientCommonPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -381,7 +381,7 @@ public static boolean canSend(ServerPlayNetworkHandler handler, PacketType<?> ty
* @param buf the packet byte buf which represents the payload of the packet
* @return a new packet
*/
public static Packet<ClientPlayPacketListener> createS2CPacket(Identifier channelName, PacketByteBuf buf) {
public static Packet<ClientCommonPacketListener> createS2CPacket(Identifier channelName, PacketByteBuf buf) {
Objects.requireNonNull(channelName, "Channel cannot be null");
Objects.requireNonNull(buf, "Buf cannot be null");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.fabricmc.fabric.impl.networking;

import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.s2c.login.LoginQueryRequestPayload;
import net.minecraft.util.Identifier;

public record PacketByteBufLoginQueryRequestPayload(Identifier id, PacketByteBuf data) implements LoginQueryRequestPayload {
@Override
public void write(PacketByteBuf buf) {
buf.writeBytes(this.data());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.fabricmc.fabric.impl.networking;

import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.c2s.login.LoginQueryResponse;

public record PacketByteBufLoginQueryResponse(PacketByteBuf data) implements LoginQueryResponse {
@Override
public void write(PacketByteBuf buf) {
buf.writeBytes(this.data());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.fabricmc.fabric.impl.networking;

import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;

public record PacketByteBufPayload(Identifier id, PacketByteBuf data) implements CustomPayload {
@Override
public void write(PacketByteBuf buf) {
buf.writeBytes(this.data());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import org.jetbrains.annotations.Nullable;

import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.PacketCallbacks;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.login.LoginQueryResponseC2SPacket;
import net.minecraft.network.packet.s2c.login.LoginCompressionS2CPacket;
import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket;
Expand All @@ -46,7 +46,8 @@
import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking;
import net.fabricmc.fabric.impl.networking.AbstractNetworkAddon;
import net.fabricmc.fabric.impl.networking.GenericFutureListenerHolder;
import net.fabricmc.fabric.mixin.networking.accessor.LoginQueryResponseC2SPacketAccessor;
import net.fabricmc.fabric.impl.networking.PacketByteBufLoginQueryRequestPayload;
import net.fabricmc.fabric.impl.networking.PacketByteBufLoginQueryResponse;
import net.fabricmc.fabric.mixin.networking.accessor.ServerLoginNetworkHandlerAccessor;

public final class ServerLoginNetworkAddon extends AbstractNetworkAddon<ServerLoginNetworking.LoginQueryResponseHandler> implements PacketSender {
Expand Down Expand Up @@ -128,8 +129,9 @@ private void sendCompressionPacket() {
* @return true if the packet was handled
*/
public boolean handle(LoginQueryResponseC2SPacket packet) {
LoginQueryResponseC2SPacketAccessor access = (LoginQueryResponseC2SPacketAccessor) packet;
return handle(access.getQueryId(), access.getResponse());
// TODO 1.20.2 likely an unsafe cast.
PacketByteBufLoginQueryResponse response = (PacketByteBufLoginQueryResponse) packet.response();
return handle(packet.queryId(), response.data());
}

private boolean handle(int queryId, @Nullable PacketByteBuf originalBuf) {
Expand Down Expand Up @@ -164,7 +166,7 @@ private boolean handle(int queryId, @Nullable PacketByteBuf originalBuf) {
public Packet<?> createPacket(Identifier channelName, PacketByteBuf buf) {
int queryId = this.queryIdFactory.nextId();

LoginQueryRequestS2CPacket ret = new LoginQueryRequestS2CPacket(queryId, channelName, buf);
LoginQueryRequestS2CPacket ret = new LoginQueryRequestS2CPacket(queryId, new PacketByteBufLoginQueryRequestPayload(channelName, buf));
return ret;
}

Expand All @@ -188,7 +190,7 @@ public void sendPacket(Packet<?> packet, PacketCallbacks callback) {
}

public void registerOutgoingPacket(LoginQueryRequestS2CPacket packet) {
this.channels.put(packet.getQueryId(), packet.getChannel());
this.channels.put(packet.queryId(), packet.payload().id());
}

@Override
Expand All @@ -205,7 +207,7 @@ protected void invokeDisconnectEvent() {
this.receiver.endSession(this);
}

public void handlePlayTransition() {
public void handleConfigurationTransition() {
this.receiver.endSession(this);
}

Expand Down
Loading

0 comments on commit 54e1b91

Please sign in to comment.