daily pastebin goal
54%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package io.github.leordev.eosforgemod.common.network;
  2.  
  3. import io.github.leordev.eosforgemod.EOSForgeMod;
  4. import io.netty.buffer.ByteBuf;
  5. import net.minecraft.entity.player.EntityPlayerMP;
  6. import net.minecraft.init.Items;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
  9. import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
  10. import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
  11.  
  12. public class BlockChainTransferMessage implements IMessage {
  13.  
  14.     private int action;
  15.  
  16.     public BlockChainTransferMessage() {
  17.         this.action = 1;
  18.     }
  19.  
  20.     @Override
  21.     public void fromBytes(ByteBuf buf) {
  22.         buf.writeInt(action);
  23.     }
  24.  
  25.     @Override
  26.     public void toBytes(ByteBuf buf) {
  27.         action = buf.readInt();
  28.     }
  29.  
  30.     public static class MessageHandler implements IMessageHandler<BlockChainTransferMessage, IMessage> {
  31.         @Override
  32.         public IMessage onMessage(BlockChainTransferMessage message, MessageContext ctx) {
  33.             EntityPlayerMP serverPlayer = ctx.getServerHandler().player;
  34.  
  35.             if (message.action != 1) return null;
  36.  
  37.             EOSForgeMod.logger.info("Processing message...");
  38.  
  39.             serverPlayer.openContainer.putStackInSlot(1, new ItemStack(Items.DIAMOND, 99));
  40.  
  41.             serverPlayer.getServerWorld().addScheduledTask(() -> {
  42.                 serverPlayer.inventory.addItemStackToInventory(new ItemStack(Items.DIAMOND, 99));
  43.             });
  44.  
  45.             // No response packet
  46.             return null;
  47.         }
  48.     }
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top