Fix Forge CUI handler

This commit is contained in:
Kenzie Togami 2015-02-15 09:53:25 -08:00
parent ba363bce20
commit 5c99d4bf59
3 changed files with 20 additions and 8 deletions

View File

@ -34,8 +34,8 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.server.S3FPacketCustomPayload;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
import io.netty.buffer.Unpooled;
import javax.annotation.Nullable;
@ -117,8 +117,7 @@ public void dispatchCUIEvent(CUIEvent event) {
send = send + "|" + StringUtil.joinString(params, "|");
}
PacketBuffer buffer = new PacketBuffer(Unpooled.copiedBuffer(send.getBytes(WECUIPacketHandler.UTF_8_CHARSET)));
S3FPacketCustomPayload packet = new S3FPacketCustomPayload(ForgeWorldEdit.CUI_PLUGIN_CHANNEL, buffer);
this.player.playerNetServerHandler.sendPacket(packet);
WECUIPacketHandler.WECUI_CHANNEL.sendTo(new FMLProxyPacket(buffer, ForgeWorldEdit.CUI_PLUGIN_CHANNEL), player);
}
@Override

View File

@ -95,6 +95,7 @@ public void preInit(FMLPreInitializationEvent event) {
@EventHandler
public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
WECUIPacketHandler.init();
proxy.registerHandlers();
}

View File

@ -23,9 +23,13 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.play.client.C17PacketCustomPayload;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.ThreadQuickExitException;
import net.minecraft.network.play.server.S20PacketEntityProperties;
import net.minecraft.network.play.server.S3FPacketCustomPayload;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.FMLEventChannel;
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
@ -33,7 +37,7 @@
public class WECUIPacketHandler {
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
private static FMLEventChannel WECUI_CHANNEL;
public static FMLEventChannel WECUI_CHANNEL;
public static void init() {
WECUI_CHANNEL = NetworkRegistry.INSTANCE.newEventDrivenChannel(ForgeWorldEdit.CUI_PLUGIN_CHANNEL);
@ -42,7 +46,6 @@ public static void init() {
@SubscribeEvent
public void onPacketData(ServerCustomPacketEvent event) {
C17PacketCustomPayload rawPacket = (C17PacketCustomPayload) event.packet.toC17Packet();
if (event.packet.channel().equals(ForgeWorldEdit.CUI_PLUGIN_CHANNEL)) {
EntityPlayerMP player = getPlayerFromEvent(event);
LocalSession session = ForgeWorldEdit.inst.getSession((EntityPlayerMP) player);
@ -50,9 +53,18 @@ public void onPacketData(ServerCustomPacketEvent event) {
if (session.hasCUISupport()) {
return;
}
String text = new String(rawPacket.getBufferData().array(), UTF_8_CHARSET);
String text = event.packet.payload().toString(UTF_8_CHARSET);
session.handleCUIInitializationMessage(text);
session.describeCUI(ForgeWorldEdit.inst.wrap(player));
}
}
@SubscribeEvent
public void callProcessPacket(ClientCustomPacketEvent event) {
try {
new S3FPacketCustomPayload(event.packet.channel(), new PacketBuffer(event.packet.payload())).processPacket(event.handler);
} catch (ThreadQuickExitException suppress) {
}
}