Updated most of the networking code... a lot of it is probably broken
still
This commit is contained in:
parent
c075079630
commit
2a5774d477
21 changed files with 465 additions and 235 deletions
|
@ -1,15 +1,21 @@
|
|||
package StevenDimDoors.mod_pocketDim;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.network.DimDoorsNetwork;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
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;
|
||||
|
||||
public class ConnectionHandler implements IConnectionHandler
|
||||
public class ConnectionHandler
|
||||
{
|
||||
@Override
|
||||
public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager)
|
||||
@SubscribeEvent
|
||||
public String connectionReceived(FMLNetworkEvent.ServerConnectionFromClientEvent event)
|
||||
{
|
||||
for(NewDimData data : PocketManager.getDimensions())
|
||||
{
|
||||
|
@ -17,8 +23,9 @@ public class ConnectionHandler implements IConnectionHandler
|
|||
{
|
||||
if(data.isPocketDimension()||data.id()==mod_pocketDim.properties.LimboDimensionID)
|
||||
{
|
||||
Packet250CustomPayload[] pkt = ForgePacket.makePacketSet(new DimensionRegisterPacket(data.id(), DimensionManager.getProviderType(data.id())));
|
||||
manager.addToSendQueue(pkt[0]);
|
||||
DimDoorsNetwork.sendToPlayer( new ForgeMessage.DimensionRegisterMessage(data.id(), DimensionManager.getProviderType(data.id())), )
|
||||
Packet pkt =
|
||||
event.manager.scheduleOutboundPacket(pkt[0]);
|
||||
}
|
||||
}
|
||||
catch(Exception E)
|
||||
|
@ -29,14 +36,8 @@ public class ConnectionHandler implements IConnectionHandler
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager) { }
|
||||
|
||||
@Override
|
||||
public void connectionOpened(NetHandler netClientHandler,MinecraftServer server, INetworkManager manager) { }
|
||||
|
||||
@Override
|
||||
public void connectionClosed(INetworkManager manager)
|
||||
@SubscribeEvent
|
||||
public void connectionClosed(FMLNetworkEvent.ClientDisconnectionFromServerEvent event)
|
||||
{
|
||||
if(PocketManager.isConnected)
|
||||
{
|
||||
|
@ -44,11 +45,8 @@ public class ConnectionHandler implements IConnectionHandler
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login) { }
|
||||
|
||||
@Override
|
||||
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
|
||||
@SubscribeEvent
|
||||
public void playerLoggedIn(PlayerEvent.PlayerLoggedInEvent event)
|
||||
{
|
||||
// Hax... please don't do this! >_<
|
||||
PocketManager.getDimwatcher().onCreated(new ClientDimData(PocketManager.createDimensionDataDangerously(0)));
|
||||
|
|
|
@ -4,18 +4,15 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.network.*;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
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 cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import net.minecraft.network.Packet;
|
||||
|
||||
public class ServerPacketHandler implements IPacketHandler
|
||||
public class ServerPacketHandler
|
||||
{
|
||||
public ServerPacketHandler()
|
||||
{
|
||||
|
@ -23,21 +20,18 @@ public class ServerPacketHandler implements IPacketHandler
|
|||
PocketManager.registerLinkWatcher(new LinkWatcher());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { }
|
||||
|
||||
private static class DimWatcher implements IUpdateWatcher<ClientDimData>
|
||||
{
|
||||
@Override
|
||||
public void onCreated(ClientDimData message)
|
||||
{
|
||||
sendDimPacket(PacketConstants.CREATE_DIM_PACKET_ID, message);
|
||||
DimDoorsNetwork.sendToAllPlayers(new CreateDimensionPacket(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleted(ClientDimData message)
|
||||
{
|
||||
sendDimPacket(PacketConstants.DELETE_DIM_PACKET_ID, message);
|
||||
DimDoorsNetwork.sendToAllPlayers(new DeleteDimensionPacket(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,89 +47,19 @@ public class ServerPacketHandler implements IPacketHandler
|
|||
@Override
|
||||
public void onCreated(ClientLinkData message)
|
||||
{
|
||||
sendLinkPacket(PacketConstants.CREATE_LINK_PACKET_ID, message);
|
||||
DimDoorsNetwork.sendToAllPlayers(new CreateLinkPacket(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleted(ClientLinkData message)
|
||||
{
|
||||
sendLinkPacket(PacketConstants.DELETE_LINK_PACKET_ID, message);
|
||||
DimDoorsNetwork.sendToAllPlayers(new DeleteLinkPacket(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ClientLinkData message)
|
||||
{
|
||||
sendLinkPacket(PacketConstants.UPDATE_LINK_PACKET_ID, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static Packet250CustomPayload createLinkPacket(ClientLinkData data)
|
||||
{
|
||||
try
|
||||
{
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
DataOutputStream writer = new DataOutputStream(buffer);
|
||||
writer.writeByte(PacketConstants.CREATE_LINK_PACKET_ID);
|
||||
data.write(writer);
|
||||
writer.close();
|
||||
packet.channel = PacketConstants.CHANNEL_NAME;
|
||||
packet.data = buffer.toByteArray();
|
||||
packet.length = packet.data.length;
|
||||
return packet;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
//This shouldn't happen...
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void sendDimPacket(byte id, ClientDimData data)
|
||||
{
|
||||
try
|
||||
{
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
DataOutputStream writer = new DataOutputStream(buffer);
|
||||
writer.writeByte(id);
|
||||
data.write(writer);
|
||||
writer.close();
|
||||
packet.channel = PacketConstants.CHANNEL_NAME;
|
||||
packet.data = buffer.toByteArray();
|
||||
packet.length = packet.data.length;
|
||||
PacketDispatcher.sendPacketToAllPlayers(packet);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
//This shouldn't happen...
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendLinkPacket(byte id, ClientLinkData message)
|
||||
{
|
||||
try
|
||||
{
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
DataOutputStream writer = new DataOutputStream(buffer);
|
||||
writer.writeByte(id);
|
||||
message.write(writer);
|
||||
writer.close();
|
||||
packet.channel = PacketConstants.CHANNEL_NAME;
|
||||
packet.data = buffer.toByteArray();
|
||||
packet.length = packet.data.length;
|
||||
PacketDispatcher.sendPacketToAllPlayers(packet);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
//This shouldn't happen...
|
||||
e.printStackTrace();
|
||||
DimDoorsNetwork.sendToAllPlayers(new UpdateLinkPacket(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public class CommandCreateDungeonRift extends DDCommandBase
|
|||
if (PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result))
|
||||
{
|
||||
// Create a rift to our selected dungeon and notify the player
|
||||
sender.worldObj.setBlock(x, y + 1, z, mod_pocketDim.blockRift.blockID, 0, 3);
|
||||
sender.worldObj.setBlock(x, y + 1, z, mod_pocketDim.blockRift, 0, 3);
|
||||
sendChat(sender, "Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ").");
|
||||
}
|
||||
else
|
||||
|
|
|
@ -14,6 +14,9 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
|||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemDoor;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.play.server.S07PacketRespawn;
|
||||
import net.minecraft.network.play.server.S1DPacketEntityEffect;
|
||||
import net.minecraft.network.play.server.S1FPacketSetExperience;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
@ -298,7 +301,7 @@ public class DDTeleporter
|
|||
|
||||
// Set the new dimension and inform the client that it's moving to a new world.
|
||||
player.dimension = destination.getDimension();
|
||||
player.playerNetServerHandler.sendPacketToPlayer(new Packet9Respawn(player.dimension, (byte)player.worldObj.difficultySetting, newWorld.getWorldInfo().getTerrainType(), newWorld.getHeight(), player.theItemInWorldManager.getGameType()));
|
||||
player.playerNetServerHandler.sendPacket(new S07PacketRespawn(player.dimension, player.worldObj.difficultySetting, newWorld.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType()));
|
||||
|
||||
// GreyMaria: Used the safe player entity remover before.
|
||||
// This should fix an apparently unreported bug where
|
||||
|
@ -321,10 +324,10 @@ public class DDTeleporter
|
|||
for(Object potionEffect : player.getActivePotionEffects())
|
||||
{
|
||||
PotionEffect effect = (PotionEffect)potionEffect;
|
||||
player.playerNetServerHandler.sendPacketToPlayer(new Packet41EntityEffect(player.entityId, effect));
|
||||
player.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(player.getEntityId(), effect));
|
||||
}
|
||||
|
||||
player.playerNetServerHandler.sendPacketToPlayer(new Packet43Experience(player.experience, player.experienceTotal, player.experienceLevel));
|
||||
player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
|
||||
}
|
||||
|
||||
// Creates sanity by removing the entity from its old location's chunk entity list, if applicable.
|
||||
|
@ -384,7 +387,7 @@ public class DDTeleporter
|
|||
newWorld.getChunkProvider().loadChunk(MathHelper.floor_double(entity.posX) >> 4, MathHelper.floor_double(entity.posZ) >> 4);
|
||||
// Tell Forge we're moving its players so everyone else knows.
|
||||
// Let's try doing this down here in case this is what's killing NEI.
|
||||
FMLCommonHandler.instance().firePlayerChangedDimensionEvent((EntityPlayer)entity, oldWorld.provider.dimensionId, newWorld.provider.dimensionId);
|
||||
FMLCommonHandler.instance().firePlayerChangedDimensionEvent((EntityPlayer) entity, oldWorld.provider.dimensionId, newWorld.provider.dimensionId);
|
||||
}
|
||||
DDTeleporter.placeInPortal(entity, newWorld, destination, properties, checkOrientation);
|
||||
return entity;
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package StevenDimDoors.mod_pocketDim.core;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -21,7 +18,6 @@ import StevenDimDoors.mod_pocketDim.saving.PackedDimData;
|
|||
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.UpdateWatcherProxy;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
@ -508,8 +504,7 @@ public class PocketManager
|
|||
*
|
||||
* @param dimensionID
|
||||
* @param parent
|
||||
* @param isPocket
|
||||
* @param isDungeon
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
private static NewDimData registerDimension(int dimensionID, InnerDimData parent, DimensionType type)
|
||||
|
@ -689,12 +684,7 @@ public class PocketManager
|
|||
return linkWatcher.unregisterReceiver(watcher);
|
||||
}
|
||||
|
||||
public static void getWatchers(IUpdateSource updateSource)
|
||||
{
|
||||
updateSource.registerWatchers(new ClientDimWatcher(), new ClientLinkWatcher());
|
||||
}
|
||||
|
||||
public static void writePacket(DataOutputStream output) throws IOException
|
||||
public static void writePacket(DataOutput output) throws IOException
|
||||
{
|
||||
// Write a very compact description of our dimensions and links to be
|
||||
// sent to a client
|
||||
|
@ -716,7 +706,7 @@ public class PocketManager
|
|||
}
|
||||
}
|
||||
|
||||
public static void readPacket(DataInputStream input) throws IOException
|
||||
public static void readPacket(DataInput input) throws IOException
|
||||
{
|
||||
// TODO- figure out why this is getting called so frequently
|
||||
if (isLoaded)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package StevenDimDoors.mod_pocketDim.helpers;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
|
@ -27,7 +25,7 @@ public class Compactor
|
|||
}
|
||||
}
|
||||
|
||||
public static void write(Collection<? extends NewDimData> values, DataOutputStream output) throws IOException
|
||||
public static void write(Collection<? extends NewDimData> values, DataOutput output) throws IOException
|
||||
{
|
||||
// SenseiKiwi: Just encode the data straight up for now. I'll implement fancier compression later.
|
||||
output.writeInt(values.size());
|
||||
|
@ -56,7 +54,7 @@ public class Compactor
|
|||
*/
|
||||
}
|
||||
|
||||
public static void readDimensions(DataInputStream input, IDimRegistrationCallback callback) throws IOException
|
||||
public static void readDimensions(DataInput 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.
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput in) {
|
||||
try {
|
||||
PocketManager.readPacket(in);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClient(World world, EntityPlayer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(World world, EntityPlayerMP player) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
|
||||
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 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 {
|
||||
private ClientDimData dimensionData = null;
|
||||
|
||||
public CreateDimensionPacket() {}
|
||||
public CreateDimensionPacket(ClientDimData data) {
|
||||
this.dimensionData = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteArrayDataOutput out) {
|
||||
if (dimensionData != null) {
|
||||
try {
|
||||
dimensionData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput in) {
|
||||
try {
|
||||
dimensionData = ClientDimData.read(in);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClient(World world, EntityPlayer player) {
|
||||
PocketManager.getDimwatcher().onCreated(dimensionData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(World world, EntityPlayerMP player) {
|
||||
//Shouldn't be here
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
|
||||
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 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 {
|
||||
|
||||
private ClientLinkData clientLinkData = null;
|
||||
|
||||
public CreateLinkPacket() {
|
||||
}
|
||||
|
||||
public CreateLinkPacket(ClientLinkData data) {
|
||||
this.clientLinkData = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteArrayDataOutput out) {
|
||||
if (clientLinkData != null) {
|
||||
try {
|
||||
clientLinkData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput in) {
|
||||
try {
|
||||
clientLinkData = ClientLinkData.read(in);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClient(World world, EntityPlayer player) {
|
||||
PocketManager.getLinkWatcher().onCreated(clientLinkData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(World world, EntityPlayerMP player) {
|
||||
//Shouldn't be here
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
|
||||
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 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 {
|
||||
private ClientDimData dimensionData = null;
|
||||
|
||||
public DeleteDimensionPacket() {}
|
||||
public DeleteDimensionPacket(ClientDimData dimensionData) {
|
||||
this.dimensionData = dimensionData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteArrayDataOutput out) {
|
||||
if (dimensionData != null) {
|
||||
try {
|
||||
dimensionData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput in) {
|
||||
try {
|
||||
dimensionData = ClientDimData.read(in);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClient(World world, EntityPlayer player) {
|
||||
PocketManager.getDimwatcher().onDeleted(dimensionData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(World world, EntityPlayerMP player) {
|
||||
//Shouldn't be here
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
|
||||
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 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 {
|
||||
private ClientLinkData linkData;
|
||||
|
||||
public DeleteLinkPacket() {}
|
||||
public DeleteLinkPacket(ClientLinkData linkData) {
|
||||
this.linkData = linkData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteArrayDataOutput out) {
|
||||
if (linkData != null) {
|
||||
try {
|
||||
linkData.write(out);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput in) {
|
||||
try {
|
||||
linkData = ClientLinkData.read(in);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClient(World world, EntityPlayer player) {
|
||||
PocketManager.getLinkWatcher().onDeleted(linkData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(World world, EntityPlayerMP player) {
|
||||
//Shouldn't be here
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
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.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
public class DimDoorsNetwork extends FMLIndexedMessageToMessageCodec<DimDoorsPacket> {
|
||||
|
||||
private static final DimDoorsNetwork INSTANCE = new DimDoorsNetwork();
|
||||
private static final EnumMap<Side, FMLEmbeddedChannel> channels = Maps.newEnumMap(Side.class);
|
||||
|
||||
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("ModysseyTeleporters", INSTANCE));
|
||||
}
|
||||
|
||||
public void encodeInto(ChannelHandlerContext ctx, DimDoorsPacket msg, ByteBuf target) throws Exception {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
msg.write(out);
|
||||
target.writeBytes(out.toByteArray());
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
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.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,49 @@
|
|||
package StevenDimDoors.mod_pocketDim.network;
|
||||
|
||||
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 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 {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput in) {
|
||||
try {
|
||||
linkData = ClientLinkData.read(in);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClient(World world, EntityPlayer player) {
|
||||
PocketManager.getLinkWatcher().update(linkData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(World world, EntityPlayerMP player) {
|
||||
//Shouldn't be here
|
||||
}
|
||||
}
|
|
@ -9,10 +9,10 @@ import StevenDimDoors.mod_pocketDim.core.DimLink;
|
|||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
|
||||
import net.minecraft.network.Packet;
|
||||
|
||||
|
||||
|
||||
public class TileEntityDimDoor extends DDTileEntityBase
|
||||
public class TileEntityDimDoor extends DDTileEntityBase
|
||||
{
|
||||
public boolean openOrClosed;
|
||||
public int orientation;
|
||||
|
|
|
@ -7,6 +7,8 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.monster.EntityEnderman;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import StevenDimDoors.mod_pocketDim.ServerPacketHandler;
|
||||
|
@ -292,9 +294,9 @@ public class TileEntityRift extends DDTileEntityBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
|
||||
{
|
||||
readFromNBT(pkt.data);
|
||||
readFromNBT(pkt.func_148857_g());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package StevenDimDoors.mod_pocketDim.util;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.Point3D;
|
||||
|
||||
|
@ -180,7 +178,7 @@ public final class Point4D implements Comparable<Point4D>
|
|||
return "(" + x + ", " + y + ", " + z + ", " + dimension + ")";
|
||||
}
|
||||
|
||||
public static void write(Point4D point, DataOutputStream stream) throws IOException
|
||||
public static void write(Point4D point, DataOutput stream) throws IOException
|
||||
{
|
||||
stream.writeBoolean(point != null);
|
||||
if (point != null)
|
||||
|
@ -192,7 +190,7 @@ public final class Point4D implements Comparable<Point4D>
|
|||
}
|
||||
}
|
||||
|
||||
public static Point4D read(DataInputStream stream) throws IOException
|
||||
public static Point4D read(DataInput stream) throws IOException
|
||||
{
|
||||
if (stream.readBoolean())
|
||||
{
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package StevenDimDoors.mod_pocketDim.watcher;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.DimensionType;
|
||||
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||
|
||||
|
@ -27,14 +26,14 @@ public class ClientDimData
|
|||
this.type = dimension.type();
|
||||
}
|
||||
|
||||
public void write(DataOutputStream output) throws IOException
|
||||
public void write(DataOutput output) throws IOException
|
||||
{
|
||||
output.writeInt(ID);
|
||||
output.writeInt(rootID);
|
||||
output.writeInt(type.index);
|
||||
}
|
||||
|
||||
public static ClientDimData read(DataInputStream input) throws IOException
|
||||
public static ClientDimData read(DataInput input) throws IOException
|
||||
{
|
||||
int id = input.readInt();
|
||||
int rootID = input.readInt();
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package StevenDimDoors.mod_pocketDim.watcher;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.core.DDLock;
|
||||
import StevenDimDoors.mod_pocketDim.core.DimLink;
|
||||
import StevenDimDoors.mod_pocketDim.core.LinkType;
|
||||
|
@ -36,7 +35,7 @@ public class ClientLinkData
|
|||
|
||||
}
|
||||
|
||||
public void write(DataOutputStream output) throws IOException
|
||||
public void write(DataOutput output) throws IOException
|
||||
{
|
||||
Point4D.write(point, output);
|
||||
output.writeInt(this.type.index);
|
||||
|
@ -50,7 +49,7 @@ public class ClientLinkData
|
|||
}
|
||||
}
|
||||
|
||||
public static ClientLinkData read(DataInputStream input) throws IOException
|
||||
public static ClientLinkData read(DataInput input) throws IOException
|
||||
{
|
||||
Point4D point = Point4D.read(input);
|
||||
LinkType type = LinkType.getLinkTypeFromIndex(input.readInt());
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package StevenDimDoors.mod_pocketDim.watcher;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
||||
|
||||
public interface IUpdateSource
|
||||
{
|
||||
public void registerWatchers(IUpdateWatcher<ClientDimData> dimWatcher, IUpdateWatcher<ClientLinkData> linkWatcher);
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
package StevenDimDoors.mod_pocketDimClient;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.PacketConstants;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource;
|
||||
import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
|
||||
public class ClientPacketHandler implements IPacketHandler, IUpdateSource
|
||||
{
|
||||
private IUpdateWatcher<ClientLinkData> linkWatcher;
|
||||
private IUpdateWatcher<ClientDimData> dimWatcher;
|
||||
|
||||
public ClientPacketHandler()
|
||||
{
|
||||
PocketManager.getWatchers(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerWatchers(IUpdateWatcher<ClientDimData> dimWatcher, IUpdateWatcher<ClientLinkData> linkWatcher)
|
||||
{
|
||||
this.dimWatcher = dimWatcher;
|
||||
this.linkWatcher = linkWatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player)
|
||||
{
|
||||
// TODO: Is this even necessary? I'm not convinced we can receive packets from other channels anyway!
|
||||
if (!packet.channel.equals(PacketConstants.CHANNEL_NAME))
|
||||
return;
|
||||
|
||||
//Checking memory connection wasnt working for some reason, but this seems to work fine.
|
||||
if (FMLCommonHandler.instance().getMinecraftServerInstance() instanceof IntegratedServer)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
DataInputStream input = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
byte packetID = input.readByte();
|
||||
switch (packetID)
|
||||
{
|
||||
case PacketConstants.CLIENT_JOIN_PACKET_ID:
|
||||
PocketManager.readPacket(input);
|
||||
break;
|
||||
case PacketConstants.CREATE_DIM_PACKET_ID:
|
||||
dimWatcher.onCreated( ClientDimData.read(input) );
|
||||
break;
|
||||
case PacketConstants.CREATE_LINK_PACKET_ID:
|
||||
linkWatcher.onCreated( ClientLinkData.read(input) );
|
||||
break;
|
||||
case PacketConstants.DELETE_DIM_PACKET_ID:
|
||||
dimWatcher.onDeleted( ClientDimData.read(input) );
|
||||
break;
|
||||
case PacketConstants.DELETE_LINK_PACKET_ID:
|
||||
linkWatcher.onDeleted( ClientLinkData.read(input) );
|
||||
break;
|
||||
case PacketConstants.UPDATE_LINK_PACKET_ID:
|
||||
linkWatcher.update( ClientLinkData.read(input) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("An exception occurred while processing a data packet:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue