Esempio n. 1
0
 public static DataWriter getWriter(PacketId id) {
   DataWriter dw = new DataWriter();
   dw.writeByte(
       1); // amount of packets, defaults to 1. Hast obe a byte so it's easy to modify afterwards
   dw.writeData(id.getId(), DataBitHelper.PACKET_ID);
   return dw;
 }
Esempio n. 2
0
  public static void sendBlockPacket(IBlockSync block, EntityPlayer player, int id) {
    if (block instanceof TileEntity) {
      DataWriter dw = getWriter(PacketId.BLOCK_SYNC);
      TileEntity te = (TileEntity) block;
      boolean onServer = !te.getWorldObj().isRemote;

      dw.writeData(te.xCoord, DataBitHelper.WORLD_COORDINATE);
      dw.writeData(te.yCoord, DataBitHelper.WORLD_COORDINATE);
      dw.writeData(te.zCoord, DataBitHelper.WORLD_COORDINATE);
      dw.writeData(id, block.infoBitLength());

      block.writeData(dw, player, onServer, id);

      if (!onServer) {
        dw.sendToServer();
      } else if (player != null) {
        dw.sendToPlayer((EntityPlayerMP) player);
      } else {
        dw.sendToAllPlayersAround(te, BLOCK_UPDATE_RANGE);
      }

      dw.close();
    }
  }