Advertisement
TechMage66

DoBlockUpdate

Dec 7th, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. package com.techmage.magetech.network;
  2.  
  3. import com.techmage.magetech.tileentity.TileEntityPowerFurnace;
  4. import cpw.mods.fml.common.network.simpleimpl.IMessage;
  5. import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
  6. import cpw.mods.fml.common.network.simpleimpl.MessageContext;
  7. import cpw.mods.fml.relauncher.Side;
  8. import io.netty.buffer.ByteBuf;
  9. import net.minecraft.tileentity.TileEntity;
  10.  
  11. public class DoBlockUpdate implements IMessage
  12. {
  13.  
  14.     private int xCoord;
  15.     private int yCoord;
  16.     private int zCoord;
  17.     private boolean mode;
  18.  
  19.     public DoBlockUpdate() { }
  20.  
  21.     public DoBlockUpdate(int xCoord, int yCoord, int zCoord, boolean mode)
  22.     {
  23.         this.xCoord = xCoord;
  24.         this.yCoord = yCoord;
  25.         this.zCoord = zCoord;
  26.         this.mode = mode;
  27.     }
  28.  
  29.     @Override
  30.     public void fromBytes(ByteBuf buf)
  31.     {
  32.         xCoord = buf.readInt();
  33.         yCoord = buf.readInt();
  34.         zCoord = buf.readInt();
  35.         mode = buf.readBoolean();
  36.     }
  37.  
  38.     @Override
  39.     public void toBytes(ByteBuf buf)
  40.     {
  41.         buf.writeInt(xCoord);
  42.         buf.writeInt(yCoord);
  43.         buf.writeInt(zCoord);
  44.         buf.writeBoolean(mode);
  45.     }
  46.  
  47.     public static class Handler implements IMessageHandler<DoBlockUpdate, IMessage>
  48.     {
  49.         @Override
  50.         public IMessage onMessage(DoBlockUpdate msg, MessageContext ctx)
  51.         {
  52.             if (ctx.side == Side.SERVER)
  53.             {
  54.                 TileEntity tile = ctx.getServerHandler().playerEntity.worldObj.getTileEntity(msg.xCoord, msg.yCoord, msg.zCoord);
  55.                 TileEntityPowerFurnace powerFurnace = (TileEntityPowerFurnace) tile;
  56.                 ((TileEntityPowerFurnace) tile).setMode(msg.mode);
  57.                 ctx.getServerHandler().playerEntity.worldObj.markBlockForUpdate(msg.xCoord, msg.yCoord, msg.zCoord);
  58.             }
  59.             return null;
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement