mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 23:03:01 +00:00
Rewrite networking code for the 100th time to fix memory leak
This commit is contained in:
1 parent
be3883195c
commit
e5f76907ce
103 files changed
+2683
-2759
No files matched your search
@@ -1,60 +1,62 @@
|
||||
package mekanism.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.common.IRedstoneControl;
|
||||
import mekanism.common.IRedstoneControl.RedstoneControl;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.network.PacketRedstoneControl.RedstoneControlMessage;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
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 PacketRedstoneControl extends MekanismPacket
|
||||
public class PacketRedstoneControl implements IMessageHandler<RedstoneControlMessage, IMessage>
|
||||
{
|
||||
public Coord4D coord4D;
|
||||
public RedstoneControl value;
|
||||
|
||||
public PacketRedstoneControl() {}
|
||||
|
||||
public PacketRedstoneControl(Coord4D coord, RedstoneControl control)
|
||||
{
|
||||
coord4D = coord;
|
||||
value = control;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, ByteBuf dataStream)
|
||||
public IMessage onMessage(RedstoneControlMessage message, MessageContext context)
|
||||
{
|
||||
dataStream.writeInt(coord4D.xCoord);
|
||||
dataStream.writeInt(coord4D.yCoord);
|
||||
dataStream.writeInt(coord4D.zCoord);
|
||||
dataStream.writeInt(coord4D.dimensionId);
|
||||
|
||||
dataStream.writeInt(value.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ChannelHandlerContext ctx, EntityPlayer player, ByteBuf dataStream)
|
||||
{
|
||||
Coord4D obj = Coord4D.read(dataStream);
|
||||
RedstoneControl control = RedstoneControl.values()[dataStream.readInt()];
|
||||
|
||||
TileEntity tileEntity = obj.getTileEntity(player.worldObj);
|
||||
|
||||
EntityPlayer player = PacketHandler.getPlayer(context);
|
||||
TileEntity tileEntity = message.coord4D.getTileEntity(player.worldObj);
|
||||
|
||||
if(tileEntity instanceof IRedstoneControl)
|
||||
{
|
||||
((IRedstoneControl)tileEntity).setControlType(control);
|
||||
((IRedstoneControl)tileEntity).setControlType(message.value);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class RedstoneControlMessage implements IMessage
|
||||
{
|
||||
public Coord4D coord4D;
|
||||
public RedstoneControl value;
|
||||
|
||||
public RedstoneControlMessage() {}
|
||||
|
||||
public RedstoneControlMessage(Coord4D coord, RedstoneControl control)
|
||||
{
|
||||
coord4D = coord;
|
||||
value = control;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf dataStream)
|
||||
{
|
||||
dataStream.writeInt(coord4D.xCoord);
|
||||
dataStream.writeInt(coord4D.yCoord);
|
||||
dataStream.writeInt(coord4D.zCoord);
|
||||
dataStream.writeInt(coord4D.dimensionId);
|
||||
|
||||
dataStream.writeInt(value.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf dataStream)
|
||||
{
|
||||
coord4D = Coord4D.read(dataStream);
|
||||
value = RedstoneControl.values()[dataStream.readInt()];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer player)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user