Moved network infrastructure over to the simplenetworkwrapper.
This commit is contained in:
parent
337f0240a6
commit
7a82abf182
25 changed files with 253 additions and 234 deletions
src/main/java/StevenDimDoors
mod_pocketDim
CommonProxy.javaConnectionHandler.javaServerPacketHandler.java
core
helpers
network
DimDoorsNetwork.javaDimDoorsPacket.java
handlers
ClientJoinHandler.javaCreateDimensionHandler.javaCreateLinkHandler.javaDeleteDimensionHandler.javaDeleteLinkHandler.javaUpdateLinkHandler.java
packets
tileentities
util
watcher
mod_pocketDimClient
|
@ -5,6 +5,7 @@ import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
|
|||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
|
@ -151,5 +152,8 @@ public class CommonProxy implements IGuiHandler
|
|||
public void registerSidedHooks(DDProperties properties) {
|
||||
new ServerPacketHandler();
|
||||
}
|
||||
|
||||
|
||||
public EntityPlayer getMessagePlayer(MessageContext ctx) {
|
||||
return ctx.getServerHandler().playerEntity;
|
||||
}
|
||||
}
|
|
@ -1,24 +1,19 @@
|
|||
package StevenDimDoors.mod_pocketDim;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.network.ClientJoinPacket;
|
||||
import StevenDimDoors.mod_pocketDim.network.packets.ClientJoinPacket;
|
||||
import StevenDimDoors.mod_pocketDim.network.DimDoorsNetwork;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
import cpw.mods.fml.common.network.FMLOutboundHandler;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
|
||||
import net.minecraftforge.common.network.ForgeMessage;
|
||||
import net.minecraftforge.common.network.ForgeNetworkHandler;
|
||||
|
||||
public class ConnectionHandler
|
||||
{
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
package StevenDimDoors.mod_pocketDim;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.network.*;
|
||||
import StevenDimDoors.mod_pocketDim.network.packets.*;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher;
|
||||
import net.minecraft.network.Packet;
|
||||
|
||||
public class ServerPacketHandler
|
||||
{
|
||||
|
|
|
@ -4,6 +4,8 @@ import java.io.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
@ -699,7 +701,7 @@ public class PocketManager
|
|||
return linkWatcher.unregisterReceiver(watcher);
|
||||
}
|
||||
|
||||
public static void writePacket(DataOutput output) throws IOException
|
||||
public static void writePacket(ByteBuf output) throws IOException
|
||||
{
|
||||
// Write a very compact description of our dimensions and links to be
|
||||
// sent to a client
|
||||
|
@ -721,7 +723,7 @@ public class PocketManager
|
|||
}
|
||||
}
|
||||
|
||||
public static void readPacket(DataInput input) throws IOException
|
||||
public static void readPacket(ByteBuf input) throws IOException
|
||||
{
|
||||
// TODO- figure out why this is getting called so frequently
|
||||
if (isLoaded)
|
||||
|
|
|
@ -11,6 +11,7 @@ import StevenDimDoors.mod_pocketDim.core.LinkType;
|
|||
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class Compactor
|
||||
{
|
||||
|
@ -25,7 +26,7 @@ public class Compactor
|
|||
}
|
||||
}
|
||||
|
||||
public static void write(Collection<? extends NewDimData> values, DataOutput output) throws IOException
|
||||
public static void write(Collection<? extends NewDimData> values, ByteBuf output) throws IOException
|
||||
{
|
||||
// SenseiKiwi: Just encode the data straight up for now. I'll implement fancier compression later.
|
||||
output.writeInt(values.size());
|
||||
|
@ -54,7 +55,7 @@ public class Compactor
|
|||
*/
|
||||
}
|
||||
|
||||
public static void readDimensions(DataInput input, IDimRegistrationCallback callback) throws IOException
|
||||
public static void readDimensions(ByteBuf input, IDimRegistrationCallback callback) throws IOException
|
||||
{
|
||||
// Read in the dimensions one by one. Make sure we register root dimensions before
|
||||
// attempting to register the dimensions under them.
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
import StevenDimDoors.mod_pocketDim.network.handlers.*;
|
||||
import StevenDimDoors.mod_pocketDim.network.packets.*;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
|
@ -9,6 +12,8 @@ import cpw.mods.fml.common.network.FMLEmbeddedChannel;
|
|||
import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec;
|
||||
import cpw.mods.fml.common.network.FMLOutboundHandler;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
@ -23,75 +28,29 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import java.util.EnumMap;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
public class DimDoorsNetwork extends FMLIndexedMessageToMessageCodec<DimDoorsPacket> {
|
||||
public class DimDoorsNetwork extends SimpleNetworkWrapper {
|
||||
|
||||
private static final DimDoorsNetwork INSTANCE = new DimDoorsNetwork();
|
||||
private static final EnumMap<Side, FMLEmbeddedChannel> channels = Maps.newEnumMap(Side.class);
|
||||
private static final DimDoorsNetwork INSTANCE = new DimDoorsNetwork(mod_pocketDim.modid);
|
||||
|
||||
public DimDoorsNetwork(String channelName) {
|
||||
super(channelName);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
if (!channels.isEmpty())
|
||||
return;
|
||||
|
||||
INSTANCE.addDiscriminator(0, ClientJoinPacket.class);
|
||||
INSTANCE.addDiscriminator(1, CreateDimensionPacket.class);
|
||||
INSTANCE.addDiscriminator(2, DeleteDimensionPacket.class);
|
||||
INSTANCE.addDiscriminator(3, CreateLinkPacket.class);
|
||||
INSTANCE.addDiscriminator(4, DeleteLinkPacket.class);
|
||||
INSTANCE.addDiscriminator(5, UpdateLinkPacket.class);
|
||||
|
||||
channels.putAll(NetworkRegistry.INSTANCE.newChannel("DimDoors", INSTANCE));
|
||||
INSTANCE.registerMessage(ClientJoinHandler.class, ClientJoinPacket.class, 0, Side.CLIENT);
|
||||
INSTANCE.registerMessage(CreateDimensionHandler.class, CreateDimensionPacket.class, 1, Side.CLIENT);
|
||||
INSTANCE.registerMessage(DeleteDimensionHandler.class, DeleteDimensionPacket.class, 2, Side.CLIENT);
|
||||
INSTANCE.registerMessage(CreateLinkHandler.class, CreateLinkPacket.class, 3, Side.CLIENT);
|
||||
INSTANCE.registerMessage(DeleteLinkHandler.class, DeleteLinkPacket.class, 4, Side.CLIENT);
|
||||
INSTANCE.registerMessage(UpdateLinkHandler.class, UpdateLinkPacket.class, 5, Side.CLIENT);
|
||||
}
|
||||
|
||||
public void encodeInto(ChannelHandlerContext ctx, DimDoorsPacket msg, ByteBuf target) throws Exception {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
msg.write(out);
|
||||
target.writeBytes(out.toByteArray());
|
||||
public static void sendToAllPlayers(IMessage message) {
|
||||
INSTANCE.sendToAll(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeInto(ChannelHandlerContext ctx, ByteBuf source, DimDoorsPacket msg) {
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(source.array());
|
||||
|
||||
in.skipBytes(1);
|
||||
msg.read(in);
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient())
|
||||
handleClient(msg);
|
||||
else
|
||||
handleServer(ctx, msg);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private void handleClient(DimDoorsPacket msg) {
|
||||
msg.handleClient(Minecraft.getMinecraft().theWorld, Minecraft.getMinecraft().thePlayer);
|
||||
}
|
||||
|
||||
private void handleServer(ChannelHandlerContext ctx, DimDoorsPacket msg) {
|
||||
EntityPlayerMP player = ((NetHandlerPlayServer)ctx.channel().attr(NetworkRegistry.NET_HANDLER).get()).playerEntity;
|
||||
msg.handleServer(player.worldObj, player);
|
||||
}
|
||||
|
||||
public static void sendToAllPlayers(DimDoorsPacket packet) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL);
|
||||
channels.get(Side.SERVER).writeAndFlush(packet);
|
||||
}
|
||||
|
||||
public static void sendToServer(DimDoorsPacket packet) {
|
||||
channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER);
|
||||
channels.get(Side.CLIENT).writeAndFlush(packet);
|
||||
}
|
||||
|
||||
public static void sendToPlayer(DimDoorsPacket packet, EntityPlayer player) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
|
||||
channels.get(Side.SERVER).writeAndFlush(packet);
|
||||
}
|
||||
|
||||
public static void sendToVicinity(DimDoorsPacket packet, TileEntity entity, double distance) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
|
||||
|
||||
NetworkRegistry.TargetPoint vicinity = new NetworkRegistry.TargetPoint(entity.getWorldObj().provider.dimensionId, entity.xCoord + 0.5, entity.yCoord + 0.5, entity.zCoord + 0.5, distance);
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(vicinity);
|
||||
channels.get(Side.SERVER).writeAndFlush(packet);
|
||||
public static void sendToPlayer(IMessage message, EntityPlayer player) {
|
||||
if (player instanceof EntityPlayerMP)
|
||||
INSTANCE.sendTo(message, (EntityPlayerMP)player);
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class DimDoorsPacket {
|
||||
public abstract void write(ByteArrayDataOutput out);
|
||||
public abstract void read(ByteArrayDataInput in);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract void handleClient(World world, EntityPlayer player);
|
||||
|
||||
public abstract void handleServer(World world, EntityPlayerMP player);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package StevenDimDoors.mod_pocketDim.network.handlers;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.network.packets.ClientJoinPacket;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
|
||||
public class ClientJoinHandler implements IMessageHandler<ClientJoinPacket, IMessage> {
|
||||
|
||||
public ClientJoinHandler() {}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(ClientJoinPacket message, MessageContext ctx) {
|
||||
EntityPlayer player = mod_pocketDim.proxy.getMessagePlayer(ctx);
|
||||
NewDimData dimensionData = PocketManager.getDimensionData(player.worldObj);
|
||||
|
||||
if (dimensionData.isPocketDimension())
|
||||
player.worldObj.provider.registerWorld(player.worldObj);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package StevenDimDoors.mod_pocketDim.network.handlers;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.network.packets.CreateDimensionPacket;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class CreateDimensionHandler implements IMessageHandler<CreateDimensionPacket, IMessage> {
|
||||
|
||||
public CreateDimensionHandler() {}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(CreateDimensionPacket message, MessageContext ctx) {
|
||||
PocketManager.getDimwatcher().onCreated(message.getDimensionData());
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package StevenDimDoors.mod_pocketDim.network.handlers;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.network.packets.CreateLinkPacket;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class CreateLinkHandler implements IMessageHandler<CreateLinkPacket, IMessage> {
|
||||
|
||||
public CreateLinkHandler() {}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(CreateLinkPacket message, MessageContext ctx) {
|
||||
PocketManager.getLinkWatcher().onCreated(message.getClientLinkData());
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package StevenDimDoors.mod_pocketDim.network.handlers;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.network.packets.DeleteDimensionPacket;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class DeleteDimensionHandler implements IMessageHandler<DeleteDimensionPacket, IMessage> {
|
||||
|
||||
public DeleteDimensionHandler() {}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(DeleteDimensionPacket message, MessageContext ctx) {
|
||||
PocketManager.getDimwatcher().onDeleted(message.getDimensionData());
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package StevenDimDoors.mod_pocketDim.network.handlers;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.network.packets.DeleteLinkPacket;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class DeleteLinkHandler implements IMessageHandler<DeleteLinkPacket, IMessage> {
|
||||
@Override
|
||||
public IMessage onMessage(DeleteLinkPacket message, MessageContext ctx) {
|
||||
PocketManager.getLinkWatcher().onDeleted(message.getLinkData());
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package StevenDimDoors.mod_pocketDim.network.handlers;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.network.packets.UpdateLinkPacket;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class UpdateLinkHandler implements IMessageHandler<UpdateLinkPacket, IMessage> {
|
||||
@Override
|
||||
public IMessage onMessage(UpdateLinkPacket message, MessageContext ctx) {
|
||||
PocketManager.getLinkWatcher().update(message.getLinkData());
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,27 +1,23 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
package StevenDimDoors.mod_pocketDim.network.packets;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ClientJoinPacket extends DimDoorsPacket {
|
||||
@Override
|
||||
public void write(ByteArrayDataOutput out) {
|
||||
try {
|
||||
PocketManager.writePacket(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
public class ClientJoinPacket implements IMessage {
|
||||
|
||||
public ClientJoinPacket() {}
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput in) {
|
||||
public void fromBytes(ByteBuf in) {
|
||||
try {
|
||||
PocketManager.readPacket(in);
|
||||
} catch (IOException ex) {
|
||||
|
@ -30,15 +26,12 @@ public class ClientJoinPacket extends DimDoorsPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleClient(World world, EntityPlayer player) {
|
||||
NewDimData dimensionData = PocketManager.getDimensionData(player.worldObj);
|
||||
|
||||
if (dimensionData.isPocketDimension())
|
||||
player.worldObj.provider.registerWorld(player.worldObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(World world, EntityPlayerMP player) {
|
||||
public void toBytes(ByteBuf out) {
|
||||
try {
|
||||
PocketManager.writePacket(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,16 +1,18 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
package StevenDimDoors.mod_pocketDim.network.packets;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CreateDimensionPacket extends DimDoorsPacket {
|
||||
public class CreateDimensionPacket implements IMessage {
|
||||
private ClientDimData dimensionData = null;
|
||||
|
||||
public CreateDimensionPacket() {}
|
||||
|
@ -18,19 +20,10 @@ public class CreateDimensionPacket extends DimDoorsPacket {
|
|||
this.dimensionData = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteArrayDataOutput out) {
|
||||
if (dimensionData != null) {
|
||||
try {
|
||||
dimensionData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public ClientDimData getDimensionData() { return dimensionData; }
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput in) {
|
||||
public void fromBytes(ByteBuf in) {
|
||||
try {
|
||||
dimensionData = ClientDimData.read(in);
|
||||
} catch (IOException ex) {
|
||||
|
@ -39,12 +32,13 @@ public class CreateDimensionPacket extends DimDoorsPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleClient(World world, EntityPlayer player) {
|
||||
PocketManager.getDimwatcher().onCreated(dimensionData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(World world, EntityPlayerMP player) {
|
||||
//Shouldn't be here
|
||||
public void toBytes(ByteBuf out) {
|
||||
if (dimensionData != null) {
|
||||
try {
|
||||
dimensionData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +1,18 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
package StevenDimDoors.mod_pocketDim.network.packets;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CreateLinkPacket extends DimDoorsPacket {
|
||||
public class CreateLinkPacket implements IMessage {
|
||||
|
||||
private ClientLinkData clientLinkData = null;
|
||||
|
||||
|
@ -21,19 +23,10 @@ public class CreateLinkPacket extends DimDoorsPacket {
|
|||
this.clientLinkData = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteArrayDataOutput out) {
|
||||
if (clientLinkData != null) {
|
||||
try {
|
||||
clientLinkData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public ClientLinkData getClientLinkData() { return clientLinkData; }
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput in) {
|
||||
public void fromBytes(ByteBuf in) {
|
||||
try {
|
||||
clientLinkData = ClientLinkData.read(in);
|
||||
} catch (IOException ex) {
|
||||
|
@ -42,12 +35,13 @@ public class CreateLinkPacket extends DimDoorsPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleClient(World world, EntityPlayer player) {
|
||||
PocketManager.getLinkWatcher().onCreated(clientLinkData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(World world, EntityPlayerMP player) {
|
||||
//Shouldn't be here
|
||||
public void toBytes(ByteBuf out) {
|
||||
if (clientLinkData != null) {
|
||||
try {
|
||||
clientLinkData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +1,19 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
package StevenDimDoors.mod_pocketDim.network.packets;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DeleteDimensionPacket extends DimDoorsPacket {
|
||||
public class DeleteDimensionPacket implements IMessage {
|
||||
private ClientDimData dimensionData = null;
|
||||
|
||||
public DeleteDimensionPacket() {}
|
||||
|
@ -18,19 +21,10 @@ public class DeleteDimensionPacket extends DimDoorsPacket {
|
|||
this.dimensionData = dimensionData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteArrayDataOutput out) {
|
||||
if (dimensionData != null) {
|
||||
try {
|
||||
dimensionData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public ClientDimData getDimensionData() { return dimensionData; }
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput in) {
|
||||
public void fromBytes(ByteBuf in) {
|
||||
try {
|
||||
dimensionData = ClientDimData.read(in);
|
||||
} catch (IOException ex) {
|
||||
|
@ -39,12 +33,13 @@ public class DeleteDimensionPacket extends DimDoorsPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleClient(World world, EntityPlayer player) {
|
||||
PocketManager.getDimwatcher().onDeleted(dimensionData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(World world, EntityPlayerMP player) {
|
||||
//Shouldn't be here
|
||||
public void toBytes(ByteBuf out) {
|
||||
if (dimensionData != null) {
|
||||
try {
|
||||
dimensionData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +1,18 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
package StevenDimDoors.mod_pocketDim.network.packets;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DeleteLinkPacket extends DimDoorsPacket {
|
||||
public class DeleteLinkPacket implements IMessage {
|
||||
private ClientLinkData linkData;
|
||||
|
||||
public DeleteLinkPacket() {}
|
||||
|
@ -19,19 +20,10 @@ public class DeleteLinkPacket extends DimDoorsPacket {
|
|||
this.linkData = linkData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteArrayDataOutput out) {
|
||||
if (linkData != null) {
|
||||
try {
|
||||
linkData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public ClientLinkData getLinkData() { return linkData; }
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput in) {
|
||||
public void fromBytes(ByteBuf in) {
|
||||
try {
|
||||
linkData = ClientLinkData.read(in);
|
||||
} catch (IOException ex) {
|
||||
|
@ -40,12 +32,13 @@ public class DeleteLinkPacket extends DimDoorsPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleClient(World world, EntityPlayer player) {
|
||||
PocketManager.getLinkWatcher().onDeleted(linkData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(World world, EntityPlayerMP player) {
|
||||
//Shouldn't be here
|
||||
public void toBytes(ByteBuf out) {
|
||||
if (linkData != null) {
|
||||
try {
|
||||
linkData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +1,29 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
package StevenDimDoors.mod_pocketDim.network.packets;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class UpdateLinkPacket extends DimDoorsPacket {
|
||||
public class UpdateLinkPacket implements IMessage {
|
||||
private ClientLinkData linkData = null;
|
||||
|
||||
public UpdateLinkPacket() {}
|
||||
public UpdateLinkPacket(ClientLinkData linkData) {
|
||||
this.linkData = linkData;
|
||||
}
|
||||
@Override
|
||||
public void write(ByteArrayDataOutput out) {
|
||||
if (linkData != null) {
|
||||
try {
|
||||
linkData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ClientLinkData getLinkData() { return linkData; }
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput in) {
|
||||
public void fromBytes(ByteBuf in) {
|
||||
try {
|
||||
linkData = ClientLinkData.read(in);
|
||||
} catch (IOException ex) {
|
||||
|
@ -38,12 +32,13 @@ public class UpdateLinkPacket extends DimDoorsPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleClient(World world, EntityPlayer player) {
|
||||
PocketManager.getLinkWatcher().update(linkData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(World world, EntityPlayerMP player) {
|
||||
//Shouldn't be here
|
||||
public void toBytes(ByteBuf out) {
|
||||
if (linkData != null) {
|
||||
try {
|
||||
linkData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,11 +2,8 @@ package StevenDimDoors.mod_pocketDim.tileentities;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.network.CreateLinkPacket;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import StevenDimDoors.mod_pocketDim.ServerPacketHandler;
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
import StevenDimDoors.mod_pocketDim.core.DimLink;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package StevenDimDoors.mod_pocketDim.tileentities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.network.CreateLinkPacket;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.monster.EntityEnderman;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -13,8 +11,6 @@ import net.minecraft.network.NetworkManager;
|
|||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import StevenDimDoors.mod_pocketDim.ServerPacketHandler;
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
import StevenDimDoors.mod_pocketDim.core.DimLink;
|
||||
|
|
|
@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.util;
|
|||
import java.io.*;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.Point3D;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
|
||||
|
@ -188,7 +189,7 @@ public final class Point4D implements Comparable<Point4D>
|
|||
}
|
||||
}
|
||||
|
||||
public static void write(Point4D point, DataOutput stream) throws IOException
|
||||
public static void write(Point4D point, ByteBuf stream) throws IOException
|
||||
{
|
||||
stream.writeBoolean(point != null);
|
||||
if (point != null)
|
||||
|
@ -200,7 +201,7 @@ public final class Point4D implements Comparable<Point4D>
|
|||
}
|
||||
}
|
||||
|
||||
public static Point4D read(DataInput stream) throws IOException
|
||||
public static Point4D read(ByteBuf stream) throws IOException
|
||||
{
|
||||
if (stream.readBoolean())
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.io.*;
|
|||
|
||||
import StevenDimDoors.mod_pocketDim.core.DimensionType;
|
||||
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ClientDimData
|
||||
{
|
||||
|
@ -26,14 +27,14 @@ public class ClientDimData
|
|||
this.type = dimension.type();
|
||||
}
|
||||
|
||||
public void write(DataOutput output) throws IOException
|
||||
public void write(ByteBuf output) throws IOException
|
||||
{
|
||||
output.writeInt(ID);
|
||||
output.writeInt(rootID);
|
||||
output.writeInt(type.index);
|
||||
}
|
||||
|
||||
public static ClientDimData read(DataInput input) throws IOException
|
||||
public static ClientDimData read(ByteBuf input) throws IOException
|
||||
{
|
||||
int id = input.readInt();
|
||||
int rootID = input.readInt();
|
||||
|
|
|
@ -6,6 +6,7 @@ import StevenDimDoors.mod_pocketDim.core.DDLock;
|
|||
import StevenDimDoors.mod_pocketDim.core.DimLink;
|
||||
import StevenDimDoors.mod_pocketDim.core.LinkType;
|
||||
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class ClientLinkData
|
||||
|
@ -36,7 +37,7 @@ public class ClientLinkData
|
|||
|
||||
}
|
||||
|
||||
public void write(DataOutput output) throws IOException
|
||||
public void write(ByteBuf output) throws IOException
|
||||
{
|
||||
Point4D.write(point, output);
|
||||
output.writeInt(this.type.index);
|
||||
|
@ -67,7 +68,7 @@ public class ClientLinkData
|
|||
}
|
||||
}
|
||||
|
||||
public static ClientLinkData read(DataInput input) throws IOException
|
||||
public static ClientLinkData read(ByteBuf input) throws IOException
|
||||
{
|
||||
Point4D point = Point4D.read(input);
|
||||
LinkType type = LinkType.getLinkTypeFromIndex(input.readInt());
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package StevenDimDoors.mod_pocketDimClient;
|
||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import StevenDimDoors.mod_pocketDim.CommonProxy;
|
||||
|
@ -60,4 +63,9 @@ public class ClientProxy extends CommonProxy
|
|||
PocketManager.getDimwatcher().registerReceiver (new PocketManager.ClientDimWatcher());
|
||||
PocketManager.getLinkWatcher().registerReceiver(new PocketManager.ClientLinkWatcher());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPlayer getMessagePlayer(MessageContext ctx) {
|
||||
return Minecraft.getMinecraft().thePlayer;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue