Mekanism-tilera-Edition/src/main/java/mekanism/common/network/PacketTileEntity.java

61 lines
1.3 KiB
Java
Raw Normal View History

package mekanism.common.network;
import java.io.DataOutputStream;
import java.util.ArrayList;
import mekanism.api.Coord4D;
import mekanism.common.ITileNetwork;
import mekanism.common.PacketHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import com.google.common.io.ByteArrayDataInput;
public class PacketTileEntity implements IMekanismPacket
{
public Coord4D object3D;
public ArrayList parameters;
@Override
public String getName()
{
return "TileEntity";
}
@Override
public IMekanismPacket setParams(Object... data)
{
object3D = (Coord4D)data[0];
parameters = (ArrayList)data[1];
return this;
}
@Override
public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception
{
int x = dataStream.readInt();
int y = dataStream.readInt();
int z = dataStream.readInt();
TileEntity tileEntity = world.getTileEntity(x, y, z);
if(tileEntity instanceof ITileNetwork)
{
((ITileNetwork)tileEntity).handlePacketData(dataStream);
}
}
@Override
public void write(DataOutputStream dataStream) throws Exception
{
dataStream.writeInt(object3D.xCoord);
dataStream.writeInt(object3D.yCoord);
dataStream.writeInt(object3D.zCoord);
PacketHandler.encode(new Object[] {parameters}, dataStream);
}
}