parent
8732497a24
commit
33b90334b4
|
@ -88,7 +88,7 @@ public class BiomesOPlenty
|
|||
@EventHandler
|
||||
public void load(FMLInitializationEvent event)
|
||||
{
|
||||
packetPipeline.initalize();
|
||||
packetPipeline.initialize();
|
||||
|
||||
TreecapitatorIntegration.init();
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ public class CreativeTabsBOP extends CreativeTabs
|
|||
}
|
||||
|
||||
@Override
|
||||
//TODO: public ItemStack getIconItemStack()
|
||||
public ItemStack getIconItemStack()
|
||||
{
|
||||
return new ItemStack(BOPItemHelper.get("food"), 1, 7);
|
||||
|
|
|
@ -1,25 +1,29 @@
|
|||
package biomesoplenty.common.network;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageCodec;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
|
||||
import cpw.mods.fml.common.network.FMLOutboundHandler;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Packet pipeline class. Directs all registered packet data to be handled by the packets themselves.
|
||||
|
@ -31,7 +35,7 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
|||
{
|
||||
private EnumMap<Side, FMLEmbeddedChannel> channels;
|
||||
private LinkedList<Class<? extends AbstractPacket>> packets = new LinkedList<Class<? extends AbstractPacket>>();
|
||||
private boolean isPostInitialised = false;
|
||||
private boolean isPostInitialized = false;
|
||||
|
||||
/**
|
||||
* Register your packet with the pipeline. Discriminators are automatically set.
|
||||
|
@ -42,8 +46,7 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
|||
*/
|
||||
public boolean registerPacket(Class<? extends AbstractPacket> clazz)
|
||||
{
|
||||
if (this.packets.size() > 256)
|
||||
{
|
||||
if (this.packets.size() > 256) {
|
||||
// You should log here!!
|
||||
return false;
|
||||
}
|
||||
|
@ -54,7 +57,7 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
|||
return false;
|
||||
}
|
||||
|
||||
if (this.isPostInitialised)
|
||||
if (this.isPostInitialized)
|
||||
{
|
||||
// You should log here!!
|
||||
return false;
|
||||
|
@ -70,8 +73,7 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
|||
{
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
Class<? extends AbstractPacket> clazz = msg.getClass();
|
||||
if (!this.packets.contains(msg.getClass()))
|
||||
{
|
||||
if (!this.packets.contains(msg.getClass())) {
|
||||
throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
|
@ -98,10 +100,9 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
|||
pkt.decodeInto(ctx, payload.slice());
|
||||
|
||||
EntityPlayer player;
|
||||
switch (FMLCommonHandler.instance().getEffectiveSide())
|
||||
{
|
||||
switch (FMLCommonHandler.instance().getEffectiveSide()) {
|
||||
case CLIENT:
|
||||
player = Minecraft.getMinecraft().thePlayer;
|
||||
player = this.getClientPlayer();
|
||||
pkt.handleClientSide(player);
|
||||
break;
|
||||
|
||||
|
@ -118,26 +119,25 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
|||
}
|
||||
|
||||
// Method to call from FMLInitializationEvent
|
||||
public void initalize()
|
||||
public void initialize()
|
||||
{
|
||||
this.channels = NetworkRegistry.INSTANCE.newChannel("BiomeOPlenty", this);
|
||||
this.channels = NetworkRegistry.INSTANCE.newChannel("BiomesOPlenty", this);
|
||||
}
|
||||
|
||||
// Method to call from FMLPostInitializationEvent
|
||||
// Ensures that packet discriminators are common between server and client by using logical sorting
|
||||
public void postInitialize()
|
||||
{
|
||||
if (this.isPostInitialised)
|
||||
if (this.isPostInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.isPostInitialised = true;
|
||||
Collections.sort(this.packets, new Comparator<Class<? extends AbstractPacket>>()
|
||||
{
|
||||
this.isPostInitialized = true;
|
||||
Collections.sort(this.packets, new Comparator<Class<? extends AbstractPacket>>() {
|
||||
|
||||
@Override
|
||||
public int compare(Class<? extends AbstractPacket> clazz1, Class<? extends AbstractPacket> clazz2)
|
||||
{
|
||||
public int compare(Class<? extends AbstractPacket> clazz1, Class<? extends AbstractPacket> clazz2) {
|
||||
int com = String.CASE_INSENSITIVE_ORDER.compare(clazz1.getCanonicalName(), clazz2.getCanonicalName());
|
||||
if (com == 0) {
|
||||
com = clazz1.getCanonicalName().compareTo(clazz2.getCanonicalName());
|
||||
|
@ -148,6 +148,12 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
|||
});
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private EntityPlayer getClientPlayer()
|
||||
{
|
||||
return Minecraft.getMinecraft().thePlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to everyone.
|
||||
* <p/>
|
||||
|
@ -155,8 +161,7 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
|||
*
|
||||
* @param message The message to send
|
||||
*/
|
||||
public void sendToAll(AbstractPacket message)
|
||||
{
|
||||
public void sendToAll(AbstractPacket message) {
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue