2013-06-13 23:37:30 +02:00
|
|
|
package mekanism.common.network;
|
|
|
|
|
2014-06-02 23:57:40 +02:00
|
|
|
import io.netty.buffer.ByteBuf;
|
2014-06-11 11:57:49 +02:00
|
|
|
import mekanism.common.PacketHandler;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.common.item.ItemPortableTeleporter;
|
2014-06-11 11:57:49 +02:00
|
|
|
import mekanism.common.network.PacketDigitUpdate.DigitUpdateMessage;
|
2013-06-13 23:37:30 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-06-11 11:57:49 +02:00
|
|
|
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
|
|
|
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
|
|
|
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
2013-06-13 23:37:30 +02:00
|
|
|
|
2014-06-11 11:57:49 +02:00
|
|
|
public class PacketDigitUpdate implements IMessageHandler<DigitUpdateMessage, IMessage>
|
2013-06-13 23:37:30 +02:00
|
|
|
{
|
2014-06-02 17:33:19 +02:00
|
|
|
@Override
|
2014-06-11 11:57:49 +02:00
|
|
|
public IMessage onMessage(DigitUpdateMessage message, MessageContext context)
|
2013-06-13 23:37:30 +02:00
|
|
|
{
|
2014-06-11 11:57:49 +02:00
|
|
|
ItemStack currentStack = PacketHandler.getPlayer(context).getCurrentEquippedItem();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-06-13 23:37:30 +02:00
|
|
|
if(currentStack != null && currentStack.getItem() instanceof ItemPortableTeleporter)
|
|
|
|
{
|
|
|
|
ItemPortableTeleporter item = (ItemPortableTeleporter)currentStack.getItem();
|
2014-06-11 11:57:49 +02:00
|
|
|
item.setDigit(currentStack, message.index, message.digit);
|
2013-06-13 23:37:30 +02:00
|
|
|
}
|
2014-06-11 11:57:49 +02:00
|
|
|
|
|
|
|
return null;
|
2013-06-13 23:37:30 +02:00
|
|
|
}
|
2014-06-11 11:57:49 +02:00
|
|
|
|
|
|
|
public static class DigitUpdateMessage implements IMessage
|
2014-04-20 22:15:44 +02:00
|
|
|
{
|
2014-06-11 11:57:49 +02:00
|
|
|
public int index;
|
|
|
|
public int digit;
|
|
|
|
|
|
|
|
public DigitUpdateMessage() {}
|
|
|
|
|
|
|
|
public DigitUpdateMessage(int ind, int dig)
|
|
|
|
{
|
|
|
|
index = ind;
|
|
|
|
digit = dig;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void toBytes(ByteBuf dataStream)
|
|
|
|
{
|
|
|
|
dataStream.writeInt(index);
|
|
|
|
dataStream.writeInt(digit);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fromBytes(ByteBuf dataStream)
|
|
|
|
{
|
|
|
|
index = dataStream.readInt();
|
|
|
|
digit = dataStream.readInt();
|
|
|
|
}
|
2014-04-20 22:15:44 +02:00
|
|
|
}
|
2013-06-13 23:37:30 +02:00
|
|
|
}
|