Reformatted all the code using the default intelji formatting options.

This commit is contained in:
modmuss50 2015-08-09 11:05:32 +01:00
parent 2f63a24070
commit e0ab0af822
363 changed files with 20524 additions and 23016 deletions

View file

@ -8,34 +8,34 @@ import java.io.IOException;
public class PacketAesu extends SimplePacket {
public PacketAesu() {
}
public PacketAesu() {
}
int buttonID;
int buttonID;
TileAesu aesu;
TileAesu aesu;
public PacketAesu(int buttonID, TileAesu aesu) {
this.aesu = aesu;
this.buttonID = buttonID;
}
public PacketAesu(int buttonID, TileAesu aesu) {
this.aesu = aesu;
this.buttonID = buttonID;
}
@Override
public void writeData(ByteBuf out) throws IOException {
SimplePacket.writeTileEntity(aesu, out);
out.writeInt(buttonID);
}
@Override
public void writeData(ByteBuf out) throws IOException {
SimplePacket.writeTileEntity(aesu, out);
out.writeInt(buttonID);
}
@Override
public void readData(ByteBuf in) throws IOException {
this.aesu = (TileAesu) SimplePacket.readTileEntity(in);
buttonID = in.readInt();
}
@Override
public void readData(ByteBuf in) throws IOException {
this.aesu = (TileAesu) SimplePacket.readTileEntity(in);
buttonID = in.readInt();
}
@Override
public void execute() {
if(!aesu.getWorldObj().isRemote){
aesu.handleGuiInputFromClient(buttonID);
}
}
@Override
public void execute() {
if (!aesu.getWorldObj().isRemote) {
aesu.handleGuiInputFromClient(buttonID);
}
}
}

View file

@ -16,80 +16,69 @@ import java.util.EnumMap;
import java.util.logging.Logger;
public class PacketHandler extends
FMLIndexedMessageToMessageCodec<SimplePacket> {
private static EnumMap<Side, FMLEmbeddedChannel> channels;
FMLIndexedMessageToMessageCodec<SimplePacket> {
private static EnumMap<Side, FMLEmbeddedChannel> channels;
public PacketHandler() {
addDiscriminator(0, PacketAesu.class);
}
public PacketHandler() {
addDiscriminator(0, PacketAesu.class);
}
public static EnumMap<Side, FMLEmbeddedChannel> getChannels()
{
return channels;
}
public static EnumMap<Side, FMLEmbeddedChannel> getChannels() {
return channels;
}
public static void setChannels(EnumMap<Side, FMLEmbeddedChannel> _channels)
{
channels = _channels;
}
public static void setChannels(EnumMap<Side, FMLEmbeddedChannel> _channels) {
channels = _channels;
}
public static void sendPacketToServer(SimplePacket packet)
{
PacketHandler.getChannels().get(Side.CLIENT)
.attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.TOSERVER);
PacketHandler.getChannels().get(Side.CLIENT).writeOutbound(packet);
}
public static void sendPacketToServer(SimplePacket packet) {
PacketHandler.getChannels().get(Side.CLIENT)
.attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.TOSERVER);
PacketHandler.getChannels().get(Side.CLIENT).writeOutbound(packet);
}
public static void sendPacketToPlayer(SimplePacket packet,
EntityPlayer player)
{
PacketHandler.getChannels().get(Side.SERVER)
.attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.PLAYER);
PacketHandler.getChannels().get(Side.SERVER)
.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
PacketHandler.getChannels().get(Side.SERVER).writeOutbound(packet);
}
public static void sendPacketToPlayer(SimplePacket packet,
EntityPlayer player) {
PacketHandler.getChannels().get(Side.SERVER)
.attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.PLAYER);
PacketHandler.getChannels().get(Side.SERVER)
.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
PacketHandler.getChannels().get(Side.SERVER).writeOutbound(packet);
}
public static void sendPacketToAllPlayers(SimplePacket packet)
{
PacketHandler.getChannels().get(Side.SERVER)
.attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.ALL);
PacketHandler.getChannels().get(Side.SERVER).writeOutbound(packet);
}
public static void sendPacketToAllPlayers(SimplePacket packet) {
PacketHandler.getChannels().get(Side.SERVER)
.attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.ALL);
PacketHandler.getChannels().get(Side.SERVER).writeOutbound(packet);
}
public static void sendPacketToAllPlayers(Packet packet, World world)
{
for (Object player : world.playerEntities)
{
if (player instanceof EntityPlayerMP)
if (player != null)
((EntityPlayerMP) player).playerNetServerHandler
.sendPacket(packet);
}
}
public static void sendPacketToAllPlayers(Packet packet, World world) {
for (Object player : world.playerEntities) {
if (player instanceof EntityPlayerMP)
if (player != null)
((EntityPlayerMP) player).playerNetServerHandler
.sendPacket(packet);
}
}
@Override
public void encodeInto(ChannelHandlerContext ctx, SimplePacket msg,
ByteBuf target) throws Exception
{
msg.writePacketData(target);
}
@Override
public void encodeInto(ChannelHandlerContext ctx, SimplePacket msg,
ByteBuf target) throws Exception {
msg.writePacketData(target);
}
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf source,
SimplePacket msg)
{
try
{
msg.readPacketData(source);
msg.execute();
} catch (IOException e)
{
Logger.getLogger("Network").warning(
"Something caused a Protocol Exception!");
}
}
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf source,
SimplePacket msg) {
try {
msg.readPacketData(source);
msg.execute();
} catch (IOException e) {
Logger.getLogger("Network").warning(
"Something caused a Protocol Exception!");
}
}
}

