2012-11-05 20:29:04 +01:00
|
|
|
package mekanism.common;
|
2012-08-15 22:41:41 +02:00
|
|
|
|
2012-09-03 18:11:25 +02:00
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.DataOutputStream;
|
2012-08-15 22:41:41 +02:00
|
|
|
import java.io.IOException;
|
2013-02-27 02:21:30 +01:00
|
|
|
import java.util.ArrayList;
|
2013-01-21 02:15:59 +01:00
|
|
|
import java.util.Random;
|
2012-08-15 22:41:41 +02:00
|
|
|
|
2012-12-20 22:53:39 +01:00
|
|
|
import mekanism.api.ITileNetwork;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-01-21 02:15:59 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2012-12-20 22:53:39 +01:00
|
|
|
import net.minecraft.network.INetworkManager;
|
|
|
|
import net.minecraft.network.packet.Packet250CustomPayload;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.world.World;
|
2012-10-14 03:48:29 +02:00
|
|
|
|
2012-09-03 18:11:25 +02:00
|
|
|
import com.google.common.io.ByteArrayDataInput;
|
|
|
|
import com.google.common.io.ByteStreams;
|
|
|
|
|
2013-02-27 02:21:30 +01:00
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
2012-08-15 22:41:41 +02:00
|
|
|
import cpw.mods.fml.common.network.IPacketHandler;
|
2012-09-03 18:11:25 +02:00
|
|
|
import cpw.mods.fml.common.network.PacketDispatcher;
|
2012-08-15 22:41:41 +02:00
|
|
|
import cpw.mods.fml.common.network.Player;
|
2013-02-27 02:21:30 +01:00
|
|
|
import cpw.mods.fml.server.FMLServerHandler;
|
2012-08-15 22:41:41 +02:00
|
|
|
|
2012-09-03 18:11:25 +02:00
|
|
|
/**
|
2012-11-05 20:29:04 +01:00
|
|
|
* Mekanism packet handler. As always, use packets sparingly!
|
2012-09-03 18:11:25 +02:00
|
|
|
* @author AidanBrady
|
|
|
|
*
|
|
|
|
*/
|
2012-08-15 22:41:41 +02:00
|
|
|
public class PacketHandler implements IPacketHandler
|
|
|
|
{
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-10-25 23:55:32 +02:00
|
|
|
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2012-09-03 18:11:25 +02:00
|
|
|
ByteArrayDataInput dataStream = ByteStreams.newDataInput(packet.data);
|
2012-08-15 22:41:41 +02:00
|
|
|
EntityPlayer entityplayer = (EntityPlayer)player;
|
|
|
|
|
2012-11-05 20:29:04 +01:00
|
|
|
if(packet.channel.equals("Mekanism"))
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
|
|
|
try {
|
2012-09-20 15:59:30 +02:00
|
|
|
int packetType = dataStream.readInt();
|
2012-08-15 22:41:41 +02:00
|
|
|
|
2012-09-20 15:59:30 +02:00
|
|
|
if(packetType == EnumPacketType.TIME.id)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2012-11-05 20:29:04 +01:00
|
|
|
System.out.println("[Mekanism] Received time update packet from " + entityplayer.username + ".");
|
2013-02-27 02:21:30 +01:00
|
|
|
entityplayer.getCurrentEquippedItem().damageItem(4999, entityplayer);
|
2012-11-29 02:03:55 +01:00
|
|
|
MekanismUtils.setHourForward(entityplayer.worldObj, dataStream.readInt());
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|
2012-09-20 15:59:30 +02:00
|
|
|
if(packetType == EnumPacketType.WEATHER.id)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2012-11-05 20:29:04 +01:00
|
|
|
System.out.println("[Mekanism] Received weather update packet from " + entityplayer.username + ".");
|
2013-02-27 02:21:30 +01:00
|
|
|
entityplayer.getCurrentEquippedItem().damageItem(4999, entityplayer);
|
2012-09-20 15:59:30 +02:00
|
|
|
int weatherType = dataStream.readInt();
|
|
|
|
if(weatherType == EnumWeatherType.CLEAR.id)
|
|
|
|
{
|
|
|
|
entityplayer.worldObj.getWorldInfo().setRaining(false);
|
|
|
|
entityplayer.worldObj.getWorldInfo().setThundering(false);
|
|
|
|
}
|
|
|
|
if(weatherType == EnumWeatherType.HAZE.id)
|
|
|
|
{
|
|
|
|
entityplayer.worldObj.getWorldInfo().setRaining(true);
|
|
|
|
entityplayer.worldObj.getWorldInfo().setThundering(true);
|
|
|
|
}
|
|
|
|
if(weatherType == EnumWeatherType.RAIN.id)
|
|
|
|
{
|
|
|
|
entityplayer.worldObj.getWorldInfo().setRaining(true);
|
|
|
|
}
|
|
|
|
if(weatherType == EnumWeatherType.STORM.id)
|
|
|
|
{
|
|
|
|
entityplayer.worldObj.getWorldInfo().setThundering(true);
|
|
|
|
}
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|
2012-09-20 15:59:30 +02:00
|
|
|
if(packetType == EnumPacketType.TILE_ENTITY.id)
|
2012-09-03 18:11:25 +02:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
int x = dataStream.readInt();
|
|
|
|
int y = dataStream.readInt();
|
|
|
|
int z = dataStream.readInt();
|
|
|
|
|
2013-01-21 02:15:59 +01:00
|
|
|
World world = entityplayer.worldObj;
|
2012-09-03 18:11:25 +02:00
|
|
|
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
2012-10-17 20:46:27 +02:00
|
|
|
if(tileEntity instanceof ITileNetwork)
|
2012-09-03 18:11:25 +02:00
|
|
|
{
|
2013-02-27 02:21:30 +01:00
|
|
|
((ITileNetwork)tileEntity).handlePacketData(dataStream);
|
2012-09-03 18:11:25 +02:00
|
|
|
}
|
|
|
|
} catch (Exception e)
|
|
|
|
{
|
2012-11-05 20:29:04 +01:00
|
|
|
System.err.println("[Mekanism] Error while handling tile entity packet.");
|
2012-09-03 18:11:25 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2012-11-21 16:14:35 +01:00
|
|
|
if(packetType == EnumPacketType.CONTROL_PANEL.id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
String modClass = dataStream.readUTF();
|
|
|
|
String modInstance = dataStream.readUTF();
|
|
|
|
int x = dataStream.readInt();
|
|
|
|
int y = dataStream.readInt();
|
|
|
|
int z = dataStream.readInt();
|
|
|
|
int guiId = dataStream.readInt();
|
|
|
|
|
|
|
|
Class mod = Class.forName(modClass);
|
|
|
|
|
|
|
|
if(mod == null)
|
|
|
|
{
|
|
|
|
System.err.println("[Mekanism] Incorrectly implemented IAccessibleGui -- ignoring handler packet.");
|
|
|
|
System.err.println(" ~ Unable to locate class '" + modClass + ".'");
|
|
|
|
System.err.println(" ~ GUI Container may not function correctly.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object instance = mod.getField(modInstance).get(null);
|
|
|
|
|
|
|
|
if(instance == null)
|
|
|
|
{
|
|
|
|
System.err.println("[Mekanism] Incorrectly implemented IAccessibleGui -- ignoring handler packet.");
|
|
|
|
System.err.println(" ~ Unable to locate instance object '" + modInstance + ".'");
|
|
|
|
System.err.println(" ~ GUI Container may not function correctly.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
entityplayer.openGui(instance, guiId, entityplayer.worldObj, x, y, z);
|
|
|
|
} catch (Exception e)
|
|
|
|
{
|
|
|
|
System.err.println("[Mekanism] Error while handling control panel packet.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2013-01-21 02:15:59 +01:00
|
|
|
if(packetType == EnumPacketType.PORTAL_FX.id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
Random random = new Random();
|
|
|
|
int x = dataStream.readInt();
|
|
|
|
int y = dataStream.readInt();
|
|
|
|
int z = dataStream.readInt();
|
|
|
|
|
|
|
|
for(int i = 0; i < 50; i++)
|
|
|
|
{
|
|
|
|
entityplayer.worldObj.spawnParticle("portal", x + random.nextFloat(), y + random.nextFloat(), z + random.nextFloat(), 0.0F, 0.0F, 0.0F);
|
|
|
|
entityplayer.worldObj.spawnParticle("portal", x + random.nextFloat(), y + 1 + random.nextFloat(), z + random.nextFloat(), 0.0F, 0.0F, 0.0F);
|
|
|
|
}
|
|
|
|
} catch (Exception e)
|
|
|
|
{
|
|
|
|
System.err.println("[Mekanism] Error while handling portal FX packet.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(packetType == EnumPacketType.DIGIT_UPDATE.id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
int index = dataStream.readInt();
|
|
|
|
int digit = dataStream.readInt();
|
|
|
|
|
|
|
|
ItemStack currentStack = entityplayer.getCurrentEquippedItem();
|
|
|
|
|
|
|
|
if(currentStack != null && currentStack.getItem() instanceof ItemPortableTeleporter)
|
|
|
|
{
|
|
|
|
ItemPortableTeleporter item = (ItemPortableTeleporter)currentStack.getItem();
|
|
|
|
item.setDigit(currentStack, index, digit);
|
|
|
|
}
|
|
|
|
} catch (Exception e)
|
|
|
|
{
|
|
|
|
System.err.println("[Mekanism] Error while handling digit update packet.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(packetType == EnumPacketType.STATUS_UPDATE.id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
ItemStack currentStack = entityplayer.getCurrentEquippedItem();
|
|
|
|
|
|
|
|
if(currentStack != null && currentStack.getItem() instanceof ItemPortableTeleporter)
|
|
|
|
{
|
|
|
|
ItemPortableTeleporter item = (ItemPortableTeleporter)currentStack.getItem();
|
|
|
|
item.setStatus(currentStack, dataStream.readInt());
|
|
|
|
}
|
|
|
|
} catch (Exception e)
|
|
|
|
{
|
|
|
|
System.err.println("[Mekanism] Error while handling status update packet.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(packetType == EnumPacketType.PORTABLE_TELEPORT.id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if(entityplayer instanceof EntityPlayerMP)
|
|
|
|
{
|
|
|
|
EntityPlayerMP entityPlayerMP = (EntityPlayerMP)entityplayer;
|
|
|
|
ItemStack itemstack = entityPlayerMP.getCurrentEquippedItem();
|
|
|
|
|
|
|
|
if(itemstack != null && itemstack.getItem() instanceof ItemPortableTeleporter)
|
|
|
|
{
|
|
|
|
ItemPortableTeleporter item = (ItemPortableTeleporter)itemstack.getItem();
|
|
|
|
|
|
|
|
if(item.getStatus(itemstack) == 1)
|
|
|
|
{
|
|
|
|
Teleporter.Coords coords = Mekanism.teleporters.get(new Teleporter.Code(item.getDigit(itemstack, 0), item.getDigit(itemstack, 1), item.getDigit(itemstack, 2), item.getDigit(itemstack, 3))).get(0);
|
|
|
|
|
2013-01-23 21:42:45 +01:00
|
|
|
item.onUse(item.calculateEnergyCost(entityPlayerMP, coords), itemstack);
|
|
|
|
|
2013-01-21 02:15:59 +01:00
|
|
|
if(entityPlayerMP.worldObj.provider.dimensionId != coords.dimensionId)
|
|
|
|
{
|
|
|
|
entityPlayerMP.travelToDimension(coords.dimensionId);
|
|
|
|
}
|
|
|
|
|
2013-01-23 21:42:45 +01:00
|
|
|
entityPlayerMP.playerNetServerHandler.setPlayerLocation(coords.xCoord+0.5, coords.yCoord, coords.zCoord+0.5, entityPlayerMP.rotationYaw, entityPlayerMP.rotationPitch);
|
2013-01-21 02:15:59 +01:00
|
|
|
|
2013-02-22 04:03:54 +01:00
|
|
|
entityplayer.worldObj.playSoundAtEntity(entityplayer, "mob.endermen.portal", 1.0F, 1.0F);
|
2013-01-23 21:42:45 +01:00
|
|
|
PacketHandler.sendPortalFX(coords.xCoord, coords.yCoord, coords.zCoord, coords.dimensionId);
|
2013-01-21 02:15:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e)
|
|
|
|
{
|
|
|
|
System.err.println("[Mekanism] Error while handling portable teleport packet.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2013-02-27 02:21:30 +01:00
|
|
|
if(packetType == EnumPacketType.DATA_REQUEST.id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
int x = dataStream.readInt();
|
|
|
|
int y = dataStream.readInt();
|
|
|
|
int z = dataStream.readInt();
|
|
|
|
int id = dataStream.readInt();
|
|
|
|
|
|
|
|
World world = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(id);
|
|
|
|
|
|
|
|
if(world != null && world.getBlockTileEntity(x, y, z) instanceof ITileNetwork)
|
|
|
|
{
|
|
|
|
sendTileEntityPacketToClients(world.getBlockTileEntity(x, y, z), 0, ((ITileNetwork)world.getBlockTileEntity(x, y, z)).getNetworkedData(new ArrayList()));
|
|
|
|
}
|
|
|
|
} catch (Exception e)
|
|
|
|
{
|
|
|
|
System.err.println("[Mekanism] Error while handling data request packet.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|
2012-09-03 18:11:25 +02:00
|
|
|
catch (Exception e)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2013-01-21 02:15:59 +01:00
|
|
|
System.err.println("[Mekanism] Error while handling packet.");
|
2012-08-15 22:41:41 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2012-10-02 20:39:40 +02:00
|
|
|
}
|
|
|
|
|
2012-10-22 03:29:26 +02:00
|
|
|
/**
|
2012-11-21 16:14:35 +01:00
|
|
|
* Sends a packet from client to server with the TILE_ENTITY ID as well as an undefined amount of objects.
|
|
|
|
* While it won't give you an error, you cannot send anything other than integers or booleans. This can
|
|
|
|
* also be sent with a defined range, so players far away won't receive the packet.
|
2012-11-15 21:04:12 +01:00
|
|
|
* @param sender - sending tile entity
|
2012-11-21 16:14:35 +01:00
|
|
|
* @param distance - distance to send the packet, 0 if infinite range
|
2012-11-15 21:04:12 +01:00
|
|
|
* @param dataValues - data to send
|
2012-10-22 03:29:26 +02:00
|
|
|
*/
|
2013-02-27 02:21:30 +01:00
|
|
|
public static void sendTileEntityPacketToServer(TileEntity sender, ArrayList dataValues)
|
2012-10-02 20:39:40 +02:00
|
|
|
{
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
DataOutputStream output = new DataOutputStream(bytes);
|
|
|
|
|
|
|
|
try {
|
|
|
|
output.writeInt(EnumPacketType.TILE_ENTITY.id);
|
|
|
|
output.writeInt(sender.xCoord);
|
|
|
|
output.writeInt(sender.yCoord);
|
|
|
|
output.writeInt(sender.zCoord);
|
2012-11-15 21:04:12 +01:00
|
|
|
|
|
|
|
for(Object data : dataValues)
|
|
|
|
{
|
|
|
|
if(data instanceof Integer)
|
|
|
|
{
|
|
|
|
output.writeInt((Integer)data);
|
|
|
|
}
|
|
|
|
else if(data instanceof Boolean)
|
|
|
|
{
|
|
|
|
output.writeBoolean((Boolean)data);
|
|
|
|
}
|
2012-11-25 16:45:00 +01:00
|
|
|
else if(data instanceof Double)
|
|
|
|
{
|
|
|
|
output.writeDouble((Double)data);
|
|
|
|
}
|
|
|
|
else if(data instanceof Float)
|
|
|
|
{
|
|
|
|
output.writeFloat((Float)data);
|
|
|
|
}
|
2012-11-21 16:14:35 +01:00
|
|
|
else if(data instanceof String)
|
|
|
|
{
|
|
|
|
output.writeUTF((String)data);
|
|
|
|
}
|
2013-01-12 15:52:41 +01:00
|
|
|
else if(data instanceof Byte)
|
|
|
|
{
|
|
|
|
output.writeByte((Byte)data);
|
|
|
|
}
|
|
|
|
else if(data instanceof int[])
|
|
|
|
{
|
|
|
|
for(int i : (int[])data)
|
|
|
|
{
|
|
|
|
output.writeInt(i);
|
|
|
|
}
|
|
|
|
}
|
2012-11-21 16:14:35 +01:00
|
|
|
}
|
2012-11-15 21:04:12 +01:00
|
|
|
|
|
|
|
Packet250CustomPayload packet = new Packet250CustomPayload();
|
|
|
|
packet.channel = "Mekanism";
|
|
|
|
packet.data = bytes.toByteArray();
|
|
|
|
packet.length = packet.data.length;
|
|
|
|
|
2012-11-21 16:14:35 +01:00
|
|
|
PacketDispatcher.sendPacketToServer(packet);
|
2012-11-15 21:04:12 +01:00
|
|
|
} catch (IOException e) {
|
2012-11-05 20:29:04 +01:00
|
|
|
System.err.println("[Mekanism] Error while writing tile entity packet.");
|
2012-10-02 20:39:40 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-22 03:29:26 +02:00
|
|
|
/**
|
2012-11-15 21:04:12 +01:00
|
|
|
* Sends a packet from server to client with the TILE_ENTITY ID as well as an undefined amount of objects.
|
2012-11-21 16:14:35 +01:00
|
|
|
* While it won't give you an error, you cannot send anything other than integers or booleans. This can
|
2012-11-15 21:04:12 +01:00
|
|
|
* also be sent with a defined range, so players far away won't receive the packet.
|
|
|
|
* @param sender - sending tile entity
|
2012-11-21 16:14:35 +01:00
|
|
|
* @param distance - distance to send the packet, 0 if infinite range
|
2012-11-15 21:04:12 +01:00
|
|
|
* @param dataValues - data to send
|
2012-10-22 03:29:26 +02:00
|
|
|
*/
|
2013-02-27 02:21:30 +01:00
|
|
|
public static void sendTileEntityPacketToClients(TileEntity sender, double distance, ArrayList dataValues)
|
2012-10-02 20:39:40 +02:00
|
|
|
{
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
DataOutputStream output = new DataOutputStream(bytes);
|
|
|
|
|
|
|
|
try {
|
|
|
|
output.writeInt(EnumPacketType.TILE_ENTITY.id);
|
|
|
|
output.writeInt(sender.xCoord);
|
|
|
|
output.writeInt(sender.yCoord);
|
|
|
|
output.writeInt(sender.zCoord);
|
2012-11-15 21:04:12 +01:00
|
|
|
|
|
|
|
for(Object data : dataValues)
|
|
|
|
{
|
|
|
|
if(data instanceof Integer)
|
|
|
|
{
|
|
|
|
output.writeInt((Integer)data);
|
|
|
|
}
|
|
|
|
else if(data instanceof Boolean)
|
|
|
|
{
|
|
|
|
output.writeBoolean((Boolean)data);
|
|
|
|
}
|
2012-11-25 16:45:00 +01:00
|
|
|
else if(data instanceof Double)
|
|
|
|
{
|
|
|
|
output.writeDouble((Double)data);
|
|
|
|
}
|
|
|
|
else if(data instanceof Float)
|
|
|
|
{
|
|
|
|
output.writeFloat((Float)data);
|
|
|
|
}
|
2012-11-21 16:14:35 +01:00
|
|
|
else if(data instanceof String)
|
|
|
|
{
|
|
|
|
output.writeUTF((String)data);
|
|
|
|
}
|
2013-01-12 15:52:41 +01:00
|
|
|
else if(data instanceof Byte)
|
|
|
|
{
|
|
|
|
output.writeByte((Byte)data);
|
|
|
|
}
|
2012-12-19 21:23:55 +01:00
|
|
|
else if(data instanceof int[])
|
|
|
|
{
|
|
|
|
for(int i : (int[])data)
|
|
|
|
{
|
|
|
|
output.writeInt(i);
|
|
|
|
}
|
|
|
|
}
|
2012-11-15 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Packet250CustomPayload packet = new Packet250CustomPayload();
|
|
|
|
packet.channel = "Mekanism";
|
|
|
|
packet.data = bytes.toByteArray();
|
|
|
|
packet.length = packet.data.length;
|
|
|
|
|
2012-11-21 16:14:35 +01:00
|
|
|
if(distance == 0) PacketDispatcher.sendPacketToAllPlayers(packet);
|
|
|
|
else PacketDispatcher.sendPacketToAllAround(sender.xCoord, sender.yCoord, sender.zCoord, distance, sender.worldObj.provider.dimensionId, packet);
|
2012-11-15 21:04:12 +01:00
|
|
|
} catch (IOException e) {
|
2012-11-05 20:29:04 +01:00
|
|
|
System.err.println("[Mekanism] Error while writing tile entity packet.");
|
2012-10-02 20:39:40 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2012-09-25 05:53:22 +02:00
|
|
|
}
|
|
|
|
|
2012-11-21 16:14:35 +01:00
|
|
|
/**
|
|
|
|
* When the 'Access' button is clicked on the Control Panel's GUI, it both opens the client-side GUI, as well as
|
|
|
|
* send a packet to the server with enough data to open up the server-side object, or container. This packet does
|
|
|
|
* that function -- it sends over the data from IAccessibleGui (modClass, modInstance, guiId), and uses reflection
|
|
|
|
* to attempt and access the declared instance object from the mod's main class, which is also accessed using
|
|
|
|
* reflection. Upon being handled server-side, the data is put together, checked for NPEs, and then used inside
|
|
|
|
* EntityPlayer.openGui() along with the sent-over coords.
|
|
|
|
* @param modClass
|
|
|
|
* @param modInstance
|
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
|
|
|
* @param guiId
|
|
|
|
*/
|
|
|
|
public static void sendGuiRequest(String modClass, String modInstance, int x, int y, int z, int guiId)
|
|
|
|
{
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
DataOutputStream data = new DataOutputStream(bytes);
|
|
|
|
|
|
|
|
try {
|
|
|
|
data.writeInt(EnumPacketType.CONTROL_PANEL.id);
|
|
|
|
data.writeUTF(modClass);
|
|
|
|
data.writeUTF(modInstance);
|
|
|
|
data.writeInt(x);
|
|
|
|
data.writeInt(y);
|
|
|
|
data.writeInt(z);
|
|
|
|
data.writeInt(guiId);
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("[Mekanism] An error occured while writing packet data.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
Packet250CustomPayload packet = new Packet250CustomPayload();
|
|
|
|
packet.channel = "Mekanism";
|
|
|
|
packet.data = bytes.toByteArray();
|
|
|
|
packet.length = packet.data.length;
|
|
|
|
PacketDispatcher.sendPacketToServer(packet);
|
|
|
|
System.out.println("[Mekanism] Sent control panel packet to server.");
|
|
|
|
}
|
|
|
|
|
2013-02-22 04:03:54 +01:00
|
|
|
/**
|
|
|
|
* Sends a portal effect packet to all clients in a radius around a teleporter.
|
|
|
|
* @param x - x coordinate of teleporter
|
|
|
|
* @param y - y coordinate of teleporter
|
|
|
|
* @param z - z coordinate of teleporter
|
|
|
|
* @param id - dimension ID of teleporter
|
|
|
|
*/
|
2013-01-21 02:15:59 +01:00
|
|
|
public static void sendPortalFX(int x, int y, int z, int id)
|
|
|
|
{
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
DataOutputStream data = new DataOutputStream(bytes);
|
|
|
|
|
|
|
|
try {
|
|
|
|
data.writeInt(EnumPacketType.PORTAL_FX.id);
|
|
|
|
data.writeInt(x);
|
|
|
|
data.writeInt(y);
|
|
|
|
data.writeInt(z);
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("[Mekanism] An error occured while writing packet data.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
Packet250CustomPayload packet = new Packet250CustomPayload();
|
|
|
|
packet.channel = "Mekanism";
|
|
|
|
packet.data = bytes.toByteArray();
|
|
|
|
packet.length = packet.data.length;
|
|
|
|
PacketDispatcher.sendPacketToAllAround(x, y, z, 40, id, packet);
|
|
|
|
System.out.println("[Mekanism] Sent portal FX packet to server.");
|
|
|
|
}
|
|
|
|
|
2013-02-22 04:03:54 +01:00
|
|
|
/**
|
|
|
|
* Sends a digit update for a portable teleporter to the server as an integer.
|
|
|
|
* @param index - digit index
|
|
|
|
* @param digit - digit to send
|
|
|
|
*/
|
2013-01-21 02:15:59 +01:00
|
|
|
public static void sendDigitUpdate(int index, int digit)
|
|
|
|
{
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
DataOutputStream data = new DataOutputStream(bytes);
|
|
|
|
|
|
|
|
try {
|
|
|
|
data.writeInt(EnumPacketType.DIGIT_UPDATE.id);
|
|
|
|
data.writeInt(index);
|
|
|
|
data.writeInt(digit);
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("[Mekanism] An error occured while writing packet data.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
Packet250CustomPayload packet = new Packet250CustomPayload();
|
|
|
|
packet.channel = "Mekanism";
|
|
|
|
packet.data = bytes.toByteArray();
|
|
|
|
packet.length = packet.data.length;
|
|
|
|
PacketDispatcher.sendPacketToServer(packet);
|
|
|
|
}
|
|
|
|
|
2013-02-22 04:03:54 +01:00
|
|
|
/**
|
|
|
|
* Sends a status update for a portable teleporter to the client as a string.
|
|
|
|
* @param entityplayer - player who is using the teleporter
|
|
|
|
* @param status - status to send
|
|
|
|
*/
|
2013-01-21 02:15:59 +01:00
|
|
|
public static void sendStatusUpdate(EntityPlayer entityplayer, int status)
|
|
|
|
{
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
DataOutputStream data = new DataOutputStream(bytes);
|
|
|
|
|
|
|
|
try {
|
|
|
|
data.writeInt(EnumPacketType.STATUS_UPDATE.id);
|
|
|
|
data.writeInt(status);
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("[Mekanism] An error occured while writing packet data.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
Packet250CustomPayload packet = new Packet250CustomPayload();
|
|
|
|
packet.channel = "Mekanism";
|
|
|
|
packet.data = bytes.toByteArray();
|
|
|
|
packet.length = packet.data.length;
|
|
|
|
PacketDispatcher.sendPacketToPlayer(packet, (Player)entityplayer);
|
|
|
|
}
|
|
|
|
|
2012-09-03 18:11:25 +02:00
|
|
|
/**
|
|
|
|
* Sends the server the defined packet data int.
|
2012-09-20 15:59:30 +02:00
|
|
|
* @param type - packet type
|
2012-09-03 18:11:25 +02:00
|
|
|
* @param i - int to send
|
|
|
|
*/
|
2012-09-20 15:59:30 +02:00
|
|
|
public static void sendPacketDataInt(EnumPacketType type, int i)
|
2012-09-03 18:11:25 +02:00
|
|
|
{
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
DataOutputStream data = new DataOutputStream(bytes);
|
2012-11-21 16:14:35 +01:00
|
|
|
|
2012-09-03 18:11:25 +02:00
|
|
|
try {
|
2012-09-20 15:59:30 +02:00
|
|
|
data.writeInt(type.id);
|
2012-09-03 18:11:25 +02:00
|
|
|
data.writeInt(i);
|
|
|
|
} catch (IOException e) {
|
2012-11-05 20:29:04 +01:00
|
|
|
System.out.println("[Mekanism] An error occured while writing packet data.");
|
2012-09-03 18:11:25 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2012-11-21 16:14:35 +01:00
|
|
|
|
2012-09-03 18:11:25 +02:00
|
|
|
Packet250CustomPayload packet = new Packet250CustomPayload();
|
2012-11-05 20:29:04 +01:00
|
|
|
packet.channel = "Mekanism";
|
2012-09-03 18:11:25 +02:00
|
|
|
packet.data = bytes.toByteArray();
|
|
|
|
packet.length = packet.data.length;
|
|
|
|
PacketDispatcher.sendPacketToServer(packet);
|
2013-01-23 21:42:45 +01:00
|
|
|
System.out.println("[Mekanism] Sent data int packet '" + type.id + ":" + i + "' to server");
|
2012-09-03 18:11:25 +02:00
|
|
|
}
|
2013-02-27 02:21:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is used to request a data update from the server in order to update a client-sided tile entity.
|
|
|
|
* The server will receive this request, and then send a packet to the client with all the needed information.
|
|
|
|
* @param tileEntity
|
|
|
|
*/
|
|
|
|
public static void sendDataRequest(TileEntity tileEntity)
|
|
|
|
{
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
DataOutputStream data = new DataOutputStream(bytes);
|
|
|
|
|
|
|
|
try {
|
|
|
|
data.writeInt(EnumPacketType.DATA_REQUEST.id);
|
|
|
|
data.writeInt(tileEntity.xCoord);
|
|
|
|
data.writeInt(tileEntity.yCoord);
|
|
|
|
data.writeInt(tileEntity.zCoord);
|
|
|
|
data.writeInt(tileEntity.worldObj.provider.dimensionId);
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("[Mekanism] An error occured while writing packet data.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
Packet250CustomPayload packet = new Packet250CustomPayload();
|
|
|
|
packet.channel = "Mekanism";
|
|
|
|
packet.data = bytes.toByteArray();
|
|
|
|
packet.length = packet.data.length;
|
|
|
|
PacketDispatcher.sendPacketToServer(packet);
|
|
|
|
}
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|