daily pastebin goal
54%
SHARE
TWEET

Untitled

a guest Aug 19th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.modstack.mods.disassembler.packet;
  2.  
  3. import io.netty.buffer.ByteBuf;
  4. import net.minecraft.entity.player.EntityPlayer;
  5. import net.minecraft.entity.player.EntityPlayerMP;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.nbt.NBTTagCompound;
  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. import org.modstack.mods.disassembler.tools.AtomicScrewdriver;
  12.  
  13. public class PacketClickForScrewdriver implements IMessage {
  14.     public PacketClickForScrewdriver(boolean mousePressed /*, int timer*/){
  15.         this.mousePressed = mousePressed;
  16.         //this.timer = timer;
  17.     }
  18.     public PacketClickForScrewdriver(){
  19.  
  20.     }
  21.     //public int timer;
  22.     public boolean mousePressed;
  23.  
  24.     @Override
  25.     public void fromBytes(ByteBuf buf){
  26.         mousePressed = buf.readBoolean();
  27.         //timer = buf.readInt();
  28.     }
  29.     @Override
  30.     public void toBytes(ByteBuf buf){
  31.         buf.writeBoolean(mousePressed);
  32.         //buf.writeInt(timer);
  33.     }
  34.  
  35.     public static class Handler implements IMessageHandler<PacketClickForScrewdriver,IMessage>{
  36.         @Override
  37.         public IMessage onMessage(PacketClickForScrewdriver message, MessageContext ctx){
  38.             EntityPlayerMP mp = ctx.getServerHandler().player;
  39.             mp.getServerWorld().addScheduledTask(new Runnable() {
  40.                 @Override
  41.                 public void run() {
  42.                     EntityPlayer player = ctx.getServerHandler().player;
  43.                     ItemStack currentItem = player.inventory.getStackInSlot(player.inventory.currentItem);
  44.                     if(currentItem.getItem() instanceof AtomicScrewdriver){
  45.                         NBTTagCompound nbt = new NBTTagCompound();
  46.                         nbt.setBoolean("canBreak", message.mousePressed);
  47.                         currentItem.setTagCompound(nbt);
  48.                     }
  49.                 }
  50.             });
  51.             return null;
  52.         }
  53.     }
  54.  
  55. }
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