Package mekanism.common.network

Source Code of mekanism.common.network.PacketDigitUpdate$DigitUpdateMessage

package mekanism.common.network;

import mekanism.common.PacketHandler;
import mekanism.common.item.ItemPortableTeleporter;
import mekanism.common.network.PacketDigitUpdate.DigitUpdateMessage;

import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

import io.netty.buffer.ByteBuf;

public class PacketDigitUpdate implements IMessageHandler<DigitUpdateMessage, IMessage>
{
  @Override
  public IMessage onMessage(DigitUpdateMessage message, MessageContext context)
  {
    ItemStack currentStack = PacketHandler.getPlayer(context).getCurrentEquippedItem();

    if(currentStack != null && currentStack.getItem() instanceof ItemPortableTeleporter)
    {
      ItemPortableTeleporter item = (ItemPortableTeleporter)currentStack.getItem();
      item.setDigit(currentStack, message.index, message.digit);
    }
   
    return null;
  }
 
  public static class DigitUpdateMessage implements IMessage
  {
    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();
    }
  }
}
TOP

Related Classes of mekanism.common.network.PacketDigitUpdate$DigitUpdateMessage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.