Example #1
0
  @Override
  public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) {
    super.decodeInto(ctx, data, packet);

    try {
      INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
      EntityPlayer player = CoreProxy.proxy.getPlayerFromNetHandler(netHandler);

      int packetID = packet.getID();

      switch (packetID) {
        case PacketIds.TILE_UPDATE:
          {
            onTileUpdate(player, (PacketTileUpdate) packet);
            break;
          }

        case PacketIds.STATE_UPDATE:
          {
            PacketTileState pkt = (PacketTileState) packet;
            World world = player.worldObj;

            TileEntity tile = world.getTileEntity(pkt.posX, pkt.posY, pkt.posZ);

            if (tile instanceof ISyncedTile) {
              pkt.applyStates(data, (ISyncedTile) tile);
            }

            break;
          }

        case PacketIds.GUI_RETURN:
          {
            // action will have happened already at read time
            break;
          }

        case PacketIds.GUI_WIDGET:
          {
            // action will have happened already at read time
            break;
          }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Example #2
0
  @Override
  public Packet getDescriptionPacket() {
    bindPipe();

    PacketTileState packet = new PacketTileState(this.xCoord, this.yCoord, this.zCoord);
    if (pipe != null && pipe.gate != null) {
      coreState.gateKind = pipe.gate.kind.ordinal();
    } else {
      coreState.gateKind = 0;
    }
    packet.addStateForSerialization((byte) 0, coreState);
    packet.addStateForSerialization((byte) 1, renderState);
    if (pipe instanceof IClientState) {
      packet.addStateForSerialization((byte) 2, (IClientState) pipe);
    }
    return packet.getPacket();
  }