View file

@ -9,23 +9,23 @@ import techreborn.tiles.idsu.TileIDSU;
import java.io.IOException;
public class PacketIdsu extends AbstractPacket {
public PacketIdsu() {
}
public PacketIdsu() {
}
int buttonID, channel;
int buttonID, channel;
String newName;
String newName;
TileIDSU idsu;
TileIDSU idsu;
int x, y, z;
public PacketIdsu(int buttonID, TileIDSU idsu, int channel, String newName) {
this.idsu = idsu;
this.buttonID = buttonID;
this.channel = channel;
this.newName = newName;
}
public PacketIdsu(int buttonID, TileIDSU idsu, int channel, String newName) {
this.idsu = idsu;
this.buttonID = buttonID;
this.channel = channel;
this.newName = newName;
}
@Override

View file

@ -1,21 +1,5 @@
package techreborn.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
import cpw.mods.fml.common.network.FMLOutboundHandler;
@ -23,6 +7,18 @@ import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import java.util.*;
/**
* Packet pipeline class. Directs all registered packet data to be handled by

View file

@ -12,130 +12,111 @@ import net.minecraftforge.fluids.FluidRegistry;
import java.io.IOException;
public abstract class SimplePacket {
protected EntityPlayer player;
protected byte mode;
protected EntityPlayer player;
protected byte mode;
public SimplePacket(EntityPlayer _player)
{
player = _player;
}
public SimplePacket(EntityPlayer _player) {
player = _player;
}
@SuppressWarnings("unused")
public SimplePacket()
{
player = null;
}
@SuppressWarnings("unused")
public SimplePacket() {
player = null;
}
public static String readString(ByteBuf in) throws IOException
{
byte[] stringBytes = new byte[in.readInt()];
in.readBytes(stringBytes);
return new String(stringBytes, Charsets.UTF_8);
}
public static String readString(ByteBuf in) throws IOException {
byte[] stringBytes = new byte[in.readInt()];
in.readBytes(stringBytes);
return new String(stringBytes, Charsets.UTF_8);
}
public static void writeString(String string, ByteBuf out)
throws IOException
{
byte[] stringBytes;
stringBytes = string.getBytes(Charsets.UTF_8);
out.writeInt(stringBytes.length);
out.writeBytes(stringBytes);
}
public static void writeString(String string, ByteBuf out)
throws IOException {
byte[] stringBytes;
stringBytes = string.getBytes(Charsets.UTF_8);
out.writeInt(stringBytes.length);
out.writeBytes(stringBytes);
}
public static World readWorld(ByteBuf in) throws IOException
{
return DimensionManager.getWorld(in.readInt());
}
public static World readWorld(ByteBuf in) throws IOException {
return DimensionManager.getWorld(in.readInt());
}
public static void writeWorld(World world, ByteBuf out) throws IOException
{
out.writeInt(world.provider.dimensionId);
}
public static void writeWorld(World world, ByteBuf out) throws IOException {
out.writeInt(world.provider.dimensionId);
}
public static EntityPlayer readPlayer(ByteBuf in) throws IOException
{
if (!in.readBoolean())
return null;
World playerWorld = readWorld(in);
return playerWorld.getPlayerEntityByName(readString(in));
}
public static EntityPlayer readPlayer(ByteBuf in) throws IOException {
if (!in.readBoolean())
return null;
World playerWorld = readWorld(in);
return playerWorld.getPlayerEntityByName(readString(in));
}
public static void writePlayer(EntityPlayer player, ByteBuf out)
throws IOException
{
if (player == null)
{
out.writeBoolean(false);
return;
}
out.writeBoolean(true);
writeWorld(player.worldObj, out);
writeString(player.getCommandSenderName(), out);
}
public static void writePlayer(EntityPlayer player, ByteBuf out)
throws IOException {
if (player == null) {
out.writeBoolean(false);
return;
}
out.writeBoolean(true);
writeWorld(player.worldObj, out);
writeString(player.getCommandSenderName(), out);
}
public static TileEntity readTileEntity(ByteBuf in) throws IOException
{
return readWorld(in).getTileEntity(in.readInt(), in.readInt(),
in.readInt());
}
public static TileEntity readTileEntity(ByteBuf in) throws IOException {
return readWorld(in).getTileEntity(in.readInt(), in.readInt(),
in.readInt());
}
public static void writeTileEntity(TileEntity tileEntity, ByteBuf out)
throws IOException
{
writeWorld(tileEntity.getWorldObj(), out);
out.writeInt(tileEntity.xCoord);
out.writeInt(tileEntity.yCoord);
out.writeInt(tileEntity.zCoord);
}
public static void writeTileEntity(TileEntity tileEntity, ByteBuf out)
throws IOException {
writeWorld(tileEntity.getWorldObj(), out);
out.writeInt(tileEntity.xCoord);
out.writeInt(tileEntity.yCoord);
out.writeInt(tileEntity.zCoord);
}
public static Fluid readFluid(ByteBuf in) throws IOException
{
return FluidRegistry.getFluid(readString(in));
}
public static Fluid readFluid(ByteBuf in) throws IOException {
return FluidRegistry.getFluid(readString(in));
}
public static void writeFluid(Fluid fluid, ByteBuf out) throws IOException
{
if (fluid == null)
{
writeString("", out);
return;
}
writeString(fluid.getName(), out);
}
public static void writeFluid(Fluid fluid, ByteBuf out) throws IOException {
if (fluid == null) {
writeString("", out);
return;
}
writeString(fluid.getName(), out);
}
public void writePacketData(ByteBuf out) throws IOException
{
out.writeByte(mode);
writePlayer(player, out);
writeData(out);
}
public void writePacketData(ByteBuf out) throws IOException {
out.writeByte(mode);
writePlayer(player, out);
writeData(out);
}
public abstract void writeData(ByteBuf out) throws IOException;
public abstract void writeData(ByteBuf out) throws IOException;
public void readPacketData(ByteBuf in) throws IOException
{
mode = in.readByte();
player = readPlayer(in);
readData(in);
}
public void readPacketData(ByteBuf in) throws IOException {
mode = in.readByte();
player = readPlayer(in);
readData(in);
}
public abstract void readData(ByteBuf in) throws IOException;
public abstract void readData(ByteBuf in) throws IOException;
public abstract void execute();
public abstract void execute();
public void sendPacketToServer()
{
PacketHandler.sendPacketToServer(this);
}
public void sendPacketToServer() {
PacketHandler.sendPacketToServer(this);
}
public void sendPacketToPlayer(EntityPlayer player)
{
PacketHandler.sendPacketToPlayer(this, player);
}
public void sendPacketToPlayer(EntityPlayer player) {
PacketHandler.sendPacketToPlayer(this, player);
}
public void sendPacketToAllPlayers()
{
PacketHandler.sendPacketToAllPlayers(this);
}
public void sendPacketToAllPlayers() {
PacketHandler.sendPacketToAllPlayers(this);
}
}