Advertisement
TechMage66

PacketTalismanSwitch

Jun 4th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. package com.techmage.magetech.network;
  2.  
  3. import com.techmage.magetech.init.ModItems;
  4. import com.techmage.magetech.utility.LogHelper;
  5. import cpw.mods.fml.common.network.simpleimpl.IMessage;
  6. import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
  7. import cpw.mods.fml.common.network.simpleimpl.MessageContext;
  8. import cpw.mods.fml.relauncher.Side;
  9. import io.netty.buffer.ByteBuf;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.ItemStack;
  12.  
  13. public class PacketTalismanSwitch implements IMessage
  14. {
  15.  
  16.     private int talisman;
  17.  
  18.     public PacketTalismanSwitch() { }
  19.  
  20.     public PacketTalismanSwitch(int talisman)
  21.     {
  22.         this.talisman = talisman;
  23.     }
  24.  
  25.     @Override
  26.     public void fromBytes(ByteBuf buf)
  27.     {
  28.         talisman = buf.readInt();
  29.     }
  30.  
  31.     @Override
  32.     public void toBytes(ByteBuf buf)
  33.     {
  34.         buf.writeInt(talisman);
  35.     }
  36.  
  37.     public static class Handler implements IMessageHandler<PacketTalismanSwitch, IMessage>
  38.     {
  39.         @Override
  40.         public IMessage onMessage(PacketTalismanSwitch msg, MessageContext ctx)
  41.         {
  42.             if (ctx.side == Side.SERVER)
  43.             {
  44.                 EntityPlayer player = ctx.getServerHandler().playerEntity;
  45.  
  46.                 switch (msg.talisman)
  47.                 {
  48.                     case 0:
  49.                         player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(ModItems.talismanFire));
  50.                         break;
  51.                     case 1:
  52.                         player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(ModItems.talismanAir));
  53.                         break;
  54.                     default:
  55.                         break;
  56.                 }
  57.             }
  58.             return null;
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